0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Static Public Attributes | Protected Attributes | Private Attributes | List of all members
Hypertable::BlockHeader Class Reference

Base class for block headers. More...

#include <BlockHeader.h>

Inheritance diagram for Hypertable::BlockHeader:
Inheritance graph
[legend]

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

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.

Parameters
versionVersion of block header to initialize
magicPointer to magic character sequence

Definition at line 50 of file BlockHeader.cc.

virtual Hypertable::BlockHeader::~BlockHeader ( )
inlinevirtual

Destructor.

Definition at line 64 of file BlockHeader.h.

Member Function Documentation

bool Hypertable::BlockHeader::check_magic ( const char *  magic)
inline

Compares a given character sequence with the magic field.

Parameters
magicPointer to character sequence for which to compare
Returns
true if m_magic field matches the first ten bytes of magic, false otherwise

Definition at line 86 of file BlockHeader.h.

void BlockHeader::decode ( const uint8_t **  bufp,
size_t *  remainp 
)
virtual

Decodes serialized block header.

See also
encode() for layout
Parameters
bufpAddress of pointer to beginning of serialized block header (advanced by call)
remainpAddress 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.

void BlockHeader::encode ( uint8_t **  bufp)
virtual

Encodes serialized representation of block header.

The encoding has the following format:

EncodingDescription
char[10]Magic string
int16Header checksum
int16Flags
int8Header length
int8Compression type
int32Data checksum
int32Uncompressed data length
int32Compressed data length
Parameters
bufpAddress of pointer to destination (advanced by call)

Reimplemented in Hypertable::BlockHeaderCommitLog, and Hypertable::BlockHeaderCellStore.

Definition at line 82 of file BlockHeader.cc.

size_t BlockHeader::encoded_length ( )
virtual

Returns length of serizlized block header.

See also
encode() for layout
Returns
Length of serialized 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.

Returns
true if object is logically equal to other, false otherwise.

Definition at line 143 of file BlockHeader.cc.

uint16_t Hypertable::BlockHeader::get_compression_type ( )
inline

Gets the compression type field.

Returns
Compression type (see BlockCompressionCodec::Type)

Definition at line 128 of file BlockHeader.h.

uint32_t Hypertable::BlockHeader::get_data_checksum ( )
inline

Gets the checksum field.

Returns
Checksum of compressed data

Definition at line 118 of file BlockHeader.h.

uint32_t Hypertable::BlockHeader::get_data_length ( )
inline

Gets the uncompressed data length field.

Returns
Uncompressed length of data

Definition at line 96 of file BlockHeader.h.

uint32_t Hypertable::BlockHeader::get_data_zlength ( )
inline

Gets the compressed data length field.

Returns
Compressed length of data

Definition at line 106 of file BlockHeader.h.

uint16_t Hypertable::BlockHeader::get_flags ( )
inline

Gets the flags field.

Returns
Block header flags

Definition at line 138 of file BlockHeader.h.

const char* Hypertable::BlockHeader::get_magic ( )
inline

Gets a pointer to the "magic" field.

Returns
Pointer to m_magic

Definition at line 79 of file BlockHeader.h.

void Hypertable::BlockHeader::set_compression_type ( uint16_t  type)
inline

Sets the compression type field.

Parameters
typeCompression type (see BlockCompressionCodec::Type)

Definition at line 123 of file BlockHeader.h.

void Hypertable::BlockHeader::set_data_checksum ( uint32_t  checksum)
inline

Sets the checksum field.

The checksum field stores the fletcher32 checksum of the compressed data

Parameters
checksumChecksum of compressed data

Definition at line 113 of file BlockHeader.h.

void Hypertable::BlockHeader::set_data_length ( uint32_t  length)
inline

Sets the uncompressed data length field.

Parameters
lengthUncompressed length of data

Definition at line 91 of file BlockHeader.h.

void Hypertable::BlockHeader::set_data_zlength ( uint32_t  zlength)
inline

Sets the compressed data length field.

Parameters
zlengthCompressed length of data

Definition at line 101 of file BlockHeader.h.

void Hypertable::BlockHeader::set_flags ( uint16_t  flags)
inline

Sets the flags field.

Parameters
flagsBlock header flags

Definition at line 133 of file BlockHeader.h.

void Hypertable::BlockHeader::set_magic ( const char *  magic)
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.

Parameters
magicPointer 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.

Parameters
basePointer to beginning of serialized block header

Definition at line 62 of file BlockHeader.cc.

Member Data Documentation

const uint16_t BlockHeader::LatestVersion = 1
static

Definition at line 52 of file BlockHeader.h.

uint16_t Hypertable::BlockHeader::m_compression_type
protected

Type of data compression used (see BlockCompressionCodec::Type)

Definition at line 229 of file BlockHeader.h.

uint32_t Hypertable::BlockHeader::m_data_checksum
protected

Checksum of (possibly compressed) data stored within the block.

Definition at line 226 of file BlockHeader.h.

uint32_t Hypertable::BlockHeader::m_data_length
protected

Uncompressed length of the data stored within the block.

Definition at line 220 of file BlockHeader.h.

uint32_t Hypertable::BlockHeader::m_data_zlength
protected

Compressed length of the data stored within the block.

Definition at line 223 of file BlockHeader.h.

uint16_t Hypertable::BlockHeader::m_flags
protected

Flags.

Definition at line 217 of file BlockHeader.h.

char Hypertable::BlockHeader::m_magic[10]
protected

"Magic" string used to identify start of block header

Definition at line 214 of file BlockHeader.h.

uint16_t Hypertable::BlockHeader::m_version
private

Serialization format version number

Definition at line 233 of file BlockHeader.h.


The documentation for this class was generated from the following files: