0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TableIdentifier.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; version 3 of the
9  * 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 "TableIdentifier.h"
30 
31 #include <Common/Serialization.h>
32 
33 using namespace Hypertable;
34 using namespace std;
35 
36 const char *TableIdentifier::METADATA_ID = "0/0";
37 const char *TableIdentifier::METADATA_NAME= "sys/METADATA";
39 
40 bool TableIdentifier::operator==(const TableIdentifier &other) const {
41  if (id == 0 || other.id == 0) {
42  if (id != other.id)
43  return false;
44  }
45  if (strcmp(id, other.id) ||
46  generation != other.generation)
47  return false;
48  return true;
49 }
50 
51 bool TableIdentifier::operator!=(const TableIdentifier &other) const {
52  return !(*this == other);
53 }
54 
55 bool TableIdentifier::operator<(const TableIdentifier &other) const {
56  if (id == 0 || other.id == 0) {
57  if (other.id != 0)
58  return true;
59  else if (id != 0)
60  return false;
61  }
62  int cmpval = strcmp(id, other.id);
63 
64  if (cmpval < 0 ||
65  (cmpval == 0 && generation < other.generation))
66  return true;
67  return false;
68 }
69 
71  return 1;
72 }
73 
76 }
77 
94 void TableIdentifier::encode_internal(uint8_t **bufp) const {
96  Serialization::encode_i64(bufp, generation);
97 }
98 
99 void TableIdentifier::decode_internal(uint8_t version, const uint8_t **bufp,
100  size_t *remainp) {
101  id = Serialization::decode_vstr(bufp, remainp);
102  generation = Serialization::decode_i64(bufp, remainp);
103 }
104 
105 void TableIdentifierManaged::decode_internal(uint8_t version, const uint8_t **bufp,
106  size_t *remainp) {
107  TableIdentifier::decode_internal(version, bufp, remainp);
108  *this = *this;
109 }
110 
112 ostream &Hypertable::operator<<(ostream &os, const TableIdentifier &tid) {
113  os <<"{TableIdentifier: id='"<< tid.id
114  <<"' generation="<< tid.generation <<"}";
115  return os;
116 }
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
static const char * METADATA_ID
static const char * METADATA_NAME
Declarations for TableIdentifier and TableIdentifierManaged.
size_t encoded_length_internal() const override
Returns internal serialized length.
STL namespace.
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
size_t encoded_length_vstr(size_t len)
Computes the encoded length of vstr (vint64, data, null)
bool operator!=(const TableIdentifier &other) const
void encode_internal(uint8_t **bufp) const override
Writes serialized representation of object to a buffer.
uint64_t decode_i64(const uint8_t **bufp, size_t *remainp)
Decode a 64-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
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.
void encode_vstr(uint8_t **bufp, const void *buf, size_t len)
Encode a buffer as variable length string (vint64, data, null)
Hypertable definitions
static const int METADATA_ID_LENGTH
bool operator<(const TableIdentifier &other) const
uint8_t encoding_version() const override
Returns encoding version.
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
bool operator==(const TableIdentifier &other) const