Class ByteSource.AbstractEscaper

  • All Implemented Interfaces:
    ByteSource
    Direct Known Subclasses:
    ByteSource.AccessorEscaper, ByteSource.ArrayEscaper, ByteSource.BufferEscaper, ByteSource.MemoryEscaper
    Enclosing interface:
    ByteSource

    public abstract static class ByteSource.AbstractEscaper
    extends java.lang.Object
    implements ByteSource
    Variable-length encoding. Escapes 0s as ESCAPE + zero or more ESCAPED_0_CONT + ESCAPED_0_DONE. If the source ends in 0, we use ESCAPED_0_CONT to make sure that the encoding remains smaller than that source with a further 0 at the end. Finishes in an escaped state (either with ESCAPE or ESCAPED_0_CONT), which in ByteSource.Multi is followed by a component separator between 0x10 and 0xFE. E.g. "A\0\0B" translates to 4100FEFF4200 "A\0B\0" 4100FF4200FE (+00 for ByteComparable.Version.LEGACY) "A\0" 4100FE (+00 for ByteComparable.Version.LEGACY) "AB" 414200 If in a single byte source, the bytes could be simply passed unchanged, but this would not allow us to combine components. This translation preserves order, and since the encoding for 0 is higher than the separator also makes sure shorter components are treated as smaller. The encoding is not prefix-free, since e.g. the encoding of "A" (4100) is a prefix of the encoding of "A\0" (4100FE), but the byte following the prefix is guaranteed to be FE or FF, which makes the encoding weakly prefix-free. Additionally, any such prefix sequence will compare smaller than the value to which it is a prefix, because any permitted separator byte will be smaller than the byte following the prefix.
    • Method Detail

      • next

        public final int next()
        Description copied from interface: ByteSource
        Consume the next byte, unsigned. Must be between 0 and 255, or END_OF_STREAM if there are no more bytes.
        Specified by:
        next in interface ByteSource
      • get

        protected abstract byte get​(int index)
      • limit

        protected abstract int limit()