Base class for block headers. More...
#include <BlockHeader.h>
Public Member Functions | |
BlockHeader (uint16_t version=LatestVersion, const char *magic=0) | |
Constructor. More... | |
virtual | ~BlockHeader () |
Destructor. More... | |
void | set_magic (const char *magic) |
Sets the "magic" field. More... | |
const char * | get_magic () |
Gets a pointer to the "magic" field. More... | |
bool | check_magic (const char *magic) |
Compares a given character sequence with the magic field. More... | |
void | set_data_length (uint32_t length) |
Sets the uncompressed data length field. More... | |
uint32_t | get_data_length () |
Gets the uncompressed data length field. More... | |
void | set_data_zlength (uint32_t zlength) |
Sets the compressed data length field. More... | |
uint32_t | get_data_zlength () |
Gets the compressed data length field. More... | |
void | set_data_checksum (uint32_t checksum) |
Sets the checksum field. More... | |
uint32_t | get_data_checksum () |
Gets the checksum field. More... | |
void | set_compression_type (uint16_t type) |
Sets the compression type field. More... | |
uint16_t | get_compression_type () |
Gets the compression type field. More... | |
void | set_flags (uint16_t flags) |
Sets the flags field. More... | |
uint16_t | get_flags () |
Gets the flags field. More... | |
void | write_header_checksum (uint8_t *base) |
Computes and writes checksum field. More... | |
virtual size_t | encoded_length () |
Returns length of serizlized block header. More... | |
virtual void | encode (uint8_t **bufp) |
Encodes serialized representation of block header. More... | |
virtual void | decode (const uint8_t **bufp, size_t *remainp) |
Decodes serialized block header. More... | |
bool | equals (const BlockHeader &other) const |
Equality test. More... | |
Static Public Attributes | |
static const uint16_t | LatestVersion = 1 |
Protected Attributes | |
char | m_magic [10] |
"Magic" string used to identify start of block header More... | |
uint16_t | m_flags |
Flags. More... | |
uint32_t | m_data_length |
Uncompressed length of the data stored within the block. More... | |
uint32_t | m_data_zlength |
Compressed length of the data stored within the block. More... | |
uint32_t | m_data_checksum |
Checksum of (possibly compressed) data stored within the block. More... | |
uint16_t | m_compression_type |
Type of data compression used (see BlockCompressionCodec::Type) More... | |
Private Attributes | |
uint16_t | m_version |
Serialization format version number More... | |
Base class for block headers.
The commit log files and cell store files consist of a series of (optionally compressed) blocks of data, each beginning with a header. This class is a base class that holds fields that are common to all derived header classes and provides methods for encoding and decoding these common fields to disk.
Definition at line 48 of file BlockHeader.h.
BlockHeader::BlockHeader | ( | uint16_t | version = LatestVersion , |
const char * | magic = 0 |
||
) |
Constructor.
Initializes m_version to version
, m_magic with the first ten bytes of magic
, and initializes all other members to their default values.
version | Version of block header to initialize |
magic | Pointer to magic character sequence |
Definition at line 50 of file BlockHeader.cc.
|
inlinevirtual |
Destructor.
Definition at line 64 of file BlockHeader.h.
|
inline |
Compares a given character sequence with the magic field.
magic | Pointer to character sequence for which to compare |
magic
, false otherwise Definition at line 86 of file BlockHeader.h.
|
virtual |
Decodes serialized block header.
bufp | Address of pointer to beginning of serialized block header (advanced by call) |
remainp | Address of variable holding remaining valid data pointed to by bufp (decremented by call) |
Reimplemented in Hypertable::BlockHeaderCommitLog, and Hypertable::BlockHeaderCellStore.
Definition at line 104 of file BlockHeader.cc.
|
virtual |
Encodes serialized representation of block header.
The encoding has the following format:
Encoding | Description |
---|---|
char[10] | Magic string |
int16 | Header checksum |
int16 | Flags |
int8 | Header length |
int8 | Compression type |
int32 | Data checksum |
int32 | Uncompressed data length |
int32 | Compressed data length |
bufp | Address of pointer to destination (advanced by call) |
Reimplemented in Hypertable::BlockHeaderCommitLog, and Hypertable::BlockHeaderCellStore.
Definition at line 82 of file BlockHeader.cc.
|
virtual |
Returns length of serizlized block header.
Reimplemented in Hypertable::BlockHeaderCommitLog, and Hypertable::BlockHeaderCellStore.
Definition at line 76 of file BlockHeader.cc.
bool BlockHeader::equals | ( | const BlockHeader & | other | ) | const |
Equality test.
This method compares the members of the object to the members of other
, returning true if they're all equal.
other
, false otherwise. Definition at line 143 of file BlockHeader.cc.
|
inline |
Gets the compression type field.
Definition at line 128 of file BlockHeader.h.
|
inline |
Gets the checksum field.
Definition at line 118 of file BlockHeader.h.
|
inline |
Gets the uncompressed data length field.
Definition at line 96 of file BlockHeader.h.
|
inline |
Gets the compressed data length field.
Definition at line 106 of file BlockHeader.h.
|
inline |
|
inline |
Gets a pointer to the "magic" field.
Definition at line 79 of file BlockHeader.h.
|
inline |
Sets the compression type field.
type | Compression type (see BlockCompressionCodec::Type) |
Definition at line 123 of file BlockHeader.h.
|
inline |
Sets the checksum field.
The checksum field stores the fletcher32 checksum of the compressed data
checksum | Checksum of compressed data |
Definition at line 113 of file BlockHeader.h.
|
inline |
Sets the uncompressed data length field.
length | Uncompressed length of data |
Definition at line 91 of file BlockHeader.h.
|
inline |
Sets the compressed data length field.
zlength | Compressed length of data |
Definition at line 101 of file BlockHeader.h.
|
inline |
Sets the flags field.
flags | Block header flags |
Definition at line 133 of file BlockHeader.h.
|
inline |
Sets the "magic" field.
The "magic" field is meant to contain an easily identifiable string of ten characters and is written as the first field of the block header. If a file containing a sequence of blocks gets corrupt, the magic field can be used to identify the beginning of any non-corrupted blocks for recovery purposes.
magic | Pointer to magic character sequence |
Definition at line 74 of file BlockHeader.h.
void BlockHeader::write_header_checksum | ( | uint8_t * | base | ) |
Computes and writes checksum field.
The checksum field is a two-byte field that is located immediately after the ten-byte magic string in the serialized header format (see encode()). The checksum is computed over all of the fields that follow the checksum field in the serialized format (including derived portions). This method computes the checksum and then writes it into the serialized header at location base+10
. It should be called at the end of the decode() method of derived block header classes in order to compute the checksum after all fields have been written.
base | Pointer to beginning of serialized block header |
Definition at line 62 of file BlockHeader.cc.
|
static |
Definition at line 52 of file BlockHeader.h.
|
protected |
Type of data compression used (see BlockCompressionCodec::Type)
Definition at line 229 of file BlockHeader.h.
|
protected |
Checksum of (possibly compressed) data stored within the block.
Definition at line 226 of file BlockHeader.h.
|
protected |
Uncompressed length of the data stored within the block.
Definition at line 220 of file BlockHeader.h.
|
protected |
Compressed length of the data stored within the block.
Definition at line 223 of file BlockHeader.h.
|
protected |
Flags.
Definition at line 217 of file BlockHeader.h.
|
protected |
"Magic" string used to identify start of block header
Definition at line 214 of file BlockHeader.h.
|
private |
Serialization format version number
Definition at line 233 of file BlockHeader.h.