/** Read an {@code sint32} field value from the internal buffer. */ public int readSInt32() throws IOException { final int n = readRawVarint32(); return (n >>> 1) ^ -(n & 1); }
/** Read a {@code uint32} field value from the internal buffer. */ public int readUInt32() throws IOException { return readRawVarint32(); }
/** Read an {@code int32} field value from the internal buffer. */ public int readInt32() throws IOException { return readRawVarint32(); }
/** * Read an enum field value from the internal buffer. Caller is responsible * for converting the numeric value to an actual enum. */ public int readEnum() throws IOException { return readRawVarint32(); }
public byte[] readByteArray() throws IOException { final int length = readRawVarint32(); if(length < 0) throw ProtobufException.negativeSize(); if(offset + length > limit) throw ProtobufException.misreportedSize(); final byte[] copy = new byte[length]; System.arraycopy(buffer, offset, copy, 0, length); offset += length; return copy; }
/** * 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 (offset == limit) { 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 void transferByteRangeTo(Output output, boolean utf8String, int fieldNumber, boolean repeated) throws IOException { final int length = readRawVarint32(); if(length < 0) throw ProtobufException.negativeSize(); output.writeByteRange(utf8String, fieldNumber, buffer, offset, length, repeated); offset += length; }
final int tag = readRawVarint32(); final int fieldNumber = tag >>> TAG_TYPE_BITS; if (fieldNumber == 0)
public String readString() throws IOException { final int length = readRawVarint32(); if(length < 0) throw ProtobufException.negativeSize(); if(offset + length > limit) throw ProtobufException.misreportedSize(); final int offset = this.offset; this.offset += length; return STRING.deser(buffer, offset, length); }
public <T> T mergeObject(T value, final Schema<T> schema) throws IOException { if(decodeNestedMessageAsGroup) return mergeObjectEncodedAsGroup(value, schema); final int length = readRawVarint32(); if(length < 0) throw ProtobufException.negativeSize(); // save old limit final int oldLimit = this.limit; this.limit = offset + length; if(value == null) value = schema.newMessage(); schema.mergeFrom(this, value); if(!schema.isInitialized(value)) throw new UninitializedMessageException(value, schema); checkLastTagWas(0); // restore old limit this.limit = oldLimit; return value; }
return true; case WIRETYPE_LENGTH_DELIMITED: final int size = readRawVarint32(); if(size < 0) throw ProtobufException.negativeSize();