0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CellStoreTrailerV1.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 "CellStoreTrailerV1.h"
32 
33 using namespace std;
34 using namespace Hypertable;
35 using namespace Serialization;
36 
37 
41 CellStoreTrailerV1::CellStoreTrailerV1() {
42  assert(sizeof(float) == 4);
43  clear();
44 }
45 
46 
49 void CellStoreTrailerV1::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  timestamp_min = TIMESTAMP_MAX;
60  timestamp_max = TIMESTAMP_MIN;
61  create_time = 0;
62  table_id = 0xffffffff;
63  table_generation = 0;
64  flags = 0;
65  compression_ratio = 0.0;
66  compression_type = 0;
67  version = 1;
68 }
69 
70 
71 
74 void CellStoreTrailerV1::serialize(uint8_t *buf) {
75  uint8_t *base = buf;
76  encode_i64(&buf, fix_index_offset);
77  encode_i64(&buf, var_index_offset);
78  encode_i64(&buf, filter_offset);
79  encode_i64(&buf, index_entries);
80  encode_i64(&buf, total_entries);
81  encode_i64(&buf, num_filter_items);
82  encode_i32(&buf, filter_false_positive_prob_i32);
83  encode_i64(&buf, blocksize);
84  encode_i64(&buf, revision);
85  encode_i64(&buf, timestamp_min);
86  encode_i64(&buf, timestamp_max);
87  encode_i64(&buf, create_time);
88  encode_i32(&buf, table_id);
89  encode_i32(&buf, table_generation);
90  encode_i32(&buf, flags);
91  encode_i32(&buf, compression_ratio_i32);
92  encode_i16(&buf, compression_type);
93  encode_i16(&buf, version);
94  assert(version == 1);
95  assert((buf-base) == (int)CellStoreTrailerV1::size());
96  (void)base;
97 }
98 
99 
100 
103 void CellStoreTrailerV1::deserialize(const uint8_t *buf) {
104  HT_TRY("deserializing cellstore trailer",
105  size_t remaining = CellStoreTrailerV1::size();
106  fix_index_offset = decode_i64(&buf, &remaining);
107  var_index_offset = decode_i64(&buf, &remaining);
108  filter_offset = decode_i64(&buf, &remaining);
109  index_entries = decode_i64(&buf, &remaining);
110  total_entries = decode_i64(&buf, &remaining);
111  num_filter_items = decode_i64(&buf, &remaining);
112  filter_false_positive_prob_i32 = decode_i32(&buf, &remaining);
113  blocksize = decode_i64(&buf, &remaining);
114  revision = decode_i64(&buf, &remaining);
115  timestamp_min = decode_i64(&buf, &remaining);
116  timestamp_max = decode_i64(&buf, &remaining);
117  create_time = decode_i64(&buf, &remaining);
118  table_id = decode_i32(&buf, &remaining);
119  table_generation = decode_i32(&buf, &remaining);
120  flags = decode_i32(&buf, &remaining);
121  compression_ratio_i32 = decode_i32(&buf, &remaining);
122  compression_type = decode_i16(&buf, &remaining);
123  version = decode_i16(&buf, &remaining));
124 }
125 
126 
127 
130 void CellStoreTrailerV1::display(std::ostream &os) {
131  os << "{CellStoreTrailerV1: ";
132  os << "fix_index_offset=" << fix_index_offset;
133  os << ", var_index_offset=" << var_index_offset;
134  os << ", filter_offset=" << filter_offset;
135  os << ", index_entries=" << index_entries;
136  os << ", total_entries=" << total_entries;
137  os << ", num_filter_items = " << num_filter_items;
138  os << ", filter_false_positive_prob = "
139  << filter_false_positive_prob;
140  os << ", blocksize=" << blocksize;
141  os << ", revision=" << revision;
142  os << ", timestamp_min=" << timestamp_min;
143  os << ", timestamp_max=" << timestamp_max;
144  os << ", create_time=" << create_time;
145  os << ", table_id=" << table_id;
146  os << ", table_generation=" << table_generation;
147  if (flags & INDEX_64BIT)
148  os << ", flags=64BIT_INDEX";
149  else
150  os << ", flags=" << flags;
151  os << ", compression_ratio=" << compression_ratio;
152  os << ", compression_type=" << compression_type;
153  os << ", version=" << version << "}";
154 }
155 
158 void CellStoreTrailerV1::display_multiline(std::ostream &os) {
159  os << "[CellStoreTrailerV1]\n";
160  os << " fix_index_offset: " << fix_index_offset << "\n";
161  os << " var_index_offset: " << var_index_offset << "\n";
162  os << " filter_offset: " << filter_offset << "\n";
163  os << " index_entries: " << index_entries << "\n";
164  os << " total_entries: " << total_entries << "\n";
165  os << " num_filter_items: " << num_filter_items << "\n";
166  os << " filter_false_positive_prob: "
167  << filter_false_positive_prob << "\n";
168  os << " blocksize: " << blocksize << "\n";
169  os << " revision: " << revision << "\n";
170  os << " timestamp_min: " << timestamp_min << "\n";
171  os << " timestamp_max: " << timestamp_max << "\n";
172  os << " create_time: " << create_time << "\n";
173  os << " table_id: " << table_id << "\n";
174  os << " table_generation: " << table_generation << "\n";
175  if (flags & INDEX_64BIT)
176  os << " flags: 64BIT_INDEX\n";
177  else
178  os << " flags=" << flags << "\n";
179  os << " compression_ratio: " << compression_ratio << "\n";
180  os << " compression_type: " << compression_type << "\n";
181  os << " version: " << version << std::endl;
182 }
183 
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
static const int64_t TIMESTAMP_MAX
Definition: KeySpec.h:35
#define HT_TRY(_s_, _code_)
Definition: Error.h:517