0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BalancePlan.cc
Go to the documentation of this file.
1 
22 #include <Common/Compat.h>
23 
24 #include "BalancePlan.h"
25 
26 #include <Common/Serialization.h>
27 
28 #include <iostream>
29 
30 using namespace std;
31 using namespace Hypertable;
32 
33 BalancePlan::BalancePlan(const BalancePlan &other) {
34  algorithm = other.algorithm;
35  duration_millis = other.duration_millis;
36  for (auto & move : other.moves)
37  moves.push_back( make_shared<RangeMoveSpec>(*move) );
38 }
39 
40 uint8_t BalancePlan::encoding_version() const {
41  return 1;
42 }
43 
44 size_t BalancePlan::encoded_length_internal() const {
45  size_t length = 8;
46  length += Serialization::encoded_length_vstr(algorithm);
47  for (auto &move : moves)
48  length += move->encoded_length();
49  return length;
50 }
51 
79 void BalancePlan::encode_internal(uint8_t **bufp) const {
80  Serialization::encode_vstr(bufp, algorithm);
81  Serialization::encode_i32(bufp, duration_millis);
82  Serialization::encode_i32(bufp, moves.size());
83  for (auto &move : moves)
84  move->encode(bufp);
85 }
86 
87 void BalancePlan::decode_internal(uint8_t version, const uint8_t **bufp,
88  size_t *remainp) {
89  RangeMoveSpecPtr move_spec;
90  algorithm = Serialization::decode_vstr(bufp, remainp);
91  duration_millis = Serialization::decode_i32(bufp, remainp);
92  size_t count = Serialization::decode_i32(bufp, remainp);
93  moves.reserve(count);
94  for (size_t i=0; i<count; i++) {
95  move_spec = make_shared<RangeMoveSpec>();
96  move_spec->decode(bufp, remainp);
97  moves.push_back(move_spec);
98  }
99 }
100 
103 ostream &Hypertable::operator<<(ostream &os, const BalancePlan &plan) {
104  os << "{BalancePlan:";
105  for (size_t i=0; i<plan.moves.size(); i++)
106  os << " " << (*plan.moves[i]);
107  os << " algorithm =" << plan.algorithm;
108  os << " duration_millis=" << plan.duration_millis << "}";
109  return os;
110 }
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
Balance plan.
Definition: BalancePlan.h:38
STL namespace.
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.
void encode_i32(uint8_t **bufp, uint32_t val)
Encode a 32-bit integer in little-endian order.
Compatibility Macros for C/C++.
std::ostream & operator<<(std::ostream &os, const crontab_entry &entry)
Helper function to write crontab_entry to an ostream.
Definition: Crontab.cc:301
Functions to serialize/deserialize primitives to/from a memory buffer.
void encode_vstr(uint8_t **bufp, const void *buf, size_t len)
Encode a buffer as variable length string (vint64, data, null)
Hypertable definitions
std::vector< RangeMoveSpecPtr > moves
Definition: BalancePlan.h:51
std::shared_ptr< RangeMoveSpec > RangeMoveSpecPtr