/** * Attempt to read a field tag, returning zero if we have reached EOF. * 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. */ public int readTag() throws IOException { if (isAtEnd()) { lastTag = 0; return 0; } final int tag = readRawVarint32(); if (tag >>> TAG_TYPE_BITS == 0) { // If we actually read zero, that's not a valid tag. throw ProtobufException.invalidTag(); } lastTag = tag; return tag; }
public <T> int readFieldNumber(Schema<T> schema) throws IOException { if (isAtEnd()) { lastTag = 0; return 0; } final int tag = readRawVarint32(); final int fieldNumber = tag >>> TAG_TYPE_BITS; if (fieldNumber == 0) { if(decodeNestedMessageAsGroup && WIRETYPE_TAIL_DELIMITER == (tag & TAG_TYPE_MASK)) { // protostuff's tail delimiter for streaming // 2 options: length-delimited or tail-delimited. lastTag = 0; return 0; } // If we actually read zero, that's not a valid tag. throw ProtobufException.invalidTag(); } if(decodeNestedMessageAsGroup && WIRETYPE_END_GROUP == (tag & TAG_TYPE_MASK)) { lastTag = 0; return 0; } lastTag = tag; return fieldNumber; }