Class LengthPrefixedFields
java.lang.Object
io.github.flink.gcp.connector.bigtable.LengthPrefixedFields
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 Summary
Modifier and TypeMethodDescriptionstatic byte[]Returns the calling thread's copy buffer, for a serializer'scopyto pass through everycopyByteArray(org.apache.flink.core.memory.DataInputView, org.apache.flink.core.memory.DataOutputView, byte[], java.lang.String)of one record.static voidcopyByteArray(org.apache.flink.core.memory.DataInputView source, org.apache.flink.core.memory.DataOutputView target, byte[] buffer, String description) Copies one length-prefixed field from the input to the output without decoding it.static com.google.protobuf.ByteStringreadBytes(org.apache.flink.core.memory.DataInputView source) Reads a byte string written bywriteBytes(com.google.protobuf.ByteString, org.apache.flink.core.memory.DataOutputView).static intReads a count and checks it is not negative.static StringreadString(org.apache.flink.core.memory.DataInputView source) Reads a string written bywriteString(java.lang.String, org.apache.flink.core.memory.DataOutputView).static voidwriteBytes(com.google.protobuf.ByteString value, org.apache.flink.core.memory.DataOutputView target) Writes a byte string as its length and bytes, chunk by chunk through the copy buffer so a rope is never flattened.static voidwriteString(String value, org.apache.flink.core.memory.DataOutputView target) Writes a string as its UTF-8 length and bytes.
-
Method Details
-
copyBuffer
public static byte[] copyBuffer()Returns the calling thread's copy buffer, for a serializer'scopyto pass through everycopyByteArray(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 stringtarget- the output- Throws:
IOException- if the output fails
-
readString
public static String readString(org.apache.flink.core.memory.DataInputView source) throws IOException Reads a string written bywriteString(java.lang.String, org.apache.flink.core.memory.DataOutputView).- 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 bytestarget- 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 Reads a byte string written bywriteBytes(com.google.protobuf.ByteString, org.apache.flink.core.memory.DataOutputView).- 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 inputtarget- the outputbuffer- the copy buffer, fromcopyBuffer()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 inputdescription- what is counted, for the failure message- Returns:
- the count
- Throws:
IOException- if the input fails or the count is negative
-