Package io.datarouter.bytes
Class TerminatedByteArrayTool
java.lang.Object
io.datarouter.bytes.TerminatedByteArrayTool
public class TerminatedByteArrayTool extends Object
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 Modifier and Type Class Description static classTerminatedByteArrayTool.NumEscapedAndTerminalIndex -
Field Summary
Fields Modifier and Type Field Description static byteESCAPE_BYTEstatic intESCAPE_SHIFTstatic byteTERMINAL_BYTE -
Constructor Summary
Constructors Constructor Description TerminatedByteArrayTool() -
Method Summary
Modifier and Type Method Description static byte[]escapeAndTerminate(byte[] input)static TerminatedByteArrayTool.NumEscapedAndTerminalIndexfindEscapedCountAndTerminalIndex(byte[] bytes, 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:
- Constant Field Values
-
ESCAPE_BYTE
public static final byte ESCAPE_BYTE- See Also:
- Constant Field Values
-
ESCAPE_SHIFT
public static final int ESCAPE_SHIFT- See Also:
- Constant Field Values
-
-
Constructor Details
-
TerminatedByteArrayTool
public TerminatedByteArrayTool()
-
-
Method Details
-
escapeAndTerminate
public static byte[] escapeAndTerminate(byte[] input) -
findEscapedCountAndTerminalIndex
public static TerminatedByteArrayTool.NumEscapedAndTerminalIndex findEscapedCountAndTerminalIndex(byte[] bytes, int offset) -
unescapeAndUnterminate
public static byte[] unescapeAndUnterminate(byte[] escapedBytes, int offset, int numEscaped, int terminalIndex)
-