Package io.protostuff
Class ProtobufOutput
java.lang.Object
io.protostuff.WriteSession
io.protostuff.ProtobufOutput
- All Implemented Interfaces:
Output
Protobuf serialization where the messages must be fully buffered on memory before it can be written to the socket (
OutputStream
).-
Nested Class Summary
Nested classes/interfaces inherited from class io.protostuff.WriteSession
WriteSession.FlushHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
Fields inherited from class io.protostuff.WriteSession
flushHandler, head, nextBufferSize, out, sink, size, tail
-
Constructor Summary
ConstructorsConstructorDescriptionProtobufOutput
(LinkedBuffer buffer) ProtobufOutput
(LinkedBuffer buffer, int nextBufferSize) -
Method Summary
Modifier and TypeMethodDescriptionclear()
Resets this output for re-use.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
encodeZigZag32
(int n) Encode a ZigZag-encoded 32-bit value.static long
encodeZigZag64
(long n) Encode a ZigZag-encoded 64-bit value.static byte[]
getRawVarInt32Bytes
(int value) Returns the byte array computed from the var int 32 sizestatic byte[]
getTagAndRawLittleEndian32Bytes
(int tag, int value) Returns a byte array encoded with the tag and little endian 32static byte[]
getTagAndRawLittleEndian64Bytes
(int tag, long value) Returns a byte array encoded with the tag and little endian 64static byte[]
getTagAndRawVarInt32Bytes
(int tag, int value) Returns a byte array encoded with the tag and var int 32static byte[]
getTagAndRawVarInt64Bytes
(int tag, long value) Returns a byte array encoded with the tag and var int 64void
writeBool
(int fieldNumber, boolean value, boolean repeated) Writes a boolean field.void
writeByteArray
(int fieldNumber, byte[] bytes, boolean repeated) Writes a byte array field.void
writeByteRange
(boolean utf8String, int fieldNumber, byte[] value, int offset, int length, boolean repeated) Writes a binary or a pre-encoded utf8 string.void
writeBytes
(int fieldNumber, ByteString value, boolean repeated) Writes a ByteString(wraps byte array) field.void
writeBytes
(int fieldNumber, ByteBuffer value, boolean repeated) Writes a ByteBuffer field.void
writeDouble
(int fieldNumber, double value, boolean repeated) Writes a double field.void
writeEnum
(int fieldNumber, int number, boolean repeated) Writes a enum(its number) field.void
writeFixed32
(int fieldNumber, int value, boolean repeated) Writes a fixed int(4 bytes) field.void
writeFixed64
(int fieldNumber, long value, boolean repeated) Writes a fixed long(8 bytes) field.void
writeFloat
(int fieldNumber, float value, boolean repeated) Writes a float field.void
writeInt32
(int fieldNumber, int value, boolean repeated) Writes a variable int field.void
writeInt64
(int fieldNumber, long value, boolean repeated) Writes a variable long field.<T> void
writeObject
(int fieldNumber, T value, Schema<T> schema, boolean repeated) Writes an object(using its schema) field.static int
writeRawLittleEndian32
(int value, byte[] buffer, int offset) Writes the encoded little endian 32 and returns the bytes writtenstatic int
writeRawLittleEndian64
(long value, byte[] buffer, int offset) Writes the encoded little endian 64 and returns the bytes writtenstatic void
writeRawVarInt32
(int value, byte[] buf, int offset) Encode and write a varint to the byte arraystatic LinkedBuffer
writeRawVarInt32
(int value, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the variable int 32.static void
writeRawVarInt32Bytes
(DataOutput out, int value) Encode and write a varint to theDataOutput
static void
writeRawVarInt32Bytes
(OutputStream out, int value) Encode and write a varint to theOutputStream
void
writeSFixed32
(int fieldNumber, int value, boolean repeated) Writes a signed+fixed int(4 bytes) field.void
writeSFixed64
(int fieldNumber, long value, boolean repeated) Writes a signed+fixed long(8 bytes) field.void
writeSInt32
(int fieldNumber, int value, boolean repeated) Writes a signed int field.void
writeSInt64
(int fieldNumber, long value, boolean repeated) Writes a signed long field.void
writeString
(int fieldNumber, CharSequence value, boolean repeated) Writes a String field.static LinkedBuffer
writeTagAndByteArray
(int tag, byte[] value, int offset, int valueLen, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and byte arraystatic LinkedBuffer
writeTagAndLinkedBuffer
(int tag, LinkedBuffer buffer, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and LinkedBuffer (zero-copy)static LinkedBuffer
writeTagAndRawLittleEndian32
(int tag, int value, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and little endian 32static LinkedBuffer
writeTagAndRawLittleEndian64
(int tag, long value, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and little endian 64static LinkedBuffer
writeTagAndRawVarInt32
(int tag, int value, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and var int 32static LinkedBuffer
writeTagAndRawVarInt64
(int tag, long value, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and var int 64void
writeUInt32
(int fieldNumber, int value, boolean repeated) Writes an unsigned int field.void
writeUInt64
(int fieldNumber, long value, boolean repeated) Writes an unsigned long field.Methods inherited from class io.protostuff.WriteSession
flush, flush, flush, getSize, reset, toByteArray
-
Field Details
-
LITTLE_ENDIAN_32_SIZE
public static final int LITTLE_ENDIAN_32_SIZE- See Also:
-
LITTLE_ENDIAN_64_SIZE
public static final int LITTLE_ENDIAN_64_SIZE- See Also:
-
-
Constructor Details
-
ProtobufOutput
-
ProtobufOutput
-
-
Method Details
-
clear
Resets this output for re-use.- Overrides:
clear
in classWriteSession
-
writeInt32
Description copied from interface:Output
Writes a variable int field.- Specified by:
writeInt32
in interfaceOutput
- Throws:
IOException
-
writeUInt32
Description copied from interface:Output
Writes an unsigned int field.- Specified by:
writeUInt32
in interfaceOutput
- Throws:
IOException
-
writeSInt32
Description copied from interface:Output
Writes a signed int field.- Specified by:
writeSInt32
in interfaceOutput
- Throws:
IOException
-
writeFixed32
Description copied from interface:Output
Writes a fixed int(4 bytes) field.- Specified by:
writeFixed32
in interfaceOutput
- Throws:
IOException
-
writeSFixed32
Description copied from interface:Output
Writes a signed+fixed int(4 bytes) field.- Specified by:
writeSFixed32
in interfaceOutput
- Throws:
IOException
-
writeInt64
Description copied from interface:Output
Writes a variable long field.- Specified by:
writeInt64
in interfaceOutput
- Throws:
IOException
-
writeUInt64
Description copied from interface:Output
Writes an unsigned long field.- Specified by:
writeUInt64
in interfaceOutput
- Throws:
IOException
-
writeSInt64
Description copied from interface:Output
Writes a signed long field.- Specified by:
writeSInt64
in interfaceOutput
- Throws:
IOException
-
writeFixed64
Description copied from interface:Output
Writes a fixed long(8 bytes) field.- Specified by:
writeFixed64
in interfaceOutput
- Throws:
IOException
-
writeSFixed64
Description copied from interface:Output
Writes a signed+fixed long(8 bytes) field.- Specified by:
writeSFixed64
in interfaceOutput
- Throws:
IOException
-
writeFloat
Description copied from interface:Output
Writes a float field.- Specified by:
writeFloat
in interfaceOutput
- Throws:
IOException
-
writeDouble
Description copied from interface:Output
Writes a double field.- Specified by:
writeDouble
in interfaceOutput
- Throws:
IOException
-
writeBool
Description copied from interface:Output
Writes a boolean field.- Specified by:
writeBool
in interfaceOutput
- Throws:
IOException
-
writeEnum
Description copied from interface:Output
Writes a enum(its number) field.- Specified by:
writeEnum
in interfaceOutput
- Throws:
IOException
-
writeString
Description copied from interface:Output
Writes a String field.- Specified by:
writeString
in interfaceOutput
- Throws:
IOException
-
writeBytes
Description copied from interface:Output
Writes a ByteString(wraps byte array) field.- Specified by:
writeBytes
in interfaceOutput
- Throws:
IOException
-
writeByteArray
Description copied from interface:Output
Writes a byte array field.- Specified by:
writeByteArray
in interfaceOutput
- Throws:
IOException
-
writeByteRange
public void writeByteRange(boolean utf8String, int fieldNumber, byte[] value, int offset, int length, boolean repeated) throws IOException Description copied from interface:Output
Writes a binary or a pre-encoded utf8 string.- Specified by:
writeByteRange
in interfaceOutput
- Throws:
IOException
-
writeObject
public <T> void writeObject(int fieldNumber, T value, Schema<T> schema, boolean repeated) throws IOException Description copied from interface:Output
Writes an object(using its schema) field.- Specified by:
writeObject
in interfaceOutput
- Throws:
IOException
-
writeRawVarInt32
Returns the buffer encoded with the variable int 32. -
writeTagAndLinkedBuffer
public static LinkedBuffer writeTagAndLinkedBuffer(int tag, LinkedBuffer buffer, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and LinkedBuffer (zero-copy) -
writeTagAndByteArray
public static LinkedBuffer writeTagAndByteArray(int tag, byte[] value, int offset, int valueLen, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and byte array -
writeTagAndRawVarInt32
public static LinkedBuffer writeTagAndRawVarInt32(int tag, int value, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and var int 32 -
writeTagAndRawVarInt64
public static LinkedBuffer writeTagAndRawVarInt64(int tag, long value, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and var int 64 -
writeTagAndRawLittleEndian32
public static LinkedBuffer writeTagAndRawLittleEndian32(int tag, int value, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and little endian 32 -
writeTagAndRawLittleEndian64
public static LinkedBuffer writeTagAndRawLittleEndian64(int tag, long value, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and little endian 64 -
writeRawVarInt32
Encode and write a varint to the byte array- Throws:
IOException
-
writeRawVarInt32Bytes
Encode and write a varint to theOutputStream
- Throws:
IOException
-
writeRawVarInt32Bytes
Encode and write a varint to theDataOutput
- Throws:
IOException
-
getTagAndRawVarInt32Bytes
public static byte[] getTagAndRawVarInt32Bytes(int tag, int value) Returns a byte array encoded with the tag and var int 32 -
getTagAndRawVarInt64Bytes
public static byte[] getTagAndRawVarInt64Bytes(int tag, long value) Returns a byte array encoded with the tag and var int 64 -
getTagAndRawLittleEndian32Bytes
public static byte[] getTagAndRawLittleEndian32Bytes(int tag, int value) Returns a byte array encoded with the tag and little endian 32 -
getTagAndRawLittleEndian64Bytes
public static byte[] getTagAndRawLittleEndian64Bytes(int tag, long value) Returns a byte array encoded with the tag and little endian 64 -
writeRawLittleEndian32
public static int writeRawLittleEndian32(int value, byte[] buffer, int offset) Writes the encoded little endian 32 and returns the bytes written -
writeRawLittleEndian64
public static int writeRawLittleEndian64(long value, byte[] buffer, int offset) Writes the encoded little endian 64 and returns the bytes written -
getRawVarInt32Bytes
public static byte[] getRawVarInt32Bytes(int value) Returns the byte array computed from the var int 32 size -
computeRawVarint32Size
public static int computeRawVarint32Size(int value) Compute the number of bytes that would be needed to encode a varint.value
is treated as unsigned, so it won't be sign-extended if negative. -
computeRawVarint64Size
public static int computeRawVarint64Size(long value) Compute the number of bytes that would be needed to encode a varint. -
encodeZigZag32
public static int encodeZigZag32(int n) Encode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers into values that can be efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits to be varint encoded, thus always taking 10 bytes on the wire.)- Parameters:
n
- A signed 32-bit integer.- Returns:
- An unsigned 32-bit integer, stored in a signed int because Java has no explicit unsigned support.
-
encodeZigZag64
public static long encodeZigZag64(long n) Encode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers into values that can be efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits to be varint encoded, thus always taking 10 bytes on the wire.)- Parameters:
n
- A signed 64-bit integer.- Returns:
- An unsigned 64-bit integer, stored in a signed int because Java has no explicit unsigned support.
-
writeBytes
Writes a ByteBuffer field.- Specified by:
writeBytes
in interfaceOutput
- Throws:
IOException
-