0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BlockHeaderCellStore.cc
Go to the documentation of this file.
1 /*
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 "BlockHeaderCellStore.h"
31 
32 #include <Common/Error.h>
33 #include <Common/Logger.h>
34 #include <Common/Serialization.h>
35 
36 using namespace Hypertable;
37 using namespace Serialization;
38 
39 namespace {
40  const size_t EncodedLengths[BlockHeaderCellStore::LatestVersion+1] = { 0, 0 };
41  const uint16_t BaseVersions[BlockHeaderCellStore::LatestVersion+1] = { 0, 1 };
42 }
43 
45 
46 BlockHeaderCellStore::BlockHeaderCellStore(uint16_t version, const char *magic) :
47  BlockHeader(BaseVersions[version], magic), m_version(version) {
48  HT_ASSERT(version <= LatestVersion);
49 }
50 
52  return BlockHeader::encoded_length() + EncodedLengths[m_version];
53 }
54 
55 
56 void BlockHeaderCellStore::encode(uint8_t **bufp) {
57  uint8_t *base = *bufp;
58  BlockHeader::encode(bufp);
59  if (m_version == 0)
60  *bufp += 2;
62 }
63 
64 
65 void BlockHeaderCellStore::decode(const uint8_t **bufp, size_t *remainp) {
66 
67  BlockHeader::decode(bufp, remainp);
68 
69  // If version 0, skip old checksum field
70  if (m_version == 0) {
71  *bufp += 2;
72  *remainp -= 2;
73  return;
74  }
75 }
76 
77 
78 
80  if (static_cast<const BlockHeader &>(*this) == other &&
81  m_version == other.m_version)
82  return true;
83  return false;
84 }
uint16_t m_version
Serialization format version number
#define HT_ASSERT(_e_)
Definition: Logger.h:396
bool equals(const BlockHeaderCellStore &other) const
Equality test.
BlockHeaderCellStore(uint16_t version=LatestVersion, const char *magic=0)
Constructor with version and magic string initializers.
virtual size_t encoded_length()
Returns length of serizlized block header.
Logging routines and macros.
Compatibility Macros for C/C++.
virtual void decode(const uint8_t **bufp, size_t *remainp)
Decodes cell store block header from memory location.
Functions to serialize/deserialize primitives to/from a memory buffer.
virtual void decode(const uint8_t **bufp, size_t *remainp)
Decodes serialized block header.
Definition: BlockHeader.cc:104
Hypertable definitions
virtual void encode(uint8_t **bufp)
Encodes cell store block header to memory location.
Declarations for BlockHeaderCellStore.
virtual size_t encoded_length()
Returns length of serizlized block header.
Definition: BlockHeader.cc:76
void write_header_checksum(uint8_t *base)
Computes and writes checksum field.
Definition: BlockHeader.cc:62
Base class for block headers.
Definition: BlockHeader.h:48
Error codes, Exception handling, error logging.
virtual void encode(uint8_t **bufp)
Encodes serialized representation of block header.
Definition: BlockHeader.cc:82