0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CellInterval.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 
22 #include <Common/Compat.h>
23 
24 #include "CellInterval.h"
25 
26 #include <cstring>
27 #include <iostream>
28 
29 #include <Common/Logger.h>
30 #include <Common/Serialization.h>
31 
32 using namespace Hypertable;
33 using namespace Hypertable::Lib;
34 using namespace std;
35 
37  return 1;
38 }
39 
41  return 2 + Serialization::encoded_length_vstr(start_row) +
45 }
46 
79 void CellInterval::encode_internal(uint8_t **bufp) const {
80  Serialization::encode_vstr(bufp, start_row);
81  Serialization::encode_vstr(bufp, start_column);
82  Serialization::encode_bool(bufp, start_inclusive);
83  Serialization::encode_vstr(bufp, end_row);
84  Serialization::encode_vstr(bufp, end_column);
85  Serialization::encode_bool(bufp, end_inclusive);
86 }
87 
88 void CellInterval::decode_internal(uint8_t version, const uint8_t **bufp,
89  size_t *remainp) {
90  HT_TRY("decoding cell interval",
91  start_row = Serialization::decode_vstr(bufp, remainp);
92  start_column = Serialization::decode_vstr(bufp, remainp);
93  start_inclusive = Serialization::decode_bool(bufp, remainp);
94  end_row = Serialization::decode_vstr(bufp, remainp);
95  end_column = Serialization::decode_vstr(bufp, remainp);
96  end_inclusive = Serialization::decode_bool(bufp, remainp));
97 }
98 
99 const string CellInterval::render_hql() const {
100  string hql;
101  hql.reserve( (start_row ? strlen(start_row) : 0) +
102  (start_column ? strlen(start_column) : 0) +
103  (end_row ? strlen(end_row) : 0) +
104  (end_column ? strlen(end_column) : 0) + 8);
105  if (start_row && *start_row) {
106  hql.append("\"");
107  hql.append(start_row);
108  hql.append("',\"");
109  if (start_column && *start_column)
110  hql.append(start_column);
111  hql.append("',");
112  if (start_inclusive)
113  hql.append(" <= ");
114  else
115  hql.append(" < ");
116  }
117  hql.append("CELL");
118  if (end_row && *end_row) {
119  if (end_inclusive)
120  hql.append(" <= ");
121  else
122  hql.append(" < ");
123  hql.append("\"");
124  hql.append(end_row);
125  hql.append("',\"");
126  if (end_column && *end_column)
127  hql.append(end_column);
128  hql.append("',");
129  }
130  return hql;
131 }
132 
134 ostream &Hypertable::Lib::operator<<(ostream &os, const CellInterval &ci) {
135  os <<"{CellInterval: ";
136  if (ci.start_row)
137  os << "\"" << ci.start_row << "\",\"" << ci.start_column << "\"";
138  else
139  os << "NULL";
140  if (ci.start_inclusive)
141  os << " <= cell ";
142  else
143  os << " < cell ";
144  if (ci.end_inclusive)
145  os << "<= ";
146  else
147  os << "< ";
148  if (ci.end_row)
149  os << "\"" << ci.end_row << "\",\"" << ci.end_column << "\"";
150  else
151  os << "0xff 0xff";
152  os << "}";
153  return os;
154 }
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: CellInterval.cc:88
STL namespace.
size_t encoded_length_vstr(size_t len)
Computes the encoded length of vstr (vint64, data, null)
bool decode_bool(const uint8_t **bufp, size_t *remainp)
Decodes a boolean value from the given buffer.
Definition: Serialization.h:96
ostream & operator<<(ostream &os, const CellInterval &ci)
Logging routines and macros.
size_t encoded_length_internal() const override
Returns internal serialized length.
Definition: CellInterval.cc:40
const string render_hql() const
Renders cell interval as HQL.
Definition: CellInterval.cc:99
Compatibility Macros for C/C++.
uint8_t encoding_version() const override
Returns encoding version.
Definition: CellInterval.cc:36
Functions to serialize/deserialize primitives to/from a memory buffer.
Hypertable library.
Definition: CellInterval.h:30
void encode_vstr(uint8_t **bufp, const void *buf, size_t len)
Encode a buffer as variable length string (vint64, data, null)
Hypertable definitions
void encode_bool(uint8_t **bufp, bool bval)
Encodes a boolean into the given buffer.
Definition: Serialization.h:84
void encode_internal(uint8_t **bufp) const override
Writes serialized representation of object to a buffer.
Definition: CellInterval.cc:79
Represents a cell interval.
Definition: CellInterval.h:38
#define HT_TRY(_s_, _code_)
Definition: Error.h:517