Class LengthPrefixedFields

java.lang.Object
io.github.flink.gcp.connector.bigtable.LengthPrefixedFields

@Internal public final class LengthPrefixedFields extends Object
The length-prefixed fields the connector-owned TypeSerializers share: a byte string or a UTF-8 string as an int length followed by the bytes, and a non-negative int count. Each serializer's format is its own; only the field encoding is common.

A read rejects a negative length or count with a named IOException before it allocates. A positive length the stream cannot back is allocated first and then fails as the truncation it is, so a corrupt or foreign stream can fail in that allocation or cost one oversized allocation before it is refused: no field here has a bound both serializers could share. The copy buffer is a ThreadLocal because a serializer's duplicate() returns this and task threads therefore share one instance.

  • Method Details

    • copyBuffer

      public static byte[] copyBuffer()
      Returns the calling thread's copy buffer, for a serializer's copy to pass through every copyByteArray(org.apache.flink.core.memory.DataInputView, org.apache.flink.core.memory.DataOutputView, byte[], java.lang.String) of one record.
      Returns:
      the buffer
    • writeString

      public static void writeString(String value, org.apache.flink.core.memory.DataOutputView target) throws IOException
      Writes a string as its UTF-8 length and bytes.
      Parameters:
      value - the string
      target - the output
      Throws:
      IOException - if the output fails
    • readString

      public static String readString(org.apache.flink.core.memory.DataInputView source) throws IOException
      Parameters:
      source - the input
      Returns:
      the string
      Throws:
      IOException - if the input fails or the length is negative
    • writeBytes

      public static void writeBytes(com.google.protobuf.ByteString value, org.apache.flink.core.memory.DataOutputView target) throws IOException
      Writes a byte string as its length and bytes, chunk by chunk through the copy buffer so a rope is never flattened.
      Parameters:
      value - the bytes
      target - the output
      Throws:
      IOException - if the output fails
    • readBytes

      public static com.google.protobuf.ByteString readBytes(org.apache.flink.core.memory.DataInputView source) throws IOException
      Parameters:
      source - the input
      Returns:
      the bytes
      Throws:
      IOException - if the input fails or the length is negative
    • copyByteArray

      public static void copyByteArray(org.apache.flink.core.memory.DataInputView source, org.apache.flink.core.memory.DataOutputView target, byte[] buffer, String description) throws IOException
      Copies one length-prefixed field from the input to the output without decoding it.
      Parameters:
      source - the input
      target - the output
      buffer - the copy buffer, from copyBuffer()
      description - what the field is, for the failure message
      Throws:
      IOException - if the input or output fails or the length is negative
    • readCount

      public static int readCount(org.apache.flink.core.memory.DataInputView source, String description) throws IOException
      Reads a count and checks it is not negative.
      Parameters:
      source - the input
      description - what is counted, for the failure message
      Returns:
      the count
      Throws:
      IOException - if the input fails or the count is negative