[svn] commit: r426 - /branches/parkinglot/src/lib/cc/cpp/data.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Jan 4 12:59:22 UTC 2010
Author: jelte
Date: Mon Jan 4 12:59:22 2010
New Revision: 426
Log:
fixed a few bugs found with the tests;
- added a wire-type ITEM_REAL (for DoubleElements) (we could technically
use ITEM_INT with the current code, but certainly not ITEM_UTF8).
if we keep this one, we need to add it to the other versions too (python&ruby)
- Bad boolean values in the string format returned a Null ElementPtr instead of raising an exception.
- Fixed decoding of True values off the wire
- Removed a few checks that aren't needed
- Fixed a null-termination problem when encoding big packets (i.e. > 256 and
> 65535 bytes)
Modified:
branches/parkinglot/src/lib/cc/cpp/data.cc
Modified: branches/parkinglot/src/lib/cc/cpp/data.cc
==============================================================================
--- branches/parkinglot/src/lib/cc/cpp/data.cc (original)
+++ branches/parkinglot/src/lib/cc/cpp/data.cc Mon Jan 4 12:59:22 2010
@@ -20,6 +20,7 @@
const unsigned char ITEM_NULL = 0x04;
const unsigned char ITEM_BOOL = 0x05;
const unsigned char ITEM_INT = 0x06;
+const unsigned char ITEM_REAL = 0x07;
const unsigned char ITEM_UTF8 = 0x08;
const unsigned char ITEM_MASK = 0x0f;
@@ -246,7 +247,7 @@
} else if (boost::iequals(word, "False")) {
return Element::create(false);
} else {
- return ElementPtr();
+ throw ParseError(std::string("Bad boolean value: ") + word, line, pos);
}
}
@@ -294,9 +295,6 @@
in.get();
pos++;
p.second = Element::createFromString(in, line, pos);
- if (!p.second) {
- throw ParseError(std::string("missing map value for ") + p.first, line, pos);
- };
m.insert(p);
skip_to(in, line, pos, ",}", " \t\n");
c = in.get();
@@ -544,16 +542,13 @@
return ss.str();
}
-// currently throws when one of the types in the path (except the one
+// throws when one of the types in the path (except the one
// we're looking for) is not a MapElement
// returns 0 if it could simply not be found
// should that also be an exception?
ElementPtr
MapElement::find(const std::string& id)
{
- if (getType() != map) {
- throw TypeError();
- }
size_t sep = id.find('/');
if (sep == std::string::npos) {
return get(id);
@@ -612,7 +607,8 @@
{
char c;
c = in.get();
- if (c == 0x01) {
+
+ if (c == '1') {
return Element::create(true);
} else {
return Element::create(false);
@@ -621,6 +617,13 @@
ElementPtr
decode_int(std::stringstream& in, int& item_length)
+{
+ int skip, me;
+ return from_stringstream_int_or_double(in, skip, me);
+}
+
+ElementPtr
+decode_real(std::stringstream& in, int& item_length)
{
int skip, me;
return from_stringstream_int_or_double(in, skip, me);
@@ -730,6 +733,9 @@
break;
case ITEM_INT:
element = decode_int(in, item_length);
+ break;
+ case ITEM_REAL:
+ element = decode_real(in, item_length);
break;
case ITEM_BLOB:
element = decode_blob(in, item_length);
@@ -792,21 +798,19 @@
type |= ITEM_LENGTH_8;
ss << type << val;
} else if (length <= 0x0000ffff) {
- unsigned char val[3];
+ unsigned char val[2];
val[0] = (length & 0x0000ff00) >> 8;
val[1] = (length & 0x000000ff);
- val[2] = 0;
type |= ITEM_LENGTH_16;
- ss << type << val;
- } else {
- unsigned char val[5];
+ ss << type << val[0] << val[1];
+ } else {
+ unsigned char val[4];
val[0] = (length & 0xff000000) >> 24;
val[1] = (length & 0x00ff0000) >> 16;
val[2] = (length & 0x0000ff00) >> 8;
val[3] = (length & 0x000000ff);
- val[4] = 0;
type |= ITEM_LENGTH_32;
- ss << type << val;
+ ss << type << val[0] << val[1] << val[2] << val[3];
}
return ss.str();
}
@@ -816,7 +820,7 @@
{
std::stringstream ss;
- int length = stringValue().length();
+ unsigned int length = stringValue().length();
ss << encode_length(length, ITEM_UTF8) << stringValue();
return ss.str();
@@ -861,7 +865,7 @@
text << str();
int length = text.str().length();
- ss << encode_length(length, ITEM_UTF8) << text.str();
+ ss << encode_length(length, ITEM_REAL) << text.str();
return ss.str();
}
More information about the bind10-changes
mailing list