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.
  • Field Details

  • Constructor Details

    • TerminatedByteArrayTool

      public TerminatedByteArrayTool()
  • Method Details

    • 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)