Exemple #1
0
        /// <summary>
        /// Retrieves a codec suitable for a message field with the given tag.
        /// </summary>
        /// <param name="tag">The tag.</param>
        /// <param name="parser">A parser to use for the message type.</param>
        /// <returns>A codec for the given tag.</returns>
        public static FieldCodec <T> ForMessage <T>(uint tag, MessageParser <T> parser) where T : class, IMessage <T>
        {
            return(new FieldCodec <T>(input => { T message = parser.CreateTemplate(); input.ReadMessage(message); return message; },
                                      (output, value) => output.WriteMessage(value), (CodedInputStream i, ref T v) =>
            {
                if (v == null)
                {
                    v = parser.CreateTemplate();
                }

                i.ReadMessage(v);
            },
                                      (ref T v, T v2) =>
            {
                if (v2 == null)
                {
                    return false;
                }
                else if (v == null)
                {
                    v = v2.Clone();
                }
                else
                {
                    v.MergeFrom(v2);
                }
                return true;
            }, message => CodedOutputStream.ComputeMessageSize(message), tag));
        }
 /// <summary>
 /// Retrieves a codec suitable for a message field with the given tag.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <param name="parser">A parser to use for the message type.</param>
 /// <returns>A codec for the given tag.</returns>
 public static FieldCodec <T> ForMessage <T>(uint tag, MessageParser <T> parser) where T : IMessage <T>
 {
     return(new FieldCodec <T>(input => { T message = parser.CreateTemplate(); input.ReadMessage(message); return message; },
                               (output, value) => output.WriteMessage(value), message => CodedOutputStream.ComputeMessageSize(message), tag));
 }
Exemple #3
0
 internal int <ForMessage> b__16_2(T message)
 {
     return(CodedOutputStream.ComputeMessageSize(message));
 }