0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RowInterval.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 "RowInterval.h"
25 
26 #include <Common/Logger.h>
27 #include <Common/Serialization.h>
28 
29 #include <cstring>
30 #include <iostream>
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) +
43 }
44 
69 void RowInterval::encode_internal(uint8_t **bufp) const {
70  Serialization::encode_vstr(bufp, start);
71  Serialization::encode_bool(bufp, start_inclusive);
72  Serialization::encode_vstr(bufp, end);
73  Serialization::encode_bool(bufp, end_inclusive);
74 }
75 
76 void RowInterval::decode_internal(uint8_t version, const uint8_t **bufp,
77  size_t *remainp) {
78  HT_TRY("decoding row interval",
79  start = Serialization::decode_vstr(bufp, remainp);
80  start_inclusive = Serialization::decode_bool(bufp, remainp);
81  end = Serialization::decode_vstr(bufp, remainp);
82  end_inclusive = Serialization::decode_bool(bufp, remainp));
83 }
84 
85 const string RowInterval::render_hql() const {
86  string hql;
87  hql.reserve( (start ? strlen(start) : 0) + (end ? strlen(end) : 0) + 8);
88  if (start && *start) {
89  hql.append("\"");
90  hql.append(start);
91  hql.append("\"");
92  if (start_inclusive)
93  hql.append(" <= ");
94  else
95  hql.append(" < ");
96  }
97  hql.append("ROW");
98  if (end && *end) {
99  if (end_inclusive)
100  hql.append(" <= ");
101  else
102  hql.append(" < ");
103  hql.append("\"");
104  hql.append(end);
105  hql.append("\"");
106  }
107  return hql;
108 }
109 
111 ostream &Hypertable::Lib::operator<<(ostream &os, const RowInterval &ri) {
112  os <<"{RowInterval: ";
113  if (ri.start)
114  os << "\"" << ri.start << "\"";
115  else
116  os << "NULL";
117  if (ri.start_inclusive)
118  os << " <= row ";
119  else
120  os << " < row ";
121  if (ri.end_inclusive)
122  os << "<= ";
123  else
124  os << "< ";
125  if (ri.end)
126  os << "\"" << ri.end << "\"";
127  else
128  os << "0xff 0xff";
129  os << "}";
130  return os;
131 }
uint8_t encoding_version() const override
Returns encoding version.
Definition: RowInterval.cc:36
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
const string render_hql() const
Renders row interval as HQL.
Definition: RowInterval.cc:85
size_t encoded_length_internal() const override
Returns internal serialized length.
Definition: RowInterval.cc:40
STL namespace.
size_t encoded_length_vstr(size_t len)
Computes the encoded length of vstr (vint64, data, null)
Represents a row interval.
Definition: RowInterval.h:38
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
Definition: RowInterval.cc:76
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.
Compatibility Macros for C/C++.
Functions to serialize/deserialize primitives to/from a memory buffer.
void encode_internal(uint8_t **bufp) const override
Writes serialized representation of object to a buffer.
Definition: RowInterval.cc:69
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
#define HT_TRY(_s_, _code_)
Definition: Error.h:517