Example #1
0
            internal static T Read <T>(CodedInputStream input, FieldCodec <T> codec)
            {
                int length   = input.ReadLength();
                int oldLimit = input.PushLimit(length);

                uint tag;
                T    value = codec.DefaultValue;

                while (input.ReadTag(out tag))
                {
                    if (tag == 0)
                    {
                        throw InvalidProtocolBufferException.InvalidTag();
                    }
                    if (tag == codec.Tag)
                    {
                        value = codec.Read(input);
                    }
                    if (WireFormat.IsEndGroupTag(tag))
                    {
                        break;
                    }
                }
                input.CheckLastTagWas(0);
                input.PopLimit(oldLimit);

                return(value);
            }
Example #2
0
 /// <summary>
 /// Merges data from the given stream into an existing message.
 /// </summary>
 /// <param name="message">The message to merge the data into.</param>
 /// <param name="input">Stream containing the data to merge, which must be protobuf-encoded binary data.</param>
 public static void MergeFrom(this IMessage message, Stream input)
 {
     Preconditions.CheckNotNull(message, "message");
     Preconditions.CheckNotNull(input, "input");
     CodedInputStream codedInput = new CodedInputStream(input);
     message.MergeFrom(codedInput);
     codedInput.CheckLastTagWas(0);
 }
Example #3
0
 /// <summary>
 /// Merges data from the given byte array into an existing message.
 /// </summary>
 /// <param name="message">The message to merge the data into.</param>
 /// <param name="data">The data to merge, which must be protobuf-encoded binary data.</param>
 public static void MergeFrom(this IMessage message, byte[] data)
 {
     Preconditions.CheckNotNull(message, "message");
     Preconditions.CheckNotNull(data, "data");
     CodedInputStream input = new CodedInputStream(data);
     message.MergeFrom(input);
     input.CheckLastTagWas(0);
 }
        public static void MergeFrom(this IMessage message, Stream input)
        {
            Preconditions.CheckNotNull(message, "message");
            Preconditions.CheckNotNull(input, "input");
            CodedInputStream codedInput = CodedInputStream.CreateInstance(input);

            message.MergeFrom(codedInput);
            codedInput.CheckLastTagWas(0);
        }
        public static void MergeFrom(this IMessage message, ByteString data)
        {
            Preconditions.CheckNotNull(message, "message");
            Preconditions.CheckNotNull(data, "data");
            CodedInputStream input = data.CreateCodedInput();

            message.MergeFrom(input);
            input.CheckLastTagWas(0);
        }
        public static void MergeFrom(this IMessage message, byte[] data)
        {
            Preconditions.CheckNotNull(message, "message");
            Preconditions.CheckNotNull(data, "data");
            CodedInputStream input = CodedInputStream.CreateInstance(data);

            message.MergeFrom(input);
            input.CheckLastTagWas(0);
        }