Exemplo n.º 1
0
        public void Skip(SerializerInput input)
        {
            var toSkip = input.ReadInt();

            if (toSkip == -1)//null
            {
                return;
            }

            input.Skip(toSkip);
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        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)}");
            }
        }
Exemplo n.º 5
0
 public void Skip(SerializerInput input)
 {
     input.Skip(sizeof(T));
 }