0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MetaLogEntity.cc
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
28 #include <Common/Compat.h>
29 
30 #include "MetaLogEntity.h"
31 
32 #include <Common/Checksum.h>
33 #include <Common/Error.h>
34 #include <Common/Logger.h>
35 #include <Common/Serialization.h>
36 
37 using namespace Hypertable;
38 using namespace Hypertable::MetaLog;
39 
40 Entity::Entity(int32_t type) : header(type) { }
41 
42 Entity::Entity(const EntityHeader &header_) : header(header_) { }
43 
44 
45 void Entity::encode_entry(uint8_t **bufp) {
47  uint8_t *header_encode_position = *bufp;
48  *bufp += EntityHeader::LENGTH;
49  uint8_t *payload_encode_position = *bufp;
50  encode(bufp);
51  header.checksum = fletcher32(payload_encode_position, *bufp-payload_encode_position);
52  header.encode(&header_encode_position);
53  HT_ASSERT(header_encode_position == payload_encode_position);
54 }
int32_t length
Length of entity header plus serialized state.
void encode(uint8_t **bufp) const
Encodes (serializes) header to a buffer.
virtual size_t encoded_length() const
Returns serialized object length.
Definition: Serializable.cc:37
EntityHeader header
Entity header
#define HT_ASSERT(_e_)
Definition: Logger.h:396
uint32_t fletcher32(const void *data8, size_t len8)
Compute fletcher32 checksum for arbitary data.
Definition: Checksum.cc:42
Static length of entity header.
virtual void encode(uint8_t **bufp) const
Writes serialized representation of object to a buffer.
Definition: Serializable.cc:64
Logging routines and macros.
Declarations for MetaLog::Entity.
Compatibility Macros for C/C++.
Functions to serialize/deserialize primitives to/from a memory buffer.
Hypertable definitions
Implementation of checksum routines.
void encode_entry(uint8_t **bufp)
Encodes entity header plus serialized state.
Entity(int32_t type)
Constructor from entity type.
int32_t checksum
Checksum of serialized entity state
Error codes, Exception handling, error logging.
MetaLog framework.
Definition: MetaLog.h:44