Skip to content

Commit fe6eefe

Browse files
committed
Copy some enhancements from the async branch
Bailing on the promise of creating a makefile Fix some implicit narrowing conversions Remove dependency on boost filesystem in tests Make clean script also clean libevent
1 parent 8b527bf commit fe6eefe

12 files changed

Lines changed: 180 additions & 48 deletions

Tests/objects.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
USER_OBJS := ../libeventinstall/lib/libevent.a
66

7-
LIBS := -lcppunit -lboost_system-mt -lboost_filesystem-mt -lvoltcpp
7+
LIBS := -lcppunit -lvoltcpp
88

clean.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ cd library_release && make clean
44
cd ../library_debug && make clean
55
cd ../library_release_static && make clean
66
cd ../Tests && make clean
7+
cd ../libevent && make clean

include/AuthenticationRequest.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class AuthenticationRequest {
3333
int32_t getSerializedSize() {
3434
return 8 + //String length prefixes
3535
20 + //SHA-1 hash of PW
36-
m_username.size() +
37-
m_service.size()
36+
static_cast<int32_t>(m_username.size()) +
37+
static_cast<int32_t>(m_service.size())
3838
+ 4 //length prefix
3939
+ 1; //version number
4040
}

include/ByteBuffer.hpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,53 @@ class ByteBuffer {
272272
put(value.data(), size);
273273
return *this;
274274
}
275+
276+
bool getBytes(bool &wasNull, int32_t bufsize, uint8_t *out_value, int32_t *out_len)
277+
throw (OverflowUnderflowException) {
278+
int32_t length = getInt32();
279+
*out_len = length;
280+
if (!out_value)
281+
return false;
282+
if (length == -1) {
283+
wasNull = true;
284+
return true;
285+
}
286+
if (length > bufsize)
287+
return false;
288+
char *data = getByReference(length);
289+
memcpy(out_value, data, length);
290+
return true;
291+
}
292+
bool getBytes(int32_t index, bool &wasNull, const int32_t bufsize, uint8_t *out_value, int32_t *out_len)
293+
throw (OverflowUnderflowException, IndexOutOfBoundsException) {
294+
int32_t length = getInt32(index);
295+
*out_len = length;
296+
if (!out_value)
297+
return false;
298+
if (length == -1) {
299+
wasNull = true;
300+
return true;
301+
}
302+
if (length > bufsize)
303+
return false;
304+
char *data = getByReference(index + 4, length);
305+
memcpy(out_value, data, length);
306+
return true;
307+
}
308+
ByteBuffer& putBytes(const int32_t bufsize, const uint8_t *in_value)
309+
throw (OverflowUnderflowException) {
310+
assert(in_value);
311+
putInt32(bufsize);
312+
put((const char*)in_value, bufsize);
313+
return *this;
314+
}
315+
ByteBuffer& putBytes(int32_t index, const int32_t bufsize, const uint8_t *in_value)
316+
throw (OverflowUnderflowException, IndexOutOfBoundsException) {
317+
assert(in_value);
318+
putInt32(index, bufsize);
319+
put(index + 4, (const char*)in_value, bufsize);
320+
return *this;
321+
}
275322
ByteBuffer& putString(int32_t index, std::string value) throw (OverflowUnderflowException, IndexOutOfBoundsException) {
276323
int32_t size = static_cast<int32_t>(value.size());
277324
putInt32(index, size);

include/ParameterSet.hpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,29 @@ class ParameterSet {
4242
friend class Procedure;
4343
public:
4444

45+
/**
46+
* Add a binary payload
47+
* @throws ParamMismatchException Supplied parameter is the wrong type for this position or too many have been set
48+
* @return Reference to this parameter set to allow invocation chaining.
49+
*/
50+
ParameterSet& addBytes(const int32_t bufsize, const uint8_t *in_value)
51+
throw (voltdb::ParamMismatchException) {
52+
validateType(WIRE_TYPE_VARBINARY, false);
53+
m_buffer.ensureRemaining(1 + 4 + bufsize);
54+
m_buffer.putInt8(WIRE_TYPE_DECIMAL);
55+
m_buffer.putBytes(bufsize, in_value);
56+
m_currentParam++;
57+
return *this;
58+
}
59+
4560
/**
4661
* Add a decimal value for the current parameter
4762
* @throws ParamMismatchException Supplied parameter is the wrong type for this position or too many have been set
4863
* @return Reference to this parameter set to allow invocation chaining.
4964
*/
5065
ParameterSet& addDecimal(Decimal val) throw (voltdb::ParamMismatchException) {
5166
validateType(WIRE_TYPE_DECIMAL, false);
52-
m_buffer.ensureRemaining(sizeof(Decimal) + 1);
67+
m_buffer.ensureRemaining(static_cast<int32_t>(sizeof(Decimal)) + 1);
5368
m_buffer.putInt8(WIRE_TYPE_DECIMAL);
5469
val.serializeTo(&m_buffer);
5570
m_currentParam++;
@@ -63,7 +78,7 @@ class ParameterSet {
6378
*/
6479
ParameterSet& addDecimal(std::vector<Decimal> vals) throw (voltdb::ParamMismatchException) {
6580
validateType(WIRE_TYPE_DECIMAL, true);
66-
m_buffer.ensureRemaining(4 + (sizeof(Decimal) * vals.size()));
81+
m_buffer.ensureRemaining(4 + static_cast<int32_t>(sizeof(Decimal) * vals.size()));
6782
m_buffer.putInt8(WIRE_TYPE_ARRAY);
6883
m_buffer.putInt8(WIRE_TYPE_DECIMAL);
6984
m_buffer.putInt16(static_cast<int16_t>(vals.size()));
@@ -95,7 +110,7 @@ class ParameterSet {
95110
*/
96111
ParameterSet& addTimestamp(std::vector<int64_t> vals) throw (voltdb::ParamMismatchException) {
97112
validateType(WIRE_TYPE_TIMESTAMP, true);
98-
m_buffer.ensureRemaining(4 + (sizeof(int64_t) * vals.size()));
113+
m_buffer.ensureRemaining(4 + static_cast<int32_t>(sizeof(int64_t) * vals.size()));
99114
m_buffer.putInt8(WIRE_TYPE_ARRAY);
100115
m_buffer.putInt8(WIRE_TYPE_TIMESTAMP);
101116
m_buffer.putInt16(static_cast<int16_t>(vals.size()));
@@ -127,7 +142,7 @@ class ParameterSet {
127142
*/
128143
ParameterSet& addInt64(std::vector<int64_t> vals) throw (voltdb::ParamMismatchException) {
129144
validateType(WIRE_TYPE_BIGINT, true);
130-
m_buffer.ensureRemaining(4 + (sizeof(int64_t) * vals.size()));
145+
m_buffer.ensureRemaining(4 + static_cast<int32_t>(sizeof(int64_t) * vals.size()));
131146
m_buffer.putInt8(WIRE_TYPE_ARRAY);
132147
m_buffer.putInt8(WIRE_TYPE_BIGINT);
133148
m_buffer.putInt16(static_cast<int16_t>(vals.size()));
@@ -159,7 +174,7 @@ class ParameterSet {
159174
*/
160175
ParameterSet& addInt32(std::vector<int32_t> vals) throw (voltdb::ParamMismatchException) {
161176
validateType(WIRE_TYPE_INTEGER, true);
162-
m_buffer.ensureRemaining(4 + (sizeof(int32_t) * vals.size()));
177+
m_buffer.ensureRemaining(4 + static_cast<int32_t>(sizeof(int32_t) * vals.size()));
163178
m_buffer.putInt8(WIRE_TYPE_ARRAY);
164179
m_buffer.putInt8(WIRE_TYPE_INTEGER);
165180
m_buffer.putInt16(static_cast<int16_t>(vals.size()));
@@ -191,7 +206,7 @@ class ParameterSet {
191206
*/
192207
ParameterSet& addInt16(std::vector<int16_t> vals) throw (voltdb::ParamMismatchException) {
193208
validateType(WIRE_TYPE_SMALLINT, true);
194-
m_buffer.ensureRemaining(4 + (sizeof(int16_t) * vals.size()));
209+
m_buffer.ensureRemaining(4 + static_cast<int32_t>(sizeof(int16_t) * vals.size()));
195210
m_buffer.putInt8(WIRE_TYPE_ARRAY);
196211
m_buffer.putInt8(WIRE_TYPE_SMALLINT);
197212
m_buffer.putInt16(static_cast<int16_t>(vals.size()));
@@ -223,7 +238,7 @@ class ParameterSet {
223238
*/
224239
ParameterSet& addInt8(std::vector<int8_t> vals) throw (voltdb::ParamMismatchException) {
225240
validateType(WIRE_TYPE_TINYINT, true);
226-
m_buffer.ensureRemaining(6 + (sizeof(int8_t) * vals.size()));
241+
m_buffer.ensureRemaining(6 + static_cast<int32_t>(sizeof(int8_t) * vals.size()));
227242
m_buffer.putInt8(WIRE_TYPE_ARRAY);
228243
m_buffer.putInt8(WIRE_TYPE_TINYINT);
229244
m_buffer.putInt32(static_cast<int32_t>(vals.size()));
@@ -255,7 +270,7 @@ class ParameterSet {
255270
*/
256271
ParameterSet& addDouble(std::vector<double> vals) throw (voltdb::ParamMismatchException) {
257272
validateType(WIRE_TYPE_FLOAT, true);
258-
m_buffer.ensureRemaining(2 + (sizeof(double) * vals.size()));
273+
m_buffer.ensureRemaining(2 + static_cast<int32_t>(sizeof(double) * vals.size()));
259274
m_buffer.putInt8(WIRE_TYPE_ARRAY);
260275
m_buffer.putInt8(WIRE_TYPE_FLOAT);
261276
m_buffer.putInt16(static_cast<int16_t>(vals.size()));
@@ -291,7 +306,7 @@ class ParameterSet {
291306
*/
292307
ParameterSet& addString(std::string val) throw (voltdb::ParamMismatchException) {
293308
validateType(WIRE_TYPE_STRING, false);
294-
m_buffer.ensureRemaining(5 + val.size());
309+
m_buffer.ensureRemaining(5 + static_cast<int32_t>(val.size()));
295310
m_buffer.putInt8(WIRE_TYPE_STRING);
296311
m_buffer.putString(val);
297312
m_currentParam++;

include/Row.hpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ class Row {
5353
m_data(rowData), m_columns(columns), m_wasNull(false), m_offsets(columns->size()), m_hasCalculatedOffsets(false) {
5454
}
5555

56+
/*
57+
* Retrieve the value at the specified column index as bytes. The type of the column
58+
* must be Varbinary.
59+
* @throws InvalidColumnException The index of the column was invalid or the type of the column does
60+
* not match the type of the get method.
61+
* @return Whether the buffer provided was large enough.
62+
*/
63+
bool getVarbinary(int32_t column, int32_t bufsize, uint8_t *out_value, int32_t *out_len) throw(voltdb::InvalidColumnException) {
64+
validateType(WIRE_TYPE_VARBINARY, column);
65+
return m_data.getBytes(getOffset(column), m_wasNull, bufsize, out_value, out_len);
66+
}
67+
5668
/*
5769
* Retrieve the value at the specified column index as a Decimal. The type of the column
5870
* must be Decimal.
@@ -241,12 +253,27 @@ class Row {
241253
getDouble(column); break;
242254
case WIRE_TYPE_STRING:
243255
getString(column); break;
256+
case WIRE_TYPE_VARBINARY:
257+
int out_len;
258+
getVarbinary(column, 0, NULL, &out_len); break;
244259
default:
245260
assert(false);
246261
}
247262
return wasNull();
248263
}
249264

265+
/*
266+
* Retrieve the value from the column with the specified name as bytes. The type of the column
267+
* must be Varbinary.
268+
* @throws InvalidColumnException The index of the column was invalid or the type of the column does
269+
* not match the type of the get method.
270+
* @return Whether the buffer provided was large enough.
271+
*/
272+
bool getVarbinary(std::string cname, int32_t bufsize, uint8_t *out_value, int32_t *out_len)
273+
throw(voltdb::InvalidColumnException) {
274+
return getVarbinary(getColumnIndexByName(cname), bufsize, out_value, out_len);
275+
}
276+
250277
/*
251278
* Retrieve the value from the column with the specified name as a Decimal. The type of the column
252279
* must be Decimal.
@@ -367,7 +394,8 @@ class Row {
367394
*/
368395
void toString(std::ostringstream &ostream, std::string indent) {
369396
ostream << indent;
370-
for (size_t ii = 0; ii < m_columns->size(); ii++) {
397+
const int32_t size = static_cast<int32_t>(m_columns->size());
398+
for (int32_t ii = 0; ii < size; ii++) {
371399
if (ii != 0) {
372400
ostream << ", ";
373401
}
@@ -392,14 +420,16 @@ class Row {
392420
ostream << getTimestamp(ii); break;
393421
case WIRE_TYPE_DECIMAL:
394422
ostream << getDecimal(ii).toString(); break;
423+
case WIRE_TYPE_VARBINARY:
424+
ostream << "VARBINARY VALUE"; break;
395425
default:
396426
assert(false);
397427
}
398428
}
399429
}
400430

401431
int32_t columnCount() {
402-
return m_columns->size();
432+
return static_cast<int32_t>(m_columns->size());
403433
}
404434

405435
std::vector<voltdb::Column> columns() {
@@ -442,6 +472,9 @@ class Row {
442472
case WIRE_TYPE_STRING:
443473
if (type != WIRE_TYPE_STRING) throw InvalidColumnException();
444474
break;
475+
case WIRE_TYPE_VARBINARY:
476+
if (type != WIRE_TYPE_VARBINARY) throw InvalidColumnException();
477+
break;
445478
default:
446479
assert(false);
447480
break;
@@ -463,7 +496,7 @@ class Row {
463496
m_offsets[0] = m_data.position();
464497
for (int32_t i = 1; i < static_cast<ssize_t>(m_columns->size()); i++) {
465498
WireType type = m_columns->at(static_cast<size_t>(i - 1)).m_type;
466-
if (type == WIRE_TYPE_STRING) {
499+
if (type == WIRE_TYPE_STRING || (type == WIRE_TYPE_VARBINARY)) {
467500
int32_t length = m_data.getInt32(m_offsets[static_cast<size_t>(i - 1)]);
468501
if (length == -1) {
469502
m_offsets[static_cast<size_t>(i)] = m_offsets[static_cast<size_t>(i - 1)] + 4;

include/RowBuilder.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,29 @@ class RowBuilder {
104104
m_buffer.putInt32(-1);
105105
m_currentColumn++;
106106
break;
107+
case WIRE_TYPE_VARBINARY:
108+
m_buffer.ensureRemaining(4);
109+
m_buffer.putInt32(-1);
110+
m_currentColumn++;
111+
break;
107112
default:
108113
assert(false);
109114
}
110115
}
111116
void addString(std::string val) {
112117
validateType(WIRE_TYPE_STRING);
113-
m_buffer.ensureRemaining(4 + val.size());
118+
m_buffer.ensureRemaining(4 + static_cast<int32_t>(val.size()));
114119
m_buffer.putString(val);
115120
m_currentColumn++;
116121
}
122+
123+
void addVarbinary(const int32_t bufsize, const uint8_t *in_value) {
124+
validateType(WIRE_TYPE_VARBINARY);
125+
m_buffer.ensureRemaining(4 + bufsize);
126+
m_buffer.putBytes(bufsize, in_value);
127+
m_currentColumn++;
128+
}
129+
117130
void reset() {
118131
m_buffer.clear();
119132
m_currentColumn = 0;

include/WireType.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ enum WireType {
3838
WIRE_TYPE_FLOAT = 8,
3939
WIRE_TYPE_STRING = 9,
4040
WIRE_TYPE_TIMESTAMP = 11,
41-
WIRE_TYPE_DECIMAL = 22
41+
WIRE_TYPE_DECIMAL = 22,
42+
WIRE_TYPE_VARBINARY = 25
4243
};
4344

4445
std::string wireTypeToString(WireType type);

src/Table.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace voltdb {
6262
}
6363

6464
int32_t Table::columnCount() {
65-
return m_columns->size();
65+
return static_cast<int32_t>(m_columns->size());
6666
}
6767

6868
std::vector<voltdb::Column> Table::columns() {

src/WireType.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ std::string wireTypeToString(WireType type) {
4646
return std::string("TIMESTAMP");
4747
case WIRE_TYPE_DECIMAL:
4848
return std::string("DECIMAL");
49+
case WIRE_TYPE_VARBINARY:
50+
return std::string("VARBINARY");
4951
default:
5052
assert(false);
5153
}

0 commit comments

Comments
 (0)