0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CellStoreTrailerV0.cc
Go to the documentation of this file.
1 
22 #include "Common/Compat.h"
23 #include <cassert>
24 #include <iostream>
25 
26 #include "Common/Serialization.h"
27 #include "Common/Logger.h"
28 
29 #include "Hypertable/Lib/KeySpec.h"
30 
31 #include "CellStoreTrailerV0.h"
32 
33 using namespace std;
34 using namespace Hypertable;
35 using namespace Serialization;
36 
37 
41 CellStoreTrailerV0::CellStoreTrailerV0() {
42  assert(sizeof(float) == 4);
43  clear();
44 }
45 
46 
49 void CellStoreTrailerV0::clear() {
50  fix_index_offset = 0;
51  var_index_offset = 0;
52  filter_offset = 0;
53  index_entries = 0;
54  total_entries = 0;
55  num_filter_items = 0;
56  filter_false_positive_prob = 0.0;
57  blocksize = 0;
58  revision = TIMESTAMP_MIN;
59  table_id = 0xffffffff;
60  table_generation = 0;
61  compression_ratio = 0.0;
62  compression_type = 0;
63  version = 0;
64 }
65 
66 
67 
70 void CellStoreTrailerV0::serialize(uint8_t *buf) {
71  uint8_t *base = buf;
72  encode_i32(&buf, fix_index_offset);
73  encode_i32(&buf, var_index_offset);
74  encode_i32(&buf, filter_offset);
75  encode_i32(&buf, index_entries);
76  encode_i32(&buf, total_entries);
77  encode_i32(&buf, num_filter_items);
78  encode_i32(&buf, filter_false_positive_prob_i32);
79  encode_i32(&buf, blocksize);
80  encode_i64(&buf, revision);
81  encode_i32(&buf, table_id);
82  encode_i32(&buf, table_generation);
83  encode_i32(&buf, compression_ratio_i32);
84  encode_i16(&buf, compression_type);
85  encode_i16(&buf, version);
86  assert((buf-base) == (int)CellStoreTrailerV0::size());
87  (void)base;
88 }
89 
90 
91 
94 void CellStoreTrailerV0::deserialize(const uint8_t *buf) {
95  HT_TRY("deserializing cellstore trailer",
96  size_t remaining = CellStoreTrailerV0::size();
97  fix_index_offset = decode_i32(&buf, &remaining);
98  var_index_offset = decode_i32(&buf, &remaining);
99  filter_offset = decode_i32(&buf, &remaining);
100  index_entries = decode_i32(&buf, &remaining);
101  total_entries = decode_i32(&buf, &remaining);
102  num_filter_items = decode_i32(&buf, &remaining);
103  filter_false_positive_prob_i32 = decode_i32(&buf, &remaining);
104  blocksize = decode_i32(&buf, &remaining);
105  revision = decode_i64(&buf, &remaining);
106  table_id = decode_i32(&buf, &remaining);
107  table_generation = decode_i32(&buf, &remaining);
108  compression_ratio_i32 = decode_i32(&buf, &remaining);
109  compression_type = decode_i16(&buf, &remaining);
110  version = decode_i16(&buf, &remaining));
111 }
112 
113 
114 
117 void CellStoreTrailerV0::display(std::ostream &os) {
118  os << "{CellStoreTrailerV0: ";
119  os << "fix_index_offset=" << fix_index_offset;
120  os << ", var_index_offset=" << var_index_offset;
121  os << ", filter_offset=" << filter_offset;
122  os << ", index_entries=" << index_entries;
123  os << ", total_entries=" << total_entries;
124  os << ", num_filter_items = " << num_filter_items;
125  os << ", filter_false_positive_prob = "
126  << filter_false_positive_prob;
127  os << ", blocksize=" << blocksize;
128  os << ", revision=" << revision;
129  os << ", table_id=" << table_id;
130  os << ", table_generation=" << table_generation;
131  os << ", compression_ratio=" << compression_ratio;
132  os << ", compression_type=" << compression_type;
133  os << ", version=" << version << "}";
134 }
135 
136 
139 void CellStoreTrailerV0::display_multiline(std::ostream &os) {
140  os << "[CellStoreTrailerV0]\n";
141  os << " fix_index_offset: " << fix_index_offset << "\n";
142  os << " var_index_offset: " << var_index_offset << "\n";
143  os << " filter_offset: " << filter_offset << "\n";
144  os << " index_entries: " << index_entries << "\n";
145  os << " total_entries: " << total_entries << "\n";
146  os << " num_filter_items: " << num_filter_items << "\n";
147  os << " filter_false_positive_prob: "
148  << filter_false_positive_prob << "\n";
149  os << " blocksize: " << blocksize << "\n";
150  os << " revision: " << revision << "\n";
151  os << " table_id: " << table_id << "\n";
152  os << " table_generation: " << table_generation << "\n";
153  os << " compression_ratio: " << compression_ratio << "\n";
154  os << " compression_type: " << compression_type << "\n";
155  os << " version: " << version << "\n";
156 }
157 
STL namespace.
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
static const int64_t TIMESTAMP_MIN
Definition: KeySpec.h:34
uint64_t decode_i64(const uint8_t **bufp, size_t *remainp)
Decode a 64-bit integer in little-endian order.
uint16_t decode_i16(const uint8_t **bufp, size_t *remainp)
Decode a 16-bit integer in little-endian order.
Logging routines and macros.
void encode_i32(uint8_t **bufp, uint32_t val)
Encode a 32-bit integer in little-endian order.
Compatibility Macros for C/C++.
void encode_i16(uint8_t **bufp, uint16_t val)
Encode a 16-bit integer in little-endian order.
void encode_i64(uint8_t **bufp, uint64_t val)
Encode a 64-bit integer in little-endian order.
Functions to serialize/deserialize primitives to/from a memory buffer.
Hypertable definitions
#define HT_TRY(_s_, _code_)
Definition: Error.h:517