0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BlockHeader.h
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 #ifndef HYPERTABLE_BLOCKHEADER_H
29 #define HYPERTABLE_BLOCKHEADER_H
30 
31 #include <utility>
32 
33 namespace Hypertable {
34 
35  using namespace std::rel_ops;
36 
48  class BlockHeader {
49 
50  public:
51 
52  static const uint16_t LatestVersion = 1;
53 
61  BlockHeader(uint16_t version=LatestVersion, const char *magic=0);
62 
64  virtual ~BlockHeader() { }
65 
74  void set_magic(const char *magic) { memcpy(m_magic, magic, 10); }
75 
79  const char *get_magic() { return (const char *)m_magic; }
80 
86  bool check_magic(const char *magic) { return !memcmp(magic, m_magic, 10); }
87 
91  void set_data_length(uint32_t length) { m_data_length = length; }
92 
96  uint32_t get_data_length() { return m_data_length; }
97 
101  void set_data_zlength(uint32_t zlength) { m_data_zlength = zlength; }
102 
106  uint32_t get_data_zlength() { return m_data_zlength; }
107 
112  void
113  set_data_checksum(uint32_t checksum) { m_data_checksum = checksum; }
114 
118  uint32_t get_data_checksum() { return m_data_checksum; }
119 
123  void set_compression_type(uint16_t type) { m_compression_type = type; }
124 
128  uint16_t get_compression_type() { return m_compression_type; }
129 
133  void set_flags(uint16_t flags) { m_flags = flags; }
134 
138  uint16_t get_flags() { return m_flags; }
139 
151  void write_header_checksum(uint8_t *base);
152 
157  virtual size_t encoded_length();
158 
192  virtual void encode(uint8_t **bufp);
193 
201  virtual void decode(const uint8_t **bufp, size_t *remainp);
202 
209  bool equals(const BlockHeader &other) const;
210 
211  protected:
212 
214  char m_magic[10];
215 
217  uint16_t m_flags;
218 
220  uint32_t m_data_length;
221 
223  uint32_t m_data_zlength;
224 
226  uint32_t m_data_checksum;
227 
230 
231  private:
233  uint16_t m_version;
234  };
235 
242  inline bool operator==(const BlockHeader &lhs, const BlockHeader &rhs) {
243  return lhs.equals(rhs);
244  }
245 
247 }
248 
249 #endif // HYPERTABLE_BLOCKHEADER_H
250 
void set_data_length(uint32_t length)
Sets the uncompressed data length field.
Definition: BlockHeader.h:91
void set_data_checksum(uint32_t checksum)
Sets the checksum field.
Definition: BlockHeader.h:113
uint32_t m_data_checksum
Checksum of (possibly compressed) data stored within the block.
Definition: BlockHeader.h:226
bool check_magic(const char *magic)
Compares a given character sequence with the magic field.
Definition: BlockHeader.h:86
uint16_t get_compression_type()
Gets the compression type field.
Definition: BlockHeader.h:128
virtual ~BlockHeader()
Destructor.
Definition: BlockHeader.h:64
void set_data_zlength(uint32_t zlength)
Sets the compressed data length field.
Definition: BlockHeader.h:101
uint16_t m_compression_type
Type of data compression used (see BlockCompressionCodec::Type)
Definition: BlockHeader.h:229
uint32_t m_data_zlength
Compressed length of the data stored within the block.
Definition: BlockHeader.h:223
uint16_t get_flags()
Gets the flags field.
Definition: BlockHeader.h:138
uint32_t get_data_checksum()
Gets the checksum field.
Definition: BlockHeader.h:118
bool equals(const BlockHeader &other) const
Equality test.
Definition: BlockHeader.cc:143
void set_flags(uint16_t flags)
Sets the flags field.
Definition: BlockHeader.h:133
uint32_t get_data_length()
Gets the uncompressed data length field.
Definition: BlockHeader.h:96
uint16_t m_version
Serialization format version number
Definition: BlockHeader.h:233
bool operator==(const directory_entry< _Key, _Tp > &lhs, const directory_entry< _Key, _Tp > &rhs)
Definition: directory.h:112
Hypertable definitions
void set_compression_type(uint16_t type)
Sets the compression type field.
Definition: BlockHeader.h:123
void set_magic(const char *magic)
Sets the "magic" field.
Definition: BlockHeader.h:74
uint16_t m_flags
Flags.
Definition: BlockHeader.h:217
uint32_t get_data_zlength()
Gets the compressed data length field.
Definition: BlockHeader.h:106
const char * get_magic()
Gets a pointer to the "magic" field.
Definition: BlockHeader.h:79
Base class for block headers.
Definition: BlockHeader.h:48
uint32_t m_data_length
Uncompressed length of the data stored within the block.
Definition: BlockHeader.h:220