public void Skip(SerializerInput input) { var toSkip = input.ReadInt(); if (toSkip == -1)//null { return; } input.Skip(toSkip); }
/// <summary> /// Populates a object fields with data from the stream /// </summary> /// <typeparam name="T"></typeparam> /// <param name="stream"></param> /// <param name="ob"></param> /// <param name="bufferSize"></param> /// <returns>false if type is not serializable</returns> public static bool TryPopulateObject <T>(Stream stream, ref T ob, int bufferSize = 4096 * 2) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } var serializerInput = new SerializerInput(bufferSize, stream); var tryPopulateObject = _uSerializer.TryPopulateObject(serializerInput, ref ob); serializerInput.FinishRead(); return(tryPopulateObject); }
/// <summary> /// Creates a object with data from the stream /// </summary> /// <typeparam name="T"></typeparam> /// <param name="stream"></param> /// <param name="result"></param> /// <param name="bufferSize"></param> /// <returns>false if type is not serializable</returns> public static bool TryDeserialize <T>(Stream stream, ref T result, int bufferSize = 4096 * 2) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } var serializerInput = new SerializerInput(bufferSize, stream); var tryDeserialize = _uSerializer.TryDeserialize <T>(serializerInput, ref result); serializerInput.FinishRead(); return(tryDeserialize); }
public USerializerBenchmark() { var consoleLogger = new ConsoleLogger(); var serializationProviders = ProvidersUtils.GetDefaultProviders(consoleLogger); _uSerializer = new USerializer(new UnitySerializationPolicy(), serializationProviders, new DataTypesDatabase(), consoleLogger); _output = new SerializerOutput(2048 * 10); _input = new SerializerInput(2048 * 10); _uSerializer.PreCacheType(typeof(T)); if (_uSerializer.TryGetDataSerializer(typeof(T), out var dataSerializer)) { _serializer = dataSerializer.GetTyped <T>(); } else { throw new Exception($"Cannot serialize {typeof(T)}"); } }
public void Skip(SerializerInput input) { input.Skip(sizeof(T)); }