Class StreamFrameV5

java.lang.Object
ch.qos.logback.classic.kryo.StreamFrameV5

public final class StreamFrameV5 extends Object
V5 record framing. EVENT/CLOSE prefixes are 1 type/crc byte plus an unsigned Kryo varint length (typically 2 bytes total). Epoch STWD headers stay 6 bytes.
  byte0:  type (5) | crc3 (3)
  then:   unsigned varint length
  then:   payload[length]
CRC-3 covers type (5 bits), the length varint bytes, and a small payload window: all bytes if length <= 8, otherwise first and last CRC_WINDOW bytes. The middle is not covered; the check is for torn writes (process exit / power fail) where a later session is appended after a truncated EVENT.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
    Bytes hashed at each end of a payload longer than 2 * CRC_WINDOW.
    static final int
    1 type/crc byte + at most 3 varint bytes (covers KryoEncoder.MAX_BUFFER_SIZE).
    static final int
     
    static final int
     
    static final int
     
    static final int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
     
    static int
    computeCrc(int type, byte[] lenBytes, byte[] payload, int off, int len)
     
    static int
    computeCrc(int type, byte[] lenBuf, int lenOff, int lenLen, byte[] payload, int off, int len)
     
    static int
    countOccurrences(byte[] haystack, byte[] needle)
     
    static boolean
    crcMatches(int packedByte, byte[] lenBytes, byte[] payload, int off, int len)
     
    static int
    crcOf(int packedByte)
     
    static byte[]
     
    static int
    indexOfMagic(byte[] buf, int from, int to)
     
    static boolean
    isStreamHeader(byte[] rec)
     
    static int
    pack(int type, int crc3)
     
    static int
    typeOf(int packedByte)
     
    static int
    unsignedVarIntSize(int value)
     
    static byte[]
    wrapEvent(byte[] payload)
     
    static int
    writeEventPrefix(byte[] dest, int payloadOff, int payloadLen)
    Writes the EVENT prefix immediately before dest[payloadOff].
    static int
    writeUnsignedVarInt(byte[] dest, int off, int value)
    Kryo unsigned varint into dest[off..].

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • isStreamHeader

      public static boolean isStreamHeader(byte[] rec)
    • indexOfMagic

      public static int indexOfMagic(byte[] buf, int from, int to)
    • countOccurrences

      public static int countOccurrences(byte[] haystack, byte[] needle)
    • pack

      public static int pack(int type, int crc3)
    • typeOf

      public static int typeOf(int packedByte)
    • crcOf

      public static int crcOf(int packedByte)
    • unsignedVarIntSize

      public static int unsignedVarIntSize(int value)
    • writeUnsignedVarInt

      public static int writeUnsignedVarInt(byte[] dest, int off, int value)
      Kryo unsigned varint into dest[off..]. Returns bytes written.
    • encodeUnsignedVarInt

      public static byte[] encodeUnsignedVarInt(int value)
    • writeEventPrefix

      public static int writeEventPrefix(byte[] dest, int payloadOff, int payloadLen)
      Writes the EVENT prefix immediately before dest[payloadOff]. Payload bytes must already occupy dest[payloadOff .. payloadOff + payloadLen).
      Returns:
      prefix length in bytes (2–4)
    • wrapEvent

      public static byte[] wrapEvent(byte[] payload)
    • closeCode

      public static byte[] closeCode()
    • computeCrc

      public static int computeCrc(int type, byte[] lenBytes, byte[] payload, int off, int len)
    • computeCrc

      public static int computeCrc(int type, byte[] lenBuf, int lenOff, int lenLen, byte[] payload, int off, int len)
    • crcMatches

      public static boolean crcMatches(int packedByte, byte[] lenBytes, byte[] payload, int off, int len)