public final class CodedOutputStream extends FilterOutputStream
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 | Field and Description |
---|---|
static int |
LITTLE_ENDIAN_32_SIZE |
static int |
LITTLE_ENDIAN_64_SIZE |
out
Constructor and Description |
---|
CodedOutputStream(Buffer data) |
CodedOutputStream(byte[] data) |
CodedOutputStream(OutputStream os) |
Modifier and Type | Method and Description |
---|---|
void |
checkNoSpaceLeft() |
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 |
computeBytesSize(int fieldNumber,
Buffer value)
Compute the number of bytes that would be needed to encode a
bytes field, including tag. |
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 |
computeEnumSize(int fieldNumber,
int value)
Compute the number of bytes that would be needed to encode an enum field,
including tag.
|
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 |
computeFixed64Size(int fieldNumber,
long value)
Compute the number of bytes that would be needed to encode a
fixed64 field, including tag. |
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 |
computeInt32Size(int fieldNumber,
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 |
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 |
computeSFixed32Size(int fieldNumber,
int value)
Compute the number of bytes that would be needed to encode an
sfixed32 field, including tag. |
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 |
computeSInt32Size(int fieldNumber,
int value)
Compute the number of bytes that would be needed to encode an
sint32 field, including tag. |
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 |
computeStringSize(int fieldNumber,
String value)
Compute the number of bytes that would be needed to encode a
string field, including tag. |
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 |
computeUInt64Size(int fieldNumber,
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.
|
Buffer |
getNextBuffer(int size) |
void |
writeBool(int fieldNumber,
boolean value)
Write a
bool field, including tag, to the stream. |
void |
writeBytes(int fieldNumber,
Buffer value)
Write a
bytes field, including tag, to the stream. |
void |
writeDouble(int fieldNumber,
double value)
Write a
double field, including tag, to the stream. |
void |
writeEnum(int fieldNumber,
int value)
Write an enum field, including tag, to the stream.
|
void |
writeFixed32(int fieldNumber,
int value)
Write a
fixed32 field, including tag, to the stream. |
void |
writeFixed64(int fieldNumber,
long value)
Write a
fixed64 field, including tag, to the stream. |
void |
writeFloat(int fieldNumber,
float value)
Write a
float field, including tag, to the stream. |
void |
writeInt32(int fieldNumber,
int value)
Write an
int32 field, including tag, to the stream. |
void |
writeInt64(int fieldNumber,
long value)
Write an
int64 field, including tag, to the stream. |
void |
writeRawByte(byte value)
Write a single byte.
|
void |
writeRawByte(int value)
Write a single byte, represented by an integer value.
|
void |
writeRawBytes(Buffer data) |
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 |
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)
Encode and write a varint.
|
void |
writeRawVarint64(long value)
Encode and write a varint.
|
void |
writeSFixed32(int fieldNumber,
int value)
Write an
sfixed32 field, including tag, to the stream. |
void |
writeSFixed64(int fieldNumber,
long value)
Write an
sfixed64 field, including tag, to the stream. |
void |
writeSInt32(int fieldNumber,
int value)
Write an
sint32 field, including tag, to the stream. |
void |
writeSInt64(int fieldNumber,
long value)
Write an
sint64 field, including tag, to the stream. |
void |
writeString(int fieldNumber,
String value)
Write a
string field, including tag, to the stream. |
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 stream. |
void |
writeUInt64(int fieldNumber,
long value)
Write a
uint64 field, including tag, to the stream. |
public static final int LITTLE_ENDIAN_32_SIZE
public static final int LITTLE_ENDIAN_64_SIZE
public CodedOutputStream(OutputStream os)
public CodedOutputStream(byte[] data)
public CodedOutputStream(Buffer data)
public void writeDouble(int fieldNumber, double value) throws IOException
double
field, including tag, to the stream.IOException
public void writeFloat(int fieldNumber, float value) throws IOException
float
field, including tag, to the stream.IOException
public void writeUInt64(int fieldNumber, long value) throws IOException
uint64
field, including tag, to the stream.IOException
public void writeInt64(int fieldNumber, long value) throws IOException
int64
field, including tag, to the stream.IOException
public void writeInt32(int fieldNumber, int value) throws IOException
int32
field, including tag, to the stream.IOException
public void writeFixed64(int fieldNumber, long value) throws IOException
fixed64
field, including tag, to the stream.IOException
public void writeFixed32(int fieldNumber, int value) throws IOException
fixed32
field, including tag, to the stream.IOException
public void writeBool(int fieldNumber, boolean value) throws IOException
bool
field, including tag, to the stream.IOException
public void writeString(int fieldNumber, String value) throws IOException
string
field, including tag, to the stream.IOException
public void writeBytes(int fieldNumber, Buffer value) throws IOException
bytes
field, including tag, to the stream.IOException
public void writeUInt32(int fieldNumber, int value) throws IOException
uint32
field, including tag, to the stream.IOException
public void writeEnum(int fieldNumber, int value) throws IOException
IOException
public void writeSFixed32(int fieldNumber, int value) throws IOException
sfixed32
field, including tag, to the stream.IOException
public void writeSFixed64(int fieldNumber, long value) throws IOException
sfixed64
field, including tag, to the stream.IOException
public void writeSInt32(int fieldNumber, int value) throws IOException
sint32
field, including tag, to the stream.IOException
public void writeSInt64(int fieldNumber, long value) throws IOException
sint64
field, including tag, to the stream.IOException
public 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, String value)
string
field, including tag.public static int computeBytesSize(int fieldNumber, Buffer 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 void writeRawByte(byte value) throws IOException
IOException
public void writeRawByte(int value) throws IOException
IOException
public void writeRawBytes(byte[] value) throws IOException
IOException
public void writeRawBytes(byte[] value, int offset, int length) throws IOException
IOException
public void writeRawBytes(Buffer data) throws IOException
IOException
public void writeTag(int fieldNumber, int wireType) throws IOException
IOException
public static int computeTagSize(int fieldNumber)
public void writeRawVarint32(int value) throws IOException
value
is treated as unsigned, so it
won't be sign-extended if negative.IOException
public static int computeRawVarint32Size(int value)
value
is treated as unsigned, so it won't be sign-extended if
negative.public void writeRawVarint64(long value) throws IOException
IOException
public static int computeRawVarint64Size(long value)
public void writeRawLittleEndian32(int value) throws IOException
IOException
public void writeRawLittleEndian64(long value) throws IOException
IOException
public static int encodeZigZag32(int n)
n
- A signed 32-bit integer.public static long encodeZigZag64(long n)
n
- A signed 64-bit integer.public void checkNoSpaceLeft()
public Buffer getNextBuffer(int size) throws IOException
IOException
Copyright © 2010–2021 FuseSource, Corp.. All rights reserved.