Package com.illumon.util.codec
Class IntArrayCodec
java.lang.Object
com.illumon.util.codec.IntArrayCodec
- All Implemented Interfaces:
ObjectCodec<int[]>
,ObjectDecoder<int[]>
A codec to read/write int arrays. This is intended for use in loggers, listeners, and the database.
-
Field Summary
Fields inherited from interface com.illumon.util.codec.ObjectDecoder
VARIABLE_WIDTH_SENTINEL
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint[]
decode
(byte[] input, int offset, int length) Decode an object from an array of bytes.int[]
decode
(ByteBuffer byteBuffer) Decode an int array from the inputByteBuffer
byte[]
encode
(int[] input) Encode the specified input as an array of bytes.encodeAndGet
(int[] input) Encode the input array into the internal buffer and return it.int
What width byte array does this ObjectCodec expect to encode and decode?int
If applicable, the maximum encodable precision.int
getScale()
If applicable, the maximum encodable scale.boolean
Does this codec support encoding of null values?Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.illumon.util.codec.ObjectDecoder
checkWidth
-
Constructor Details
-
IntArrayCodec
public IntArrayCodec() -
IntArrayCodec
-
-
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
-
decode
Decode an int array from the inputByteBuffer
- Parameters:
byteBuffer
- the buffer containing the encoded int array- Returns:
- the decoded string array
-
encode
@NotNull public byte[] encode(@Nullable int[] input) Description copied from interface:ObjectCodec
Encode 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:
encode
in interfaceObjectCodec<int[]>
- Parameters:
input
- The input object, possibly null- Returns:
- The output byte array
-
isNullable
public boolean isNullable()Description copied from interface:ObjectCodec
Does this codec support encoding of null values?- Specified by:
isNullable
in interfaceObjectCodec<int[]>
- Returns:
- if null values are supported
-
getPrecision
public int getPrecision()Description copied from interface:ObjectCodec
If applicable, the maximum encodable precision. If precision is not applicable (i.e. for non-numeric types) this method should return zero.- Specified by:
getPrecision
in interfaceObjectCodec<int[]>
- Returns:
- the numeric precision supported by this codec
-
getScale
public int getScale()Description copied from interface:ObjectCodec
If applicable, the maximum encodable scale. If scale is not applicable (i.e. for non-numeric types) this method should return zero.- Specified by:
getScale
in interfaceObjectCodec<int[]>
- Returns:
- the numeric scale (digits after the decimal point) supported by this codec
-
decode
@Nullable public int[] decode(@NotNull byte[] input, int offset, int length) Description copied from interface:ObjectDecoder
Decode an object from an array of bytes.- Specified by:
decode
in interfaceObjectDecoder<int[]>
- 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:ObjectDecoder
What width byte array does this ObjectCodec expect to encode and decode?- Specified by:
expectedObjectWidth
in interfaceObjectDecoder<int[]>
- 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.
-