0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
StatsSerializable.h
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; version 3 of the
9  * License.
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 #ifndef Common_StatsSerializable_h
27 #define Common_StatsSerializable_h
28 
29 extern "C" {
30 #include <stddef.h>
31 #include <stdint.h>
32 }
33 
34 namespace Hypertable {
35 
48  public:
54  StatsSerializable(uint16_t _id, uint8_t _group_count);
55 
58 
61 
63  size_t encoded_length() const;
64 
66  void encode(uint8_t **bufp) const;
67 
69  void decode(const uint8_t **bufp, size_t *remainp);
70 
72  bool operator==(const StatsSerializable &other) const;
73 
75  bool operator!=(const StatsSerializable &other) const {
76  return !(*this == other);
77  }
78 
79  protected:
81  enum Identifier {
82  SYSTEM = 1,
83  RANGE = 2,
84  TABLE = 3,
86  };
87 
93  virtual size_t encoded_length_group(int group) const = 0;
94 
100  virtual void encode_group(int group, uint8_t **bufp) const = 0;
101 
109  virtual void decode_group(int group, uint16_t len, const uint8_t **bufp,
110  size_t *remainp) = 0;
111 
113  uint16_t id;
114 
116  uint8_t group_count;
117 
119  uint8_t group_ids[32];
120 };
121 
124 }
125 
126 #endif // Common_StatsSerializable_h
Abstract base class for managing serialized statistics.
StatsSerializable(uint16_t _id, uint8_t _group_count)
Constructor; creates a new object with an ID and a number of groups.
uint8_t group_count
Number of groups in group_ids.
virtual void decode_group(int group, uint16_t len, const uint8_t **bufp, size_t *remainp)=0
Abstruct function to deserialize a group from a memory buffer.
virtual void encode_group(int group, uint8_t **bufp) const =0
Abstruct function to serialize a group into a memory buffer.
size_t encoded_length() const
Returns the encoded length of this object.
bool operator!=(const StatsSerializable &other) const
Not Equal operator.
void decode(const uint8_t **bufp, size_t *remainp)
Deserializes this object from a buffer.
bool operator==(const StatsSerializable &other) const
Equal operator.
Hypertable definitions
virtual size_t encoded_length_group(int group) const =0
Abstruct function returning the serialized length of a group.
StatsSerializable & operator=(const StatsSerializable &other)
Assignment operator.
uint16_t id
The statistics ID.
Identifier
Statistics identifer; assigned in constructor.
uint8_t group_ids[32]
The actual group IDs.
void encode(uint8_t **bufp) const
Encodes the statistics to a serialized buffer.