From 78dabb443330c3a3d5ae6c014e48d42097c1d1d9 Mon Sep 17 00:00:00 2001 From: Jelte Jansen Date: Fri, 20 Nov 2009 14:18:37 +0000 Subject: [PATCH] bool type in cpp cc git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@316 e5f2f494-b856-4b98-b285-d166d9295462 --- src/lib/cc/cpp/data.cc | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/lib/cc/cpp/data.cc b/src/lib/cc/cpp/data.cc index 38d4c51162..bae56a2657 100644 --- a/src/lib/cc/cpp/data.cc +++ b/src/lib/cc/cpp/data.cc @@ -18,6 +18,7 @@ const unsigned char ITEM_BLOB = 0x01; const unsigned char ITEM_HASH = 0x02; const unsigned char ITEM_LIST = 0x03; const unsigned char ITEM_NULL = 0x04; +const unsigned char ITEM_BOOL = 0x05; const unsigned char ITEM_UTF8 = 0x08; const unsigned char ITEM_MASK = 0x0f; @@ -553,6 +554,18 @@ decode_tag(std::stringstream& in, int& item_length) return std::string(buf, len); } +ElementPtr +decode_bool(std::stringstream& in, int& item_length) +{ + char c; + c = in.get(); + if (c == 0x01) { + return Element::create(true); + } else { + return Element::create(false); + } +} + ElementPtr decode_blob(std::stringstream& in, int& item_length) { @@ -652,6 +665,9 @@ decode_element(std::stringstream& in, int& in_length) in_length -= item_length; switch (type) { + case ITEM_BOOL: + element = decode_bool(in, item_length); + break; case ITEM_BLOB: element = decode_blob(in, item_length); break; @@ -761,8 +777,13 @@ BoolElement::to_wire(int omit_length) std::stringstream text; text << str(); - int length = text.str().length(); - ss << encode_length(length, ITEM_UTF8) << text.str(); + int length = 1; + ss << encode_length(length, ITEM_BOOL); + if (bool_value()) { + ss << 0x01; + } else { + ss << 0x00; + } return ss.str(); }