Package io.protostuff

Class ProtobufOutput

java.lang.Object
io.protostuff.WriteSession
io.protostuff.ProtobufOutput
All Implemented Interfaces:
Output

public final class ProtobufOutput extends WriteSession implements Output
Protobuf serialization where the messages must be fully buffered on memory before it can be written to the socket ( OutputStream).
  • Field Details

  • Constructor Details

    • ProtobufOutput

      public ProtobufOutput(LinkedBuffer buffer)
    • ProtobufOutput

      public ProtobufOutput(LinkedBuffer buffer, int nextBufferSize)
  • Method Details

    • clear

      public ProtobufOutput clear()
      Resets this output for re-use.
      Overrides:
      clear in class WriteSession
    • writeInt32

      public void writeInt32(int fieldNumber, int value, boolean repeated) throws IOException
      Description copied from interface: Output
      Writes a variable int field.
      Specified by:
      writeInt32 in interface Output
      Throws:
      IOException
    • writeUInt32

      public void writeUInt32(int fieldNumber, int value, boolean repeated) throws IOException
      Description copied from interface: Output
      Writes an unsigned int field.
      Specified by:
      writeUInt32 in interface Output
      Throws:
      IOException
    • writeSInt32

      public void writeSInt32(int fieldNumber, int value, boolean repeated) throws IOException
      Description copied from interface: Output
      Writes a signed int field.
      Specified by:
      writeSInt32 in interface Output
      Throws:
      IOException
    • writeFixed32

      public void writeFixed32(int fieldNumber, int value, boolean repeated) throws IOException
      Description copied from interface: Output
      Writes a fixed int(4 bytes) field.
      Specified by:
      writeFixed32 in interface Output
      Throws:
      IOException
    • writeSFixed32

      public void writeSFixed32(int fieldNumber, int value, boolean repeated) throws IOException
      Description copied from interface: Output
      Writes a signed+fixed int(4 bytes) field.
      Specified by:
      writeSFixed32 in interface Output
      Throws:
      IOException
    • writeInt64

      public void writeInt64(int fieldNumber, long value, boolean repeated) throws IOException
      Description copied from interface: Output
      Writes a variable long field.
      Specified by:
      writeInt64 in interface Output
      Throws:
      IOException
    • writeUInt64

      public void writeUInt64(int fieldNumber, long value, boolean repeated) throws IOException
      Description copied from interface: Output
      Writes an unsigned long field.
      Specified by:
      writeUInt64 in interface Output
      Throws:
      IOException
    • writeSInt64

      public void writeSInt64(int fieldNumber, long value, boolean repeated) throws IOException
      Description copied from interface: Output
      Writes a signed long field.
      Specified by:
      writeSInt64 in interface Output
      Throws:
      IOException
    • writeFixed64

      public void writeFixed64(int fieldNumber, long value, boolean repeated) throws IOException
      Description copied from interface: Output
      Writes a fixed long(8 bytes) field.
      Specified by:
      writeFixed64 in interface Output
      Throws:
      IOException
    • writeSFixed64

      public void writeSFixed64(int fieldNumber, long value, boolean repeated) throws IOException
      Description copied from interface: Output
      Writes a signed+fixed long(8 bytes) field.
      Specified by:
      writeSFixed64 in interface Output
      Throws:
      IOException
    • writeFloat

      public void writeFloat(int fieldNumber, float value, boolean repeated) throws IOException
      Description copied from interface: Output
      Writes a float field.
      Specified by:
      writeFloat in interface Output
      Throws:
      IOException
    • writeDouble

      public void writeDouble(int fieldNumber, double value, boolean repeated) throws IOException
      Description copied from interface: Output
      Writes a double field.
      Specified by:
      writeDouble in interface Output
      Throws:
      IOException
    • writeBool

      public void writeBool(int fieldNumber, boolean value, boolean repeated) throws IOException
      Description copied from interface: Output
      Writes a boolean field.
      Specified by:
      writeBool in interface Output
      Throws:
      IOException
    • writeEnum

      public void writeEnum(int fieldNumber, int number, boolean repeated) throws IOException
      Description copied from interface: Output
      Writes a enum(its number) field.
      Specified by:
      writeEnum in interface Output
      Throws:
      IOException
    • writeString

      public void writeString(int fieldNumber, CharSequence value, boolean repeated) throws IOException
      Description copied from interface: Output
      Writes a String field.
      Specified by:
      writeString in interface Output
      Throws:
      IOException
    • writeBytes

      public void writeBytes(int fieldNumber, ByteString value, boolean repeated) throws IOException
      Description copied from interface: Output
      Writes a ByteString(wraps byte array) field.
      Specified by:
      writeBytes in interface Output
      Throws:
      IOException
    • writeByteArray

      public void writeByteArray(int fieldNumber, byte[] bytes, boolean repeated) throws IOException
      Description copied from interface: Output
      Writes a byte array field.
      Specified by:
      writeByteArray in interface Output
      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 interface Output
      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 interface Output
      Throws:
      IOException
    • writeRawVarInt32

      public static LinkedBuffer writeRawVarInt32(int value, WriteSession session, LinkedBuffer lb)
      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

      public static void writeRawVarInt32(int value, byte[] buf, int offset) throws IOException
      Encode and write a varint to the byte array
      Throws:
      IOException
    • writeRawVarInt32Bytes

      public static void writeRawVarInt32Bytes(OutputStream out, int value) throws IOException
      Encode and write a varint to the OutputStream
      Throws:
      IOException
    • writeRawVarInt32Bytes

      public static void writeRawVarInt32Bytes(DataOutput out, int value) throws IOException
      Encode and write a varint to the DataOutput
      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

      public void writeBytes(int fieldNumber, ByteBuffer value, boolean repeated) throws IOException
      Writes a ByteBuffer field.
      Specified by:
      writeBytes in interface Output
      Throws:
      IOException