Package io.deephaven.enterprise.codec
Class ByteArrayCodec
java.lang.Object
io.deephaven.enterprise.codec.ByteArrayCodec
- All Implemented Interfaces:
ObjectCodec<byte[]>,ObjectDecoder<byte[]>
A codec to read/write byte arrays. This codec does not process null values so that any byte[] can be encoded
in the minimum number of bytes within the binary log file.
-
Field Summary
Fields inherited from interface com.illumon.util.codec.ObjectDecoder
VARIABLE_WIDTH_SENTINEL -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]decode(byte[] input, int offset, int length) Decode an object from an array of bytes.byte[]decode(ByteBuffer byteBuffer) Decode a byte array from the inputByteBufferstatic byte[]decodeStatic(ByteBuffer byteBuffer) byte[]encode(byte[] input) Encode the specified input as an array of bytes.encodeAndGet(byte[] input) Encode the input array into the internal buffer and return it.static voidencodeInto(byte[] input, ByteBuffer byteBuffer) Encode the input values to the specified buffer.intWhat width byte array does this ObjectCodec expect to encode and decode?intIf applicable, the maximum encodable precision.intgetScale()If applicable, the maximum encodable scale.booleanDoes this codec support encoding of null values?static ByteBuffermaybeGetResizedBuffer(byte[] input, ByteBuffer origBuffer) Inspect the input buffer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.illumon.util.codec.ObjectDecoder
checkWidth
-
Constructor Details
-
ByteArrayCodec
public ByteArrayCodec() -
ByteArrayCodec
-
ByteArrayCodec
-
-
Method Details
-
encodeAndGet
Encode the input array into the internal buffer and return it.- Parameters:
input- the array to encode- Returns:
- a reference to the internal byte buffer
-
maybeGetResizedBuffer
@NotNull public static ByteBuffer maybeGetResizedBuffer(@NotNull byte[] input, @Nullable ByteBuffer origBuffer) Inspect the input buffer. If it is large enough to encode input, clear and return it, otherwise allocate a new buffer with an appropriate capacity and return that.- Parameters:
input- the input to encodeorigBuffer- the original buffer to maybe resize.- Returns:
- a properly sized byte buffer to encode input.
-
encodeInto
Encode the input values to the specified buffer.- Parameters:
input- the input, may be null.byteBuffer- the buffer to encode into
-
decode
Decode a byte array from the inputByteBuffer- Parameters:
byteBuffer- the buffer containing the encoded byte array- Returns:
- the decoded byte array
-
decodeStatic
-
encode
@NotNull public byte[] encode(@Nullable byte[] input) Description copied from interface:ObjectCodecEncode the specified input as an array of bytes. Note that it is up to the implementation how to encode null inputs. The use of a zero-length byte array (e.g.CollectionUtil.ZERO_LENGTH_BYTE_ARRAY) is strongly encouraged.- Specified by:
encodein interfaceObjectCodec<byte[]>- Parameters:
input- The input object, possibly null- Returns:
- The output byte array
-
isNullable
public boolean isNullable()Description copied from interface:ObjectCodecDoes this codec support encoding of null values?- Specified by:
isNullablein interfaceObjectCodec<byte[]>- Returns:
- if null values are supported
-
getPrecision
public int getPrecision()Description copied from interface:ObjectCodecIf applicable, the maximum encodable precision. If precision is not applicable (i.e. for non-numeric types) this method should return zero.- Specified by:
getPrecisionin interfaceObjectCodec<byte[]>- Returns:
- the numeric precision supported by this codec
-
getScale
public int getScale()Description copied from interface:ObjectCodecIf applicable, the maximum encodable scale. If scale is not applicable (i.e. for non-numeric types) this method should return zero.- Specified by:
getScalein interfaceObjectCodec<byte[]>- Returns:
- the numeric scale (digits after the decimal point) supported by this codec
-
decode
@Nullable public byte[] decode(@NotNull byte[] input, int offset, int length) Description copied from interface:ObjectDecoderDecode an object from an array of bytes.- Specified by:
decodein interfaceObjectDecoder<byte[]>- Parameters:
input- The input byte array containing bytes to decodeoffset- The offset into the byte array to start decoding fromlength- The length of the byte array to decode from, starting at the offset- Returns:
- The output object, possibly null
-
expectedObjectWidth
public int expectedObjectWidth()Description copied from interface:ObjectDecoderWhat width byte array does this ObjectCodec expect to encode and decode?- Specified by:
expectedObjectWidthin interfaceObjectDecoder<byte[]>- Returns:
- VARIABLE_WIDTH_SENTINEL if the codec must encode and decode variable width columns, otherwise the fixed size of byte array that must be decoded and encoded.
-