Package io.datarouter.bytes
Class TerminatedByteArrayTool
java.lang.Object
io.datarouter.bytes.TerminatedByteArrayTool
Terminated arrays can be embedded in a bigger array knowing that 0 is the terminal character. We escape away the 0
bytes inside the array.
Two escaped arrays will compare equivalently to two unescaped arrays.
To escape:
- replace 0 with 1,2.
- replace 1 with 1,3.
- append 0 at the end.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final bytestatic final intstatic final byte -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]escapeAndTerminate(byte[] input) static intescapedAndTerminatedLength(byte[] input) findEscapedCountAndTerminalIndex(byte[] bytes, int offset) static intfindTerminalIndex(byte[] bytes, int offset) static intlengthWithTerminator(byte[] bytes, int offset) static byte[]unescapeAndUnterminate(byte[] escapedBytes, int offset) static byte[]unescapeAndUnterminate(byte[] escapedBytes, int offset, int numEscaped, int terminalIndex)
-
Field Details
-
TERMINAL_BYTE
public static final byte TERMINAL_BYTE- See Also:
-
ESCAPE_BYTE
public static final byte ESCAPE_BYTE- See Also:
-
ESCAPE_SHIFT
public static final int ESCAPE_SHIFT- See Also:
-
-
Constructor Details
-
TerminatedByteArrayTool
public TerminatedByteArrayTool()
-
-
Method Details
-
escapedAndTerminatedLength
public static int escapedAndTerminatedLength(byte[] input) -
escapeAndTerminate
public static byte[] escapeAndTerminate(byte[] input) -
lengthWithTerminator
public static int lengthWithTerminator(byte[] bytes, int offset) -
findTerminalIndex
public static int findTerminalIndex(byte[] bytes, int offset) -
findEscapedCountAndTerminalIndex
public static TerminatedByteArrayTool.NumEscapedAndTerminalIndex findEscapedCountAndTerminalIndex(byte[] bytes, int offset) -
unescapeAndUnterminate
public static byte[] unescapeAndUnterminate(byte[] escapedBytes, int offset, int numEscaped, int terminalIndex) -
unescapeAndUnterminate
public static byte[] unescapeAndUnterminate(byte[] escapedBytes, int offset)
-