public abstract class ProtoSink extends Object
This class contains two kinds of methods: methods that write specific
protocol message constructs and field types (e.g. writeTag(int, int) and
writeInt32(int, int)) and methods that write low-level values (e.g.
writeRawVarint32(int) and writeRawBytes(byte[])). If you are
writing encoded protocol messages, you should use the former methods, but if
you are writing some other format of your own design, use the latter.
This class is totally unsynchronized.
| Modifier and Type | Class and Description |
|---|---|
static class |
ProtoSink.OutOfSpaceException
If you create a ProtoSink around a simple flat array, you must
not attempt to write more bytes than the array has space.
|
| Modifier | Constructor and Description |
|---|---|
protected |
ProtoSink() |
| Modifier and Type | Method and Description |
|---|---|
void |
checkNoSpaceLeft()
Verifies that
spaceLeft() returns zero. |
abstract ProtoSink |
clear()
Clears internal state and removes any references to previous outputs.
|
static int |
computeBoolSize(int fieldNumber,
boolean value)
Compute the number of bytes that would be needed to encode a
bool field, including tag. |
static int |
computeBoolSizeNoTag(boolean value)
Compute the number of bytes that would be needed to encode a
bool field. |
static int |
computeBytesSize(int fieldNumber,
RepeatedByte value)
Compute the number of bytes that would be needed to encode a
bytes field, including tag. |
static int |
computeBytesSizeNoTag(RepeatedByte value)
Compute the number of bytes that would be needed to encode a
bytes field. |
static int |
computeDelimitedSize(int length)
Compute the number of bytes that would be needed to encode
length bytes and a length delimiter.
|
static int |
computeDoubleSize(int fieldNumber,
double value)
Compute the number of bytes that would be needed to encode a
double field, including tag. |
static int |
computeDoubleSizeNoTag(double value)
Compute the number of bytes that would be needed to encode a
double field, including tag. |
static int |
computeEnumSize(int fieldNumber,
int value)
Compute the number of bytes that would be needed to encode an
enum field, including tag.
|
static int |
computeEnumSizeNoTag(int value)
Compute the number of bytes that would be needed to encode an enum field.
|
static int |
computeFixed32Size(int fieldNumber,
int value)
Compute the number of bytes that would be needed to encode a
fixed32 field, including tag. |
static int |
computeFixed32SizeNoTag(int value)
Compute the number of bytes that would be needed to encode a
fixed32 field. |
static int |
computeFixed64Size(int fieldNumber,
long value)
Compute the number of bytes that would be needed to encode a
fixed64 field, including tag. |
static int |
computeFixed64SizeNoTag(long value)
Compute the number of bytes that would be needed to encode a
fixed64 field. |
static int |
computeFloatSize(int fieldNumber,
float value)
Compute the number of bytes that would be needed to encode a
float field, including tag. |
static int |
computeFloatSizeNoTag(float value)
Compute the number of bytes that would be needed to encode a
float field, including tag. |
static int |
computeGroupSize(int fieldNumber,
ProtoMessage<?> value)
Compute the number of bytes that would be needed to encode a
group field, including tag. |
static int |
computeGroupSizeNoTag(ProtoMessage value)
Compute the number of bytes that would be needed to encode a
group field. |
static int |
computeInt32Size(int fieldNumber,
int value)
Compute the number of bytes that would be needed to encode an
int32 field, including tag. |
static int |
computeInt32SizeNoTag(int value)
Compute the number of bytes that would be needed to encode an
int32 field, including tag. |
static int |
computeInt64Size(int fieldNumber,
long value)
Compute the number of bytes that would be needed to encode an
int64 field, including tag. |
static int |
computeInt64SizeNoTag(long value)
Compute the number of bytes that would be needed to encode an
int64 field, including tag. |
static int |
computeMessageSize(int fieldNumber,
ProtoMessage<?> value)
Compute the number of bytes that would be needed to encode an
embedded message field, including tag.
|
static int |
computeMessageSizeNoTag(ProtoMessage value)
Compute the number of bytes that would be needed to encode an embedded
message field.
|
static int |
computeRawVarint32Size(int value)
Compute the number of bytes that would be needed to encode a varint.
|
static int |
computeRawVarint64Size(long value)
Compute the number of bytes that would be needed to encode a varint.
|
static int |
computeRepeatedBytesSizeNoTag(RepeatedBytes values)
Compute the number of bytes needed to encode all contained
bytes values |
static int |
computeRepeatedEnumSizeNoTag(RepeatedEnum<?> values)
Compute the number of bytes needed to encode all contained
enum values |
static int |
computeRepeatedGroupSizeNoTag(RepeatedMessage<?> values)
Compute the number of bytes needed to encode all contained
message values |
static int |
computeRepeatedInt32SizeNoTag(RepeatedInt values)
Compute the number of bytes needed to encode all contained
int32 values |
static int |
computeRepeatedInt64SizeNoTag(RepeatedLong values)
Compute the number of bytes needed to encode all contained
int32 values |
static int |
computeRepeatedMessageSizeNoTag(RepeatedMessage<?> values)
Compute the number of bytes needed to encode all contained
message values |
static int |
computeRepeatedSInt32SizeNoTag(RepeatedInt values)
Compute the number of bytes needed to encode all contained
sint32 values |
static int |
computeRepeatedSInt64SizeNoTag(RepeatedLong values)
Compute the number of bytes needed to encode all contained
sint64 values |
static int |
computeRepeatedStringSizeNoTag(RepeatedString values)
Compute the number of bytes needed to encode all contained
string values |
static int |
computeRepeatedUInt32SizeNoTag(RepeatedInt values)
Compute the number of bytes needed to encode all contained
uint32 values |
static int |
computeRepeatedUInt64SizeNoTag(RepeatedLong values)
Compute the number of bytes needed to encode all contained
uint64 values |
static int |
computeSFixed32Size(int fieldNumber,
int value)
Compute the number of bytes that would be needed to encode an
sfixed32 field, including tag. |
static int |
computeSFixed32SizeNoTag(int value)
Compute the number of bytes that would be needed to encode an
sfixed32 field. |
static int |
computeSFixed64Size(int fieldNumber,
long value)
Compute the number of bytes that would be needed to encode an
sfixed64 field, including tag. |
static int |
computeSFixed64SizeNoTag(long value)
Compute the number of bytes that would be needed to encode an
sfixed64 field. |
static int |
computeSInt32Size(int fieldNumber,
int value)
Compute the number of bytes that would be needed to encode an
sint32 field, including tag. |
static int |
computeSInt32SizeNoTag(int value)
Compute the number of bytes that would be needed to encode an
sint32 field. |
static int |
computeSInt64Size(int fieldNumber,
long value)
Compute the number of bytes that would be needed to encode an
sint64 field, including tag. |
static int |
computeSInt64SizeNoTag(long value)
Compute the number of bytes that would be needed to encode an
sint64 field. |
static int |
computeStringSize(int fieldNumber,
CharSequence value)
Compute the number of bytes that would be needed to encode a
string field, including tag. |
static int |
computeStringSizeNoTag(CharSequence value)
Compute the number of bytes that would be needed to encode a
string field. |
static int |
computeStringSizeNoTag(Utf8String value)
Compute the number of bytes that would be needed to encode a
string field. |
static int |
computeTagSize(int fieldNumber)
Compute the number of bytes that would be needed to encode a tag.
|
static int |
computeUInt32Size(int fieldNumber,
int value)
Compute the number of bytes that would be needed to encode a
uint32 field, including tag. |
static int |
computeUInt32SizeNoTag(int value)
Compute the number of bytes that would be needed to encode a
uint32 field. |
static int |
computeUInt64Size(int fieldNumber,
long value)
Compute the number of bytes that would be needed to encode a
uint64 field, including tag. |
static int |
computeUInt64SizeNoTag(long value)
Compute the number of bytes that would be needed to encode a
uint64 field, including tag. |
static int |
encodeZigZag32(int n)
Encode a ZigZag-encoded 32-bit value.
|
static long |
encodeZigZag64(long n)
Encode a ZigZag-encoded 64-bit value.
|
abstract int |
getTotalBytesWritten()
Get the total number of bytes successfully written to this sink.
|
static ProtoSink |
newArraySink()
Creates a new
ProtoSink that writes directly to a byte array. |
static ProtoSink |
newBufferSink()
Creates a new
ProtoSink that writes directly to a ByteBuffer. |
static ProtoSink |
newBytesSink()
Creates a new
ProtoSink that writes to a RepeatedByte. |
static ProtoSink |
newDirectSink()
Creates a new
ProtoSink that writes directly to a byte array or
direct memory. |
static ProtoSink |
newInstance(byte[] flatArray)
Create a new
ProtoSink that writes directly to the given
byte array. |
static ProtoSink |
newInstance(byte[] flatArray,
int offset,
int length)
Create a new
ProtoSink that writes directly to the given
byte array slice. |
static ProtoSink |
newInstance(ByteBuffer buffer)
Create a new ProtoSink writing to the given
ByteBuffer. |
static ProtoSink |
newInstance(OutputStream stream)
Create a new ProtoSink writing to the given
OutputStream. |
static ProtoSink |
newInstance(RepeatedByte bytes)
Create a new ProtoSink writing to the given
RepeatedByte. |
static ProtoSink |
newStreamSink()
Creates a new
ProtoSink that writes directly to an OutputStream. |
abstract ProtoSink |
reset()
Resets the position within the internal buffer to zero.
|
ProtoSink |
setOutput(byte[] buffer)
Changes the output to the given array.
|
ProtoSink |
setOutput(byte[] buffer,
long offset,
int length)
Changes the output to the given array.
|
ProtoSink |
setOutput(ByteBuffer buffer)
Changes the output to the given buffer.
|
ProtoSink |
setOutput(OutputStream stream)
Changes the output to the given stream.
|
ProtoSink |
setOutput(RepeatedByte bytes)
Changes the output to the given bytes.
|
int |
spaceLeft()
Returns remaining space when there is a known limit.
|
void |
writeBool(int fieldNumber,
boolean value)
Write a
bool field, including tag, to the sink. |
void |
writeBoolNoTag(boolean value)
Write a
bool field to the sink. |
void |
writeBytes(int fieldNumber,
RepeatedByte value)
Write a
bytes field, including tag, to the sink. |
void |
writeBytesNoTag(RepeatedByte value)
Write a
bytes field to the sink. |
void |
writeDouble(int fieldNumber,
double value)
Write a
double field, including tag, to the sink. |
void |
writeDoubleNoTag(double value)
Write a
double field to the sink. |
void |
writeEnum(int fieldNumber,
int value)
Write an enum field, including tag, to the sink.
|
void |
writeEnumNoTag(int value)
Write an enum field to the sink.
|
void |
writeFixed32(int fieldNumber,
int value)
Write a
fixed32 field, including tag, to the sink. |
void |
writeFixed32NoTag(int value)
Write a
fixed32 field to the sink. |
void |
writeFixed64(int fieldNumber,
long value)
Write a
fixed64 field, including tag, to the sink. |
void |
writeFixed64NoTag(long value)
Write a
fixed64 field to the sink. |
void |
writeFloat(int fieldNumber,
float value)
Write a
float field, including tag, to the sink. |
void |
writeFloatNoTag(float value)
Write a
float field to the sink. |
void |
writeGroup(int fieldNumber,
ProtoMessage value)
Write a
group field, including tag, to the sink. |
void |
writeGroupNoTag(ProtoMessage<?> value)
Write a
group field to the sink. |
void |
writeInt32(int fieldNumber,
int value)
Write an
int32 field, including tag, to the sink. |
void |
writeInt32NoTag(int value)
Write an
int32 field to the sink. |
void |
writeInt64(int fieldNumber,
long value)
Write an
int64 field, including tag, to the sink. |
void |
writeInt64NoTag(long value)
Write an
int64 field to the sink. |
void |
writeLength(int length)
Write a length delimiter to the sink
|
void |
writeMessage(int fieldNumber,
ProtoMessage value)
Write an embedded message field, including tag, to the sink.
|
void |
writeMessageNoTag(ProtoMessage<?> value)
Write an embedded message field to the sink.
|
protected void |
writeNegativeVarint32(int value)
write a negative
int32 that must be sign-extended to 10 bytes |
protected void |
writeNegativeVarint64(long value)
write a negative
int64 that must be sign-extended to 10 bytes |
void |
writePackedBoolNoTag(RepeatedBoolean values)
Write a repeated (non-packed)
bool field, excluding tag, to the sink. |
void |
writePackedDoubleNoTag(RepeatedDouble values)
Write a repeated (packed)
double field, excluding tag, to the sink. |
void |
writePackedEnumNoTag(RepeatedEnum<?> values)
Write a repeated (packed)
enum field to the sink. |
void |
writePackedFixed32NoTag(RepeatedInt values)
Write a repeated (packed)
fixed32 field, excluding tag, to the sink. |
void |
writePackedFixed64NoTag(RepeatedLong values)
Write a repeated (packed)
fixed64 field, excluding tag, to the sink. |
void |
writePackedFloatNoTag(RepeatedFloat values)
Write a repeated (packed)
float field, excluding tag, to the sink. |
void |
writePackedInt32NoTag(RepeatedInt values)
Write a repeated (packed)
int32 field to the sink. |
void |
writePackedInt64NoTag(RepeatedLong values)
Write a repeated (packed)
int32 field to the sink. |
void |
writePackedSFixed32NoTag(RepeatedInt values)
Write a repeated (packed)
sfixed32 field, excluding tag, to the sink. |
void |
writePackedSFixed64NoTag(RepeatedLong values)
Write a repeated (packed)
sfixed64 field, excluding tag, to the sink. |
void |
writePackedSInt32NoTag(RepeatedInt values)
Write a repeated (packed)
sint32 field to the sink. |
void |
writePackedSInt64NoTag(RepeatedLong values)
Write a repeated (packed)
sint64 field to the sink. |
void |
writePackedTag(int fieldNumber)
Encode and write a packed tag for the given field number.
|
void |
writePackedUInt32NoTag(RepeatedInt values)
Write a repeated (packed)
uint32 field to the sink. |
void |
writePackedUInt64NoTag(RepeatedLong values)
Write a repeated (packed)
uint32 field to the sink. |
protected void |
writeRawBooleans(boolean[] values,
int length) |
abstract void |
writeRawByte(byte value)
Write a single byte.
|
void |
writeRawByte(int value)
Write a single byte, represented by an integer value.
|
void |
writeRawBytes(byte[] value)
Write an array of bytes.
|
void |
writeRawBytes(byte[] value,
int offset,
int length)
Write part of an array of bytes.
|
void |
writeRawBytes(RepeatedByte bytes)
Writes the contents as an array of bytes
|
protected void |
writeRawDoubles(double[] values,
int length) |
protected void |
writeRawFixed32s(int[] values,
int length) |
protected void |
writeRawFixed64s(long[] values,
int length) |
protected void |
writeRawFloats(float[] values,
int length) |
void |
writeRawLittleEndian16(short value)
Write a little-endian 16-bit integer.
|
void |
writeRawLittleEndian32(int value)
Write a little-endian 32-bit integer.
|
void |
writeRawLittleEndian64(long value)
Write a little-endian 64-bit integer.
|
void |
writeRawVarint32(int value)
Deprecated.
|
void |
writeRawVarint64(long value)
Deprecated.
|
void |
writeSFixed32(int fieldNumber,
int value)
Write an
sfixed32 field, including tag, to the sink. |
void |
writeSFixed32NoTag(int value)
Write an
sfixed32 field to the sink. |
void |
writeSFixed64(int fieldNumber,
long value)
Write an
sfixed64 field, including tag, to the sink. |
void |
writeSFixed64NoTag(long value)
Write an
sfixed64 field to the sink. |
void |
writeSInt32(int fieldNumber,
int value)
Write an
sint32 field, including tag, to the sink. |
void |
writeSInt32NoTag(int value)
Write an
sint32 field to the sink. |
void |
writeSInt64(int fieldNumber,
long value)
Write an
sint64 field, including tag, to the sink. |
void |
writeSInt64NoTag(long value)
Write an
sint64 field to the sink. |
void |
writeString(int fieldNumber,
CharSequence value)
Write a
string field, including tag, to the sink. |
void |
writeStringNoTag(CharSequence value)
Write a
string field to the sink. |
void |
writeStringNoTag(Utf8String value)
Write a
string field to the sink. |
void |
writeTag(int fieldNumber,
int wireType)
Encode and write a tag.
|
void |
writeUInt32(int fieldNumber,
int value)
Write a
uint32 field, including tag, to the sink. |
static int |
writeUInt32(OutputStream output,
int value)
Encode and write a varint32 to an
OutputStream. |
void |
writeUInt32NoTag(int value)
Write a
uint32 field to the sink. |
void |
writeUInt64(int fieldNumber,
long value)
Write a
uint64 field, including tag, to the sink. |
void |
writeUInt64NoTag(long value)
Write a
uint64 field to the sink. |
public static ProtoSink newInstance(byte[] flatArray)
ProtoSink that writes directly to the given
byte array. If more bytes are written than fit in the array,
ProtoSink.OutOfSpaceException will be thrown.public static ProtoSink newInstance(byte[] flatArray, int offset, int length)
ProtoSink that writes directly to the given
byte array slice. If more bytes are written than fit in the slice,
ProtoSink.OutOfSpaceException will be thrown.public static ProtoSink newInstance(RepeatedByte bytes)
RepeatedByte.public static ProtoSink newInstance(OutputStream stream)
OutputStream.public static ProtoSink newInstance(ByteBuffer buffer)
ByteBuffer.public static ProtoSink newArraySink()
ProtoSink that writes directly to a byte array.
If more bytes are written than fit in the array, ProtoSink.OutOfSpaceException will
be thrown.
This method will return the fastest implementation available for the
current platform and may leverage features from sun.misc.Unsafe if
available.public static ProtoSink newDirectSink()
ProtoSink that writes directly to a byte array or
direct memory. If more bytes are written than fit in the array, an
ProtoSink.OutOfSpaceException will be thrown. It is similar to ArraySink,
but it allows null buffers to support raw memory addresses.
This sink requires availability of sun.misc.Unsafe. Be aware that
passing incorrect memory addresses may cause the entire runtime to
segfault.public static ProtoSink newBytesSink()
ProtoSink that writes to a RepeatedByte. The
size of the output grows automatically as more bytes are written.public static ProtoSink newStreamSink()
ProtoSink that writes directly to an OutputStream.
The implementation is lightweight and writes byte-by-byte without any internal
buffering. This is slower than writing to an array, but it does not require
extra memory.public static ProtoSink newBufferSink()
ProtoSink that writes directly to a ByteBuffer.
The current implementation is a very lightweight wrapper that writes
individual bytes. This is slower than writing to an array, but it
works on all platforms.public final ProtoSink setOutput(byte[] buffer)
public ProtoSink setOutput(byte[] buffer, long offset, int length)
public ProtoSink setOutput(RepeatedByte bytes)
public ProtoSink setOutput(OutputStream stream)
public ProtoSink setOutput(ByteBuffer buffer)
public abstract ProtoSink clear()
public void writeTag(int fieldNumber,
int wireType)
throws IOException
IOExceptionpublic void writePackedTag(int fieldNumber)
throws IOException
IOExceptionpublic void writeDouble(int fieldNumber,
double value)
throws IOException
double field, including tag, to the sink.IOExceptionpublic void writeFloat(int fieldNumber,
float value)
throws IOException
float field, including tag, to the sink.IOExceptionpublic void writeUInt64(int fieldNumber,
long value)
throws IOException
uint64 field, including tag, to the sink.IOExceptionpublic void writeInt64(int fieldNumber,
long value)
throws IOException
int64 field, including tag, to the sink.IOExceptionpublic void writeInt32(int fieldNumber,
int value)
throws IOException
int32 field, including tag, to the sink.IOExceptionpublic void writeFixed64(int fieldNumber,
long value)
throws IOException
fixed64 field, including tag, to the sink.IOExceptionpublic void writeFixed32(int fieldNumber,
int value)
throws IOException
fixed32 field, including tag, to the sink.IOExceptionpublic void writeBool(int fieldNumber,
boolean value)
throws IOException
bool field, including tag, to the sink.IOExceptionpublic void writeString(int fieldNumber,
CharSequence value)
throws IOException
string field, including tag, to the sink.IOExceptionpublic void writeGroup(int fieldNumber,
ProtoMessage value)
throws IOException
group field, including tag, to the sink.IOExceptionpublic void writeMessage(int fieldNumber,
ProtoMessage value)
throws IOException
IOExceptionpublic void writeBytes(int fieldNumber,
RepeatedByte value)
throws IOException
bytes field, including tag, to the sink.IOExceptionpublic void writeUInt32(int fieldNumber,
int value)
throws IOException
uint32 field, including tag, to the sink.IOExceptionpublic void writeEnum(int fieldNumber,
int value)
throws IOException
IOExceptionpublic void writeSFixed32(int fieldNumber,
int value)
throws IOException
sfixed32 field, including tag, to the sink.IOExceptionpublic void writeSFixed64(int fieldNumber,
long value)
throws IOException
sfixed64 field, including tag, to the sink.IOExceptionpublic void writeSInt32(int fieldNumber,
int value)
throws IOException
sint32 field, including tag, to the sink.IOExceptionpublic void writeSInt64(int fieldNumber,
long value)
throws IOException
sint64 field, including tag, to the sink.IOExceptionpublic void writePackedDoubleNoTag(RepeatedDouble values) throws IOException
double field, excluding tag, to the sink.IOExceptionpublic void writePackedFloatNoTag(RepeatedFloat values) throws IOException
float field, excluding tag, to the sink.IOExceptionpublic void writePackedFixed64NoTag(RepeatedLong values) throws IOException
fixed64 field, excluding tag, to the sink.IOExceptionpublic void writePackedFixed32NoTag(RepeatedInt values) throws IOException
fixed32 field, excluding tag, to the sink.IOExceptionpublic void writePackedSFixed32NoTag(RepeatedInt values) throws IOException
sfixed32 field, excluding tag, to the sink.IOExceptionpublic void writePackedSFixed64NoTag(RepeatedLong values) throws IOException
sfixed64 field, excluding tag, to the sink.IOExceptionpublic void writePackedBoolNoTag(RepeatedBoolean values) throws IOException
bool field, excluding tag, to the sink.IOExceptionprotected void writeRawDoubles(double[] values,
int length)
throws IOException
IOExceptionprotected void writeRawFloats(float[] values,
int length)
throws IOException
IOExceptionprotected void writeRawFixed64s(long[] values,
int length)
throws IOException
IOExceptionprotected void writeRawFixed32s(int[] values,
int length)
throws IOException
IOExceptionprotected void writeRawBooleans(boolean[] values,
int length)
throws IOException
IOExceptionpublic static int computeRepeatedEnumSizeNoTag(RepeatedEnum<?> values)
enum valuespublic void writePackedEnumNoTag(RepeatedEnum<?> values) throws IOException
enum field to the sink.IOExceptionpublic static int computeRepeatedInt32SizeNoTag(RepeatedInt values)
int32 valuespublic void writePackedInt32NoTag(RepeatedInt values) throws IOException
int32 field to the sink.IOExceptionpublic static int computeRepeatedUInt32SizeNoTag(RepeatedInt values)
uint32 valuespublic void writePackedUInt32NoTag(RepeatedInt values) throws IOException
uint32 field to the sink.IOExceptionpublic static int computeRepeatedSInt32SizeNoTag(RepeatedInt values)
sint32 valuespublic void writePackedSInt32NoTag(RepeatedInt values) throws IOException
sint32 field to the sink.IOExceptionpublic static int computeRepeatedInt64SizeNoTag(RepeatedLong values)
int32 valuespublic void writePackedInt64NoTag(RepeatedLong values) throws IOException
int32 field to the sink.IOExceptionpublic static int computeRepeatedUInt64SizeNoTag(RepeatedLong values)
uint64 valuespublic void writePackedUInt64NoTag(RepeatedLong values) throws IOException
uint32 field to the sink.IOExceptionpublic static int computeRepeatedSInt64SizeNoTag(RepeatedLong values)
sint64 valuespublic void writePackedSInt64NoTag(RepeatedLong values) throws IOException
sint64 field to the sink.IOExceptionpublic static int computeRepeatedMessageSizeNoTag(RepeatedMessage<?> values)
message valuespublic static int computeRepeatedGroupSizeNoTag(RepeatedMessage<?> values)
message valuespublic static int computeRepeatedStringSizeNoTag(RepeatedString values)
string valuespublic static int computeRepeatedBytesSizeNoTag(RepeatedBytes values)
bytes valuespublic void writeLength(int length)
throws IOException
IOExceptionpublic void writeDoubleNoTag(double value)
throws IOException
double field to the sink.IOExceptionpublic void writeFloatNoTag(float value)
throws IOException
float field to the sink.IOExceptionpublic void writeInt64NoTag(long value)
throws IOException
int64 field to the sink.IOExceptionpublic void writeInt32NoTag(int value)
throws IOException
int32 field to the sink.IOExceptionpublic void writeFixed64NoTag(long value)
throws IOException
fixed64 field to the sink.IOExceptionpublic void writeFixed32NoTag(int value)
throws IOException
fixed32 field to the sink.IOExceptionpublic void writeBoolNoTag(boolean value)
throws IOException
bool field to the sink.IOExceptionpublic void writeStringNoTag(Utf8String value) throws IOException
string field to the sink.IOExceptionpublic void writeStringNoTag(CharSequence value) throws IOException
string field to the sink.IOExceptionpublic void writeGroupNoTag(ProtoMessage<?> value) throws IOException
group field to the sink.IOExceptionpublic void writeMessageNoTag(ProtoMessage<?> value) throws IOException
IOExceptionpublic void writeBytesNoTag(RepeatedByte value) throws IOException
bytes field to the sink.IOExceptionpublic void writeEnumNoTag(int value)
throws IOException
IOExceptionpublic void writeSFixed32NoTag(int value)
throws IOException
sfixed32 field to the sink.IOExceptionpublic void writeSFixed64NoTag(long value)
throws IOException
sfixed64 field to the sink.IOExceptionpublic void writeSInt32NoTag(int value)
throws IOException
sint32 field to the sink.IOExceptionpublic void writeSInt64NoTag(long value)
throws IOException
sint64 field to the sink.IOExceptionpublic static int computeDoubleSize(int fieldNumber,
double value)
double field, including tag.public static int computeFloatSize(int fieldNumber,
float value)
float field, including tag.public static int computeUInt64Size(int fieldNumber,
long value)
uint64 field, including tag.public static int computeInt64Size(int fieldNumber,
long value)
int64 field, including tag.public static int computeInt32Size(int fieldNumber,
int value)
int32 field, including tag.public static int computeFixed64Size(int fieldNumber,
long value)
fixed64 field, including tag.public static int computeFixed32Size(int fieldNumber,
int value)
fixed32 field, including tag.public static int computeBoolSize(int fieldNumber,
boolean value)
bool field, including tag.public static int computeStringSize(int fieldNumber,
CharSequence value)
string field, including tag.public static int computeGroupSize(int fieldNumber,
ProtoMessage<?> value)
group field, including tag.public static int computeMessageSize(int fieldNumber,
ProtoMessage<?> value)
public static int computeBytesSize(int fieldNumber,
RepeatedByte value)
bytes field, including tag.public static int computeUInt32Size(int fieldNumber,
int value)
uint32 field, including tag.public static int computeEnumSize(int fieldNumber,
int value)
public static int computeSFixed32Size(int fieldNumber,
int value)
sfixed32 field, including tag.public static int computeSFixed64Size(int fieldNumber,
long value)
sfixed64 field, including tag.public static int computeSInt32Size(int fieldNumber,
int value)
sint32 field, including tag.public static int computeSInt64Size(int fieldNumber,
long value)
sint64 field, including tag.public static int computeDoubleSizeNoTag(double value)
double field, including tag.public static int computeFloatSizeNoTag(float value)
float field, including tag.public static int computeUInt64SizeNoTag(long value)
uint64 field, including tag.public static int computeInt64SizeNoTag(long value)
int64 field, including tag.public static int computeInt32SizeNoTag(int value)
int32 field, including tag.public static int computeFixed64SizeNoTag(long value)
fixed64 field.public static int computeFixed32SizeNoTag(int value)
fixed32 field.public static int computeBoolSizeNoTag(boolean value)
bool field.public static int computeStringSizeNoTag(Utf8String value)
string field.public static int computeStringSizeNoTag(CharSequence value)
string field.public static int computeGroupSizeNoTag(ProtoMessage value)
group field.public static int computeMessageSizeNoTag(ProtoMessage value)
public static int computeBytesSizeNoTag(RepeatedByte value)
bytes field.public static int computeUInt32SizeNoTag(int value)
uint32 field.public static int computeEnumSizeNoTag(int value)
public static int computeSFixed32SizeNoTag(int value)
sfixed32 field.public static int computeSFixed64SizeNoTag(long value)
sfixed64 field.public static int computeSInt32SizeNoTag(int value)
sint32 field.public static int computeSInt64SizeNoTag(long value)
sint64 field.public static int computeDelimitedSize(int length)
public int spaceLeft()
UnsupportedOperationException.public void checkNoSpaceLeft()
spaceLeft() returns zero. It's common to create
a byte array that is exactly big enough to hold a message, then write to
it with a ProtoSink. Calling checkNoSpaceLeft()
after writing verifies that the message was actually as big as expected,
which can help catch bugs.public abstract int getTotalBytesWritten()
public abstract ProtoSink reset()
getTotalBytesWritten(),
spaceLeft()public abstract void writeRawByte(byte value)
throws IOException
IOExceptionpublic void writeRawByte(int value)
throws IOException
IOExceptionpublic void writeRawBytes(byte[] value)
throws IOException
IOExceptionpublic void writeRawBytes(RepeatedByte bytes) throws IOException
IOExceptionpublic void writeRawBytes(byte[] value,
int offset,
int length)
throws IOException
IOExceptionpublic static int computeTagSize(int fieldNumber)
public void writeUInt32NoTag(int value)
throws IOException
uint32 field to the sink.IOExceptionpublic static int computeRawVarint32Size(int value)
value is treated as unsigned, so it won't be sign-extended if
negative.public void writeUInt64NoTag(long value)
throws IOException
uint64 field to the sink.IOExceptionpublic static int computeRawVarint64Size(long value)
protected void writeNegativeVarint32(int value)
throws IOException
int32 that must be sign-extended to 10 bytesIOExceptionprotected void writeNegativeVarint64(long value)
throws IOException
int64 that must be sign-extended to 10 bytesIOExceptionpublic void writeRawLittleEndian16(short value)
throws IOException
IOExceptionpublic void writeRawLittleEndian32(int value)
throws IOException
IOExceptionpublic void writeRawLittleEndian64(long value)
throws IOException
IOExceptionpublic static int encodeZigZag32(int n)
n - A signed 32-bit integer.public static long encodeZigZag64(long n)
n - A signed 64-bit integer.@Deprecated public void writeRawVarint32(int value) throws IOException
value is treated as
unsigned, so it won't be sign-extended if negative.IOException@Deprecated public void writeRawVarint64(long value) throws IOException
IOExceptionpublic static int writeUInt32(OutputStream output, int value) throws IOException
OutputStream. value is
treated as unsigned, so it won't be sign-extended if negative. This
can be used to write length delimiters before writing messages.value - uint32 value to be encoded as varintoutput - target streamIOExceptionCopyright © 2019–2024 HEBI Robotics. All rights reserved.