/// <summary>
        /// Attempt to read a field tag, returning 0 if we have reached the end
        /// of the input data. Protocol message parsers use this to read tags,
        /// since a protocol message may legally end wherever a tag occurs, and
        /// zero is not a valid tag number.
        /// </summary>

        public uint ReadTag()
        {
            if (IsAtEnd)
            {
                lastTag = 0;
                return(0);
            }

            lastTag = ReadRawVarint32();
            if (lastTag == 0)
            {
                // If we actually read zero, that's not a valid tag.
                throw InvalidProtocolBufferException.InvalidTag();
            }
            return(lastTag);
        }
Пример #2
0
        /// <summary>
        /// Attempt to read a field tag, returning 0 if we have reached the end
        /// of the input data. Protocol message parsers use this to read tags,
        /// since a protocol message may legally end wherever a tag occurs, and
        /// zero is not a valid tag number.
        /// </summary>
        public uint ReadTag()
        {
            if (bufferPos == bufferSize && !RefillBuffer(false))
            {
                lastTag = 0;
                return(0);
            }

            lastTag = ReadRawVarint32();
            if (lastTag == 0)
            {
                // If we actually read zero, that's not a valid tag.
                throw InvalidProtocolBufferException.InvalidTag();
            }
            return(lastTag);
        }
Пример #3
0
        public bool ReadTag(out uint fieldTag, out string fieldName)
        {
            fieldTag = 0;
            if (hasNextTag)
            {
                fieldName  = nextTag;
                lastTag    = fieldName;
                hasNextTag = false;
                return(true);
            }

            if (IsAtEnd)
            {
                fieldName = null;
                lastTag   = fieldName;
                return(false);
            }

            if (tokenizer.TryConsume("}"))
            {
                fieldName = null;
                lastTag   = "}";
                return(false);
            }

            if (tokenizer.TryConsume(">"))
            {
                fieldName = null;
                lastTag   = ">";
                return(false);
            }

            fieldName = tokenizer.ConsumeIdentifier();
            lastTag   = fieldName;
            if (lastTag == null)
            {
                // If we actually read zero, that's not a valid tag.
                throw InvalidProtocolBufferException.InvalidTag();
            }
            return(true);
        }
Пример #4
0
 public bool ReadTag(out uint fieldTag, out string fieldName)
 {
     fieldName = null;
     if (this.hasNextTag)
     {
         fieldTag        = this.nextTag;
         this.lastTag    = fieldTag;
         this.hasNextTag = false;
         return(true);
     }
     if (this.IsAtEnd)
     {
         fieldTag     = 0u;
         this.lastTag = fieldTag;
         return(false);
     }
     fieldTag     = this.ReadRawVarint32();
     this.lastTag = fieldTag;
     if (this.lastTag == 0u)
     {
         throw InvalidProtocolBufferException.InvalidTag();
     }
     return(true);
 }