0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PhantomLoad.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; either version 3
9  * of the 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 
26 
27 #include <Common/Compat.h>
28 
29 #include "PhantomLoad.h"
30 
31 #include <Common/Logger.h>
32 #include <Common/Serialization.h>
33 
34 using namespace Hypertable;
36 
38  return 1;
39 }
40 
42  size_t length = 8 + Serialization::encoded_length_vstr(m_location) +
43  (m_fragments.size()*4);
44  length += 4;
45  for (auto & spec : m_range_specs)
46  length += spec.encoded_length();
47  length += 4;
48  for (auto & state : m_range_states)
49  length += state.encoded_length();
50  return length;
51 }
52 
69 void PhantomLoad::encode_internal(uint8_t **bufp) const {
73  for (auto fragment : m_fragments)
74  Serialization::encode_i32(bufp, fragment);
76  for (auto & spec : m_range_specs)
77  spec.encode(bufp);
79  for (auto & state : m_range_states)
80  state.encode(bufp);
81 }
82 
83 void PhantomLoad::decode_internal(uint8_t version, const uint8_t **bufp,
84  size_t *remainp) {
85  m_location = Serialization::decode_vstr(bufp, remainp);
87  size_t count = Serialization::decode_i32(bufp, remainp);
88  m_fragments.reserve(count);
89  for (size_t i=0; i<count; ++i)
90  m_fragments.push_back(Serialization::decode_i32(bufp, remainp));
91  count = Serialization::decode_i32(bufp, remainp);
92  m_range_specs.reserve(count);
93  for (size_t i=0; i<count; ++i) {
94  QualifiedRangeSpec spec;
95  spec.decode(bufp, remainp);
96  m_range_specs.push_back(spec);
97  }
98  count = Serialization::decode_i32(bufp, remainp);
99  m_range_states.reserve(count);
100  for (size_t i=0; i<count; ++i) {
101  RangeState state;
102  state.decode(bufp, remainp);
103  m_range_states.push_back(state);
104  }
105 }
106 
107 
108 
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
Definition: PhantomLoad.cc:83
void encode_internal(uint8_t **bufp) const override
Writes serialized representation of object to a buffer.
Definition: PhantomLoad.cc:69
size_t encoded_length_vstr(size_t len)
Computes the encoded length of vstr (vint64, data, null)
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
size_t encoded_length_internal() const override
Returns internal serialized length.
Definition: PhantomLoad.cc:41
Logging routines and macros.
void encode_i32(uint8_t **bufp, uint32_t val)
Encode a 32-bit integer in little-endian order.
Declarations for PhantomLoad request parameters.
vector< QualifiedRangeSpec > m_range_specs
Vector of range specifications.
Definition: PhantomLoad.h:126
vector< RangeState > m_range_states
Vector of range states.
Definition: PhantomLoad.h:129
Compatibility Macros for C/C++.
Functions to serialize/deserialize primitives to/from a memory buffer.
virtual void decode(const uint8_t **bufp, size_t *remainp)
Reads serialized representation of object from a buffer.
Definition: Serializable.cc:70
void encode_vstr(uint8_t **bufp, const void *buf, size_t len)
Encode a buffer as variable length string (vint64, data, null)
Hypertable definitions
Qualified (with table identifier) range specification.
Range state.
Definition: RangeState.h:48
uint8_t encoding_version() const override
Returns encoding version.
Definition: PhantomLoad.cc:37