org.apache.kafka.common.record
Class Record

java.lang.Object
  extended by org.apache.kafka.common.record.Record

public final class Record
extends java.lang.Object

A record: a serialized key and value along with the associated CRC and other fields


Field Summary
static int ATTRIBUTE_LENGTH
           
static int ATTRIBUTES_OFFSET
           
static int COMPRESSION_CODEC_MASK
          Specifies the mask for the compression code.
static int CRC_LENGTH
           
static int CRC_OFFSET
          The current offset and size for all the fixed-length fields
static byte CURRENT_MAGIC_VALUE
          The current "magic" value
static int HEADER_SIZE
          The size for the record header
static int KEY_OFFSET
           
static int KEY_SIZE_LENGTH
           
static int KEY_SIZE_OFFSET
           
static int MAGIC_LENGTH
           
static int MAGIC_OFFSET
           
static int NO_COMPRESSION
          Compression code for uncompressed records
static int RECORD_OVERHEAD
          The amount of overhead bytes in a record
static int VALUE_SIZE_LENGTH
           
 
Constructor Summary
Record(byte[] value)
           
Record(byte[] key, byte[] value)
           
Record(byte[] key, byte[] value, CompressionType type)
           
Record(byte[] key, byte[] value, CompressionType type, int valueOffset, int valueSize)
          A constructor to create a LogRecord.
Record(byte[] value, CompressionType type)
           
Record(java.nio.ByteBuffer buffer)
           
 
Method Summary
 byte attributes()
          The attributes stored with this record
 java.nio.ByteBuffer buffer()
           
 long checksum()
          Retrieve the previously computed CRC for this record
 CompressionType compressionType()
          The compression type used with this record
static byte computeAttributes(CompressionType type)
           
 long computeChecksum()
          Compute the checksum of the record from the record contents
static long computeChecksum(byte[] key, byte[] value, CompressionType type, int valueOffset, int valueSize)
          Compute the checksum of the record from the attributes, key and value payloads
static long computeChecksum(java.nio.ByteBuffer buffer, int position, int size)
          Compute the checksum of the record from the record contents
 void ensureValid()
          Throw an InvalidRecordException if isValid is false for this record
 boolean equals(java.lang.Object other)
           
 int hashCode()
           
 boolean hasKey()
          Does the record have a key?
 boolean isValid()
          Returns true if the crc stored with the record matches the crc computed off the record contents
 java.nio.ByteBuffer key()
          A ByteBuffer containing the message key
 int keySize()
          The length of the key in bytes
 byte magic()
          The magic version of this record
static int recordSize(byte[] key, byte[] value)
           
static int recordSize(int keySize, int valueSize)
           
 int size()
          The complete serialized size of this record in bytes (including crc, header attributes, etc)
 java.lang.String toString()
           
 java.nio.ByteBuffer value()
          A ByteBuffer containing the value of this record
 int valueSize()
          The length of the value in bytes
static void write(java.nio.ByteBuffer buffer, byte[] key, byte[] value, CompressionType type, int valueOffset, int valueSize)
           
static void write(Compressor compressor, long crc, byte attributes, byte[] key, byte[] value, int valueOffset, int valueSize)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CRC_OFFSET

public static final int CRC_OFFSET
The current offset and size for all the fixed-length fields

See Also:
Constant Field Values

CRC_LENGTH

public static final int CRC_LENGTH
See Also:
Constant Field Values

MAGIC_OFFSET

public static final int MAGIC_OFFSET
See Also:
Constant Field Values

MAGIC_LENGTH

public static final int MAGIC_LENGTH
See Also:
Constant Field Values

ATTRIBUTES_OFFSET

public static final int ATTRIBUTES_OFFSET
See Also:
Constant Field Values

ATTRIBUTE_LENGTH

public static final int ATTRIBUTE_LENGTH
See Also:
Constant Field Values

KEY_SIZE_OFFSET

public static final int KEY_SIZE_OFFSET
See Also:
Constant Field Values

KEY_SIZE_LENGTH

public static final int KEY_SIZE_LENGTH
See Also:
Constant Field Values

KEY_OFFSET

public static final int KEY_OFFSET
See Also:
Constant Field Values

VALUE_SIZE_LENGTH

public static final int VALUE_SIZE_LENGTH
See Also:
Constant Field Values

HEADER_SIZE

public static final int HEADER_SIZE
The size for the record header

See Also:
Constant Field Values

RECORD_OVERHEAD

public static final int RECORD_OVERHEAD
The amount of overhead bytes in a record

See Also:
Constant Field Values

CURRENT_MAGIC_VALUE

public static final byte CURRENT_MAGIC_VALUE
The current "magic" value

See Also:
Constant Field Values

COMPRESSION_CODEC_MASK

public static final int COMPRESSION_CODEC_MASK
Specifies the mask for the compression code. 3 bits to hold the compression codec. 0 is reserved to indicate no compression

See Also:
Constant Field Values

NO_COMPRESSION

public static final int NO_COMPRESSION
Compression code for uncompressed records

See Also:
Constant Field Values
Constructor Detail

Record

public Record(java.nio.ByteBuffer buffer)

Record

public Record(byte[] key,
              byte[] value,
              CompressionType type,
              int valueOffset,
              int valueSize)
A constructor to create a LogRecord. If the record's compression type is not none, then its value payload should be already compressed with the specified type; the constructor would always write the value payload as is and will not do the compression itself.

Parameters:
key - The key of the record (null, if none)
value - The record value
type - The compression type used on the contents of the record (if any)
valueOffset - The offset into the payload array used to extract payload
valueSize - The size of the payload to use

Record

public Record(byte[] key,
              byte[] value,
              CompressionType type)

Record

public Record(byte[] value,
              CompressionType type)

Record

public Record(byte[] key,
              byte[] value)

Record

public Record(byte[] value)
Method Detail

write

public static void write(java.nio.ByteBuffer buffer,
                         byte[] key,
                         byte[] value,
                         CompressionType type,
                         int valueOffset,
                         int valueSize)

write

public static void write(Compressor compressor,
                         long crc,
                         byte attributes,
                         byte[] key,
                         byte[] value,
                         int valueOffset,
                         int valueSize)

recordSize

public static int recordSize(byte[] key,
                             byte[] value)

recordSize

public static int recordSize(int keySize,
                             int valueSize)

buffer

public java.nio.ByteBuffer buffer()

computeAttributes

public static byte computeAttributes(CompressionType type)

computeChecksum

public static long computeChecksum(java.nio.ByteBuffer buffer,
                                   int position,
                                   int size)
Compute the checksum of the record from the record contents


computeChecksum

public static long computeChecksum(byte[] key,
                                   byte[] value,
                                   CompressionType type,
                                   int valueOffset,
                                   int valueSize)
Compute the checksum of the record from the attributes, key and value payloads


computeChecksum

public long computeChecksum()
Compute the checksum of the record from the record contents


checksum

public long checksum()
Retrieve the previously computed CRC for this record


isValid

public boolean isValid()
Returns true if the crc stored with the record matches the crc computed off the record contents


ensureValid

public void ensureValid()
Throw an InvalidRecordException if isValid is false for this record


size

public int size()
The complete serialized size of this record in bytes (including crc, header attributes, etc)


keySize

public int keySize()
The length of the key in bytes


hasKey

public boolean hasKey()
Does the record have a key?


valueSize

public int valueSize()
The length of the value in bytes


magic

public byte magic()
The magic version of this record


attributes

public byte attributes()
The attributes stored with this record


compressionType

public CompressionType compressionType()
The compression type used with this record


value

public java.nio.ByteBuffer value()
A ByteBuffer containing the value of this record


key

public java.nio.ByteBuffer key()
A ByteBuffer containing the message key


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object