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 WriteSession
WriteSession.FlushHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intFields inherited from class 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 intcomputeRawVarint32Size(int value) Compute the number of bytes that would be needed to encode a varint.static intcomputeRawVarint64Size(long value) Compute the number of bytes that would be needed to encode a varint.static intencodeZigZag32(int n) Encode a ZigZag-encoded 32-bit value.static longencodeZigZag64(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 64voidwriteBool(int fieldNumber, boolean value, boolean repeated) Writes a boolean field.voidwriteByteArray(int fieldNumber, byte[] bytes, boolean repeated) Writes a byte array field.voidwriteByteRange(boolean utf8String, int fieldNumber, byte[] value, int offset, int length, boolean repeated) Writes a binary or a pre-encoded utf8 string.voidwriteBytes(int fieldNumber, ByteString value, boolean repeated) Writes a ByteString(wraps byte array) field.voidwriteBytes(int fieldNumber, ByteBuffer value, boolean repeated) Writes a ByteBuffer field.voidwriteDouble(int fieldNumber, double value, boolean repeated) Writes a double field.voidwriteEnum(int fieldNumber, int number, boolean repeated) Writes a enum(its number) field.voidwriteFixed32(int fieldNumber, int value, boolean repeated) Writes a fixed int(4 bytes) field.voidwriteFixed64(int fieldNumber, long value, boolean repeated) Writes a fixed long(8 bytes) field.voidwriteFloat(int fieldNumber, float value, boolean repeated) Writes a float field.voidwriteInt32(int fieldNumber, int value, boolean repeated) Writes a variable int field.voidwriteInt64(int fieldNumber, long value, boolean repeated) Writes a variable long field.<T> voidwriteObject(int fieldNumber, T value, Schema<T> schema, boolean repeated) Writes an object(using its schema) field.static intwriteRawLittleEndian32(int value, byte[] buffer, int offset) Writes the encoded little endian 32 and returns the bytes writtenstatic intwriteRawLittleEndian64(long value, byte[] buffer, int offset) Writes the encoded little endian 64 and returns the bytes writtenstatic voidwriteRawVarInt32(int value, byte[] buf, int offset) Encode and write a varint to the byte arraystatic LinkedBufferwriteRawVarInt32(int value, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the variable int 32.static voidwriteRawVarInt32Bytes(DataOutput out, int value) Encode and write a varint to theDataOutputstatic voidwriteRawVarInt32Bytes(OutputStream out, int value) Encode and write a varint to theOutputStreamvoidwriteSFixed32(int fieldNumber, int value, boolean repeated) Writes a signed+fixed int(4 bytes) field.voidwriteSFixed64(int fieldNumber, long value, boolean repeated) Writes a signed+fixed long(8 bytes) field.voidwriteSInt32(int fieldNumber, int value, boolean repeated) Writes a signed int field.voidwriteSInt64(int fieldNumber, long value, boolean repeated) Writes a signed long field.voidwriteString(int fieldNumber, CharSequence value, boolean repeated) Writes a String field.static LinkedBufferwriteTagAndByteArray(int tag, byte[] value, int offset, int valueLen, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and byte arraystatic LinkedBufferwriteTagAndLinkedBuffer(int tag, LinkedBuffer buffer, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and LinkedBuffer (zero-copy)static LinkedBufferwriteTagAndRawLittleEndian32(int tag, int value, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and little endian 32static LinkedBufferwriteTagAndRawLittleEndian64(int tag, long value, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and little endian 64static LinkedBufferwriteTagAndRawVarInt32(int tag, int value, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and var int 32static LinkedBufferwriteTagAndRawVarInt64(int tag, long value, WriteSession session, LinkedBuffer lb) Returns the buffer encoded with the tag and var int 64voidwriteUInt32(int fieldNumber, int value, boolean repeated) Writes an unsigned int field.voidwriteUInt64(int fieldNumber, long value, boolean repeated) Writes an unsigned long field.Methods inherited from class 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
-
writeInt32
Description copied from interface:OutputWrites a variable int field.- Specified by:
writeInt32in interfaceOutput- Throws:
IOException
-
writeUInt32
Description copied from interface:OutputWrites an unsigned int field.- Specified by:
writeUInt32in interfaceOutput- Throws:
IOException
-
writeSInt32
Description copied from interface:OutputWrites a signed int field.- Specified by:
writeSInt32in interfaceOutput- Throws:
IOException
-
writeFixed32
Description copied from interface:OutputWrites a fixed int(4 bytes) field.- Specified by:
writeFixed32in interfaceOutput- Throws:
IOException
-
writeSFixed32
Description copied from interface:OutputWrites a signed+fixed int(4 bytes) field.- Specified by:
writeSFixed32in interfaceOutput- Throws:
IOException
-
writeInt64
Description copied from interface:OutputWrites a variable long field.- Specified by:
writeInt64in interfaceOutput- Throws:
IOException
-
writeUInt64
Description copied from interface:OutputWrites an unsigned long field.- Specified by:
writeUInt64in interfaceOutput- Throws:
IOException
-
writeSInt64
Description copied from interface:OutputWrites a signed long field.- Specified by:
writeSInt64in interfaceOutput- Throws:
IOException
-
writeFixed64
Description copied from interface:OutputWrites a fixed long(8 bytes) field.- Specified by:
writeFixed64in interfaceOutput- Throws:
IOException
-
writeSFixed64
Description copied from interface:OutputWrites a signed+fixed long(8 bytes) field.- Specified by:
writeSFixed64in interfaceOutput- Throws:
IOException
-
writeFloat
Description copied from interface:OutputWrites a float field.- Specified by:
writeFloatin interfaceOutput- Throws:
IOException
-
writeDouble
Description copied from interface:OutputWrites a double field.- Specified by:
writeDoublein interfaceOutput- Throws:
IOException
-
writeBool
Description copied from interface:OutputWrites a boolean field.- Specified by:
writeBoolin interfaceOutput- Throws:
IOException
-
writeEnum
Description copied from interface:OutputWrites a enum(its number) field.- Specified by:
writeEnumin interfaceOutput- Throws:
IOException
-
writeString
Description copied from interface:OutputWrites a String field.- Specified by:
writeStringin interfaceOutput- Throws:
IOException
-
writeBytes
Description copied from interface:OutputWrites a ByteString(wraps byte array) field.- Specified by:
writeBytesin interfaceOutput- Throws:
IOException
-
writeByteArray
Description copied from interface:OutputWrites a byte array field.- Specified by:
writeByteArrayin 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:OutputWrites a binary or a pre-encoded utf8 string.- Specified by:
writeByteRangein interfaceOutput- Throws:
IOException
-
writeObject
public <T> void writeObject(int fieldNumber, T value, Schema<T> schema, boolean repeated) throws IOException Description copied from interface:OutputWrites an object(using its schema) field.- Specified by:
writeObjectin 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.valueis 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:
writeBytesin interfaceOutput- Throws:
IOException
-