Entity header. More...
#include <MetaLogEntityHeader.h>
Public Types | |
enum | { FLAG_REMOVE = 0x00000001, LENGTH = 32 } |
Enumeration for entity header constants. More... | |
Public Member Functions | |
EntityHeader () | |
Constructor. More... | |
EntityHeader (int32_t type_) | |
Constructor with entity type. More... | |
EntityHeader (const EntityHeader &other) | |
Copy constructor. More... | |
bool | operator< (const EntityHeader &other) const |
Less than operator for comparing this header with another. More... | |
void | encode (uint8_t **bufp) const |
Encodes (serializes) header to a buffer. More... | |
void | decode (const uint8_t **bufp, size_t *remainp) |
Decodes serialzed header from buffer. More... | |
void | display (std::ostream &os) |
Display human-readable representation of header to an ostream. More... | |
Public Attributes | |
int32_t | type {} |
Entity type defined within the context of a Definition More... | |
int32_t | checksum {} |
Checksum of serialized entity state More... | |
int64_t | id {} |
Unique ID of entity. More... | |
int64_t | timestamp {} |
Creation timestmp of entity header. More... | |
int32_t | flags {} |
Flags (either FLAG_REMOVE or 0) More... | |
int32_t | length {} |
Length of entity header plus serialized state. More... | |
Static Public Attributes | |
static bool | display_timestamp = true |
Controls whether or not timestamp is printed by display() More... | |
Static Private Attributes | |
static int64_t | ms_next_id = 1 |
Global counter for generating unique entity IDs More... | |
static std::mutex | ms_mutex |
Mutex for serializing access to ms_next_id More... | |
Entity header.
This class is used to encode and decode the serialized entity header which preceeds the serialized entity state in a MetaLog file. The id member of the header uniquely identifies an entity. Each time an entity changes state, the new state can be serialized to the MetaLog by appending it (header plus new serialized state) to the log. When the log is read, there may multiple serialized versions for the same entity (i.e. entities with the same header id
field. The last serialized version of an entity is taken to be the most up-to-date version of the entity.
Definition at line 54 of file MetaLogEntityHeader.h.
EntityHeader::EntityHeader | ( | ) |
Constructor.
Constructs an empty object initializing all members to 0.
Definition at line 47 of file MetaLogEntityHeader.cc.
EntityHeader::EntityHeader | ( | int32_t | type_ | ) |
Constructor with entity type.
Constructs a new header initializing type to type_
, id to ms_next_id (post-incrementing), timestamp to the current time returned by get_ts64(), and all other members to 0.
type_ | Numeric entity type |
Definition at line 49 of file MetaLogEntityHeader.cc.
EntityHeader::EntityHeader | ( | const EntityHeader & | other | ) |
Copy constructor.
Constructs a header by initializing all members to the corresponding members of other
. If other.id
is greater than or equal to ms_next_id, ms_next_id is set to other.id+1
.
other | Other entity header from which to copy |
Definition at line 57 of file MetaLogEntityHeader.cc.
void EntityHeader::decode | ( | const uint8_t ** | bufp, |
size_t * | remainp | ||
) |
Decodes serialzed header from buffer.
See encode() for serialization format.
bufp | Address of destination buffer pointer (advanced by call) |
remainp | Address of integer holding amount of remaining buffer, decremented by call. |
Definition at line 91 of file MetaLogEntityHeader.cc.
void EntityHeader::display | ( | std::ostream & | os | ) |
Display human-readable representation of header to an ostream.
Prints a comma-separated list of the header members to os
. If the static member display_timestamp is set to true, the timestamp is included, otherwise it is not. Tests that rely on repeatable output of entity headers for the purposes of comparison with diff can set display_timestamp to false.
os | ostream on which to print header |
Definition at line 101 of file MetaLogEntityHeader.cc.
void EntityHeader::encode | ( | uint8_t ** | bufp | ) | const |
Encodes (serializes) header to a buffer.
Encoded as follows:
Encoding | Member |
---|---|
i32 | type |
i32 | checksum |
i32 | length |
i32 | flags |
i64 | id |
i64 | timestamp |
bufp | Address of destination buffer pointer (advanced by call) |
Definition at line 82 of file MetaLogEntityHeader.cc.
bool EntityHeader::operator< | ( | const EntityHeader & | other | ) | const |
Less than operator for comparing this header with another.
Returns true if the id members are not equal but timestamp is less than other.timestamp
, or if the timestamps are equal and id is less than other.id
.
other | Other entity for which comparison is made |
other
, false otherwise. Definition at line 71 of file MetaLogEntityHeader.cc.
int32_t Hypertable::MetaLog::EntityHeader::checksum {} |
Checksum of serialized entity state
Definition at line 134 of file MetaLogEntityHeader.h.
|
static |
Controls whether or not timestamp is printed by display()
Definition at line 149 of file MetaLogEntityHeader.h.
int32_t Hypertable::MetaLog::EntityHeader::flags {} |
Flags (either FLAG_REMOVE or 0)
Definition at line 143 of file MetaLogEntityHeader.h.
int64_t Hypertable::MetaLog::EntityHeader::id {} |
Unique ID of entity.
Definition at line 137 of file MetaLogEntityHeader.h.
int32_t Hypertable::MetaLog::EntityHeader::length {} |
Length of entity header plus serialized state.
Definition at line 146 of file MetaLogEntityHeader.h.
|
staticprivate |
Mutex for serializing access to ms_next_id
Definition at line 157 of file MetaLogEntityHeader.h.
|
staticprivate |
Global counter for generating unique entity IDs
Definition at line 154 of file MetaLogEntityHeader.h.
int64_t Hypertable::MetaLog::EntityHeader::timestamp {} |
Creation timestmp of entity header.
Definition at line 140 of file MetaLogEntityHeader.h.
int32_t Hypertable::MetaLog::EntityHeader::type {} |
Entity type defined within the context of a Definition
Definition at line 131 of file MetaLogEntityHeader.h.