|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.protobuf.CodedInputStream
public final class CodedInputStream
Reads and decodes protocol message fields.
This class contains two kinds of methods: methods that read specific
protocol message constructs and field types (e.g. readTag()
and
readInt32()
) and methods that read low-level values (e.g.
readRawVarint32()
and readRawBytes(int)
). If you are reading
encoded protocol messages, you should use the former methods, but if you are
reading some other format of your own design, use the latter.
Method Summary | |
---|---|
void |
checkLastTagWas(int value)
Verifies that the last call to readTag() returned the given tag value. |
static int |
decodeZigZag32(int n)
Decode a ZigZag-encoded 32-bit value. |
static long |
decodeZigZag64(long n)
Decode a ZigZag-encoded 64-bit value. |
int |
getBytesUntilLimit()
Returns the number of bytes to be read before the current limit. |
boolean |
isAtEnd()
Returns true if the stream has reached the end of the input. |
static CodedInputStream |
newInstance(byte[] buf)
Create a new CodedInputStream wrapping the given byte array. |
static CodedInputStream |
newInstance(byte[] buf,
int off,
int len)
Create a new CodedInputStream wrapping the given byte array slice. |
static CodedInputStream |
newInstance(java.io.InputStream input)
Create a new CodedInputStream wrapping the given InputStream. |
void |
popLimit(int oldLimit)
Discards the current limit, returning to the previous limit. |
int |
pushLimit(int byteLimit)
Sets currentLimit to (current position) + byteLimit . |
boolean |
readBool()
Read a bool field value from the stream. |
ByteString |
readBytes()
Read a bytes field value from the stream. |
double |
readDouble()
Read a double field value from the stream. |
int |
readEnum()
Read an enum field value from the stream. |
int |
readFixed32()
Read a fixed32 field value from the stream. |
long |
readFixed64()
Read a fixed64 field value from the stream. |
float |
readFloat()
Read a float field value from the stream. |
void |
readGroup(int fieldNumber,
Message.Builder builder,
ExtensionRegistry extensionRegistry)
Read a group field value from the stream. |
int |
readInt32()
Read an int32 field value from the stream. |
long |
readInt64()
Read an int64 field value from the stream. |
void |
readMessage(Message.Builder builder,
ExtensionRegistry extensionRegistry)
Read an embedded message field value from the stream. |
java.lang.Object |
readPrimitiveField(Descriptors.FieldDescriptor.Type type)
Read a field of any primitive type. |
byte |
readRawByte()
Read one byte from the input. |
byte[] |
readRawBytes(int size)
Read a fixed size of bytes from the input. |
int |
readRawLittleEndian32()
Read a 32-bit little-endian integer from the stream. |
long |
readRawLittleEndian64()
Read a 64-bit little-endian integer from the stream. |
int |
readRawVarint32()
Read a raw Varint from the stream. |
long |
readRawVarint64()
Read a raw Varint from the stream. |
int |
readSFixed32()
Read an sfixed32 field value from the stream. |
long |
readSFixed64()
Read an sfixed64 field value from the stream. |
int |
readSInt32()
Read an sint32 field value from the stream. |
long |
readSInt64()
Read an sint64 field value from the stream. |
java.lang.String |
readString()
Read a string field value from the stream. |
int |
readTag()
Attempt to read a field tag, returning zero if we have reached EOF. |
int |
readUInt32()
Read a uint32 field value from the stream. |
long |
readUInt64()
Read a uint64 field value from the stream. |
void |
readUnknownGroup(int fieldNumber,
UnknownFieldSet.Builder builder)
Reads a group field value from the stream and merges it into the
given UnknownFieldSet . |
void |
resetSizeCounter()
Resets the current size counter to zero (see setSizeLimit(int) ). |
int |
setRecursionLimit(int limit)
Set the maximum message recursion depth. |
int |
setSizeLimit(int limit)
Set the maximum message size. |
boolean |
skipField(int tag)
Reads and discards a single field, given its tag value. |
void |
skipMessage()
Reads and discards an entire message. |
void |
skipRawBytes(int size)
Reads and discards size bytes. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static CodedInputStream newInstance(java.io.InputStream input)
public static CodedInputStream newInstance(byte[] buf)
public static CodedInputStream newInstance(byte[] buf, int off, int len)
public int readTag() throws java.io.IOException
java.io.IOException
public void checkLastTagWas(int value) throws InvalidProtocolBufferException
InvalidProtocolBufferException
- value
does not match the
last tag.public boolean skipField(int tag) throws java.io.IOException
false
if the tag is an endgroup tag, in which case
nothing is skipped. Otherwise, returns true
.
java.io.IOException
public void skipMessage() throws java.io.IOException
java.io.IOException
public double readDouble() throws java.io.IOException
double
field value from the stream.
java.io.IOException
public float readFloat() throws java.io.IOException
float
field value from the stream.
java.io.IOException
public long readUInt64() throws java.io.IOException
uint64
field value from the stream.
java.io.IOException
public long readInt64() throws java.io.IOException
int64
field value from the stream.
java.io.IOException
public int readInt32() throws java.io.IOException
int32
field value from the stream.
java.io.IOException
public long readFixed64() throws java.io.IOException
fixed64
field value from the stream.
java.io.IOException
public int readFixed32() throws java.io.IOException
fixed32
field value from the stream.
java.io.IOException
public boolean readBool() throws java.io.IOException
bool
field value from the stream.
java.io.IOException
public java.lang.String readString() throws java.io.IOException
string
field value from the stream.
java.io.IOException
public void readGroup(int fieldNumber, Message.Builder builder, ExtensionRegistry extensionRegistry) throws java.io.IOException
group
field value from the stream.
java.io.IOException
public void readUnknownGroup(int fieldNumber, UnknownFieldSet.Builder builder) throws java.io.IOException
group
field value from the stream and merges it into the
given UnknownFieldSet
.
java.io.IOException
public void readMessage(Message.Builder builder, ExtensionRegistry extensionRegistry) throws java.io.IOException
java.io.IOException
public ByteString readBytes() throws java.io.IOException
bytes
field value from the stream.
java.io.IOException
public int readUInt32() throws java.io.IOException
uint32
field value from the stream.
java.io.IOException
public int readEnum() throws java.io.IOException
java.io.IOException
public int readSFixed32() throws java.io.IOException
sfixed32
field value from the stream.
java.io.IOException
public long readSFixed64() throws java.io.IOException
sfixed64
field value from the stream.
java.io.IOException
public int readSInt32() throws java.io.IOException
sint32
field value from the stream.
java.io.IOException
public long readSInt64() throws java.io.IOException
sint64
field value from the stream.
java.io.IOException
public java.lang.Object readPrimitiveField(Descriptors.FieldDescriptor.Type type) throws java.io.IOException
type
- Declared type of the field.
Message.getField(Descriptors.FieldDescriptor)
for
this field.
java.io.IOException
public int readRawVarint32() throws java.io.IOException
java.io.IOException
public long readRawVarint64() throws java.io.IOException
java.io.IOException
public int readRawLittleEndian32() throws java.io.IOException
java.io.IOException
public long readRawLittleEndian64() throws java.io.IOException
java.io.IOException
public static int decodeZigZag32(int n)
n
- An unsigned 32-bit integer, stored in a signed int because
Java has no explicit unsigned support.
public static long decodeZigZag64(long n)
n
- An unsigned 64-bit integer, stored in a signed int because
Java has no explicit unsigned support.
public int setRecursionLimit(int limit)
CodedInputStream
limits
how deeply messages may be nested. The default limit is 64.
public int setSizeLimit(int limit)
CodedInputStream
limits how large a message may be.
The default limit is 64MB. You should set this limit as small
as you can without harming your app's functionality. Note that
size limits only apply when reading from an InputStream
, not
when constructed around a raw byte array (nor with
ByteString.newCodedInput()
).
If you want to read several messages from a single CodedInputStream, you
could call resetSizeCounter()
after each one to avoid hitting the
size limit.
public void resetSizeCounter()
setSizeLimit(int)
).
public int pushLimit(int byteLimit) throws InvalidProtocolBufferException
currentLimit
to (current position) + byteLimit
. This
is called when descending into a length-delimited embedded message.
InvalidProtocolBufferException
public void popLimit(int oldLimit)
oldLimit
- The old limit, as returned by pushLimit
.public int getBytesUntilLimit()
public boolean isAtEnd() throws java.io.IOException
pushLimit(int)
.
java.io.IOException
public byte readRawByte() throws java.io.IOException
InvalidProtocolBufferException
- The end of the stream or the current
limit was reached.
java.io.IOException
public byte[] readRawBytes(int size) throws java.io.IOException
InvalidProtocolBufferException
- The end of the stream or the current
limit was reached.
java.io.IOException
public void skipRawBytes(int size) throws java.io.IOException
size
bytes.
InvalidProtocolBufferException
- The end of the stream or the current
limit was reached.
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |