Пример #1
0
        public static T DeserializeWithLengthPrefix <T>(Stream source, PrefixStyle style, int fieldNumber)
        {
            RuntimeTypeModel @default = RuntimeTypeModel.Default;

            return((T)@default.DeserializeWithLengthPrefix(source, null, @default.MapType(typeof(T)), style, fieldNumber));
        }
Пример #2
0
        /// <summary>
        /// Applies a protocol-buffer stream to an existing instance, using length-prefixed
        /// data - useful with network IO.
        /// </summary>
        /// <typeparam name="T">The type being merged.</typeparam>
        /// <param name="instance">The existing instance to be modified (can be null).</param>
        /// <param name="source">The binary stream to apply to the instance (cannot be null).</param>
        /// <param name="style">How to encode the length prefix.</param>
        /// <returns>The updated instance; this may be different to the instance argument if
        /// either the original instance was null, or the stream defines a known sub-type of the
        /// original instance.</returns>
        public static T MergeWithLengthPrefix <T>(Stream source, T instance, PrefixStyle style)
        {
            RuntimeTypeModel model = RuntimeTypeModel.Default;

            return((T)model.DeserializeWithLengthPrefix(source, instance, model.MapType(typeof(T)), style, 0));
        }
Пример #3
0
 private bool TryDeserializeWithLengthPrefix(Stream source, PrefixStyle style, Serializer.TypeResolver resolver, ref object value)
 {
     value = _model.DeserializeWithLengthPrefix(source, null, typeof(TDeserialized), style, 0, resolver);
     return(value != null);
 }
 public object Deserialize(Stream stream, object o, Type t)
 {
     return(model.DeserializeWithLengthPrefix(stream, o, t, PrefixStyle.Base128, 0));
 }