/// <summary> /// Retrieves a codec suitable for a group field with the given tag. /// </summary> /// <param name="startTag">The start group tag.</param> /// <param name="endTag">The end group tag.</param> /// <param name="parser">A parser to use for the group message type.</param> /// <returns>A codec for given tag</returns> public static FieldCodec <T> ForGroup <T>(uint startTag, uint endTag, MessageParser <T> parser) where T : class, IMessage <T> { return(new FieldCodec <T>(input => { T message = parser.CreateTemplate(); input.ReadGroup(message); return message; }, (output, value) => output.WriteGroup(value), (CodedInputStream i, ref T v) => { if (v == null) { v = parser.CreateTemplate(); } i.ReadGroup(v); }, (ref T v, T v2) => { if (v2 == null) { return v == null; } else if (v == null) { v = v2.Clone(); } else { v.MergeFrom(v2); } return true; }, message => CodedOutputStream.ComputeGroupSize(message), startTag, endTag)); }
/// <summary> /// Retrieves a codec suitable for a group field with the given tag. /// </summary> /// <param name="startTag">The start group tag.</param> /// <param name="endTag">The end group tag.</param> /// <param name="parser">A parser to use for the group message type.</param> /// <returns>A codec for given tag</returns> public static FieldCodec <T> ForGroup <T>(uint startTag, uint endTag, MessageParser <T> parser) where T : IMessage <T> { return(new FieldCodec <T>(input => { T message = parser.CreateTemplate(); input.ReadGroup(message); return message; }, (output, value) => output.WriteGroup(value), message => CodedOutputStream.ComputeGroupSize(message), startTag, endTag)); }