diff options
Diffstat (limited to 'ndb/src/common/util/SimpleProperties.cpp')
-rw-r--r-- | ndb/src/common/util/SimpleProperties.cpp | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/ndb/src/common/util/SimpleProperties.cpp b/ndb/src/common/util/SimpleProperties.cpp index 00c440fcb4e..c25aaea491a 100644 --- a/ndb/src/common/util/SimpleProperties.cpp +++ b/ndb/src/common/util/SimpleProperties.cpp @@ -37,6 +37,28 @@ SimpleProperties::Writer::add(Uint16 key, Uint32 value){ } bool +SimpleProperties::Writer::add(const char * value, int len){ + const Uint32 valLen = (len + 3) / 4; + + if ((len % 4) == 0) + return putWords((Uint32*)value, valLen); + + const Uint32 putLen= valLen - 1; + if (!putWords((Uint32*)value, putLen)) + return false; + + // Special handling of last bytes + union { + Uint32 lastWord; + char lastBytes[4]; + }; + memcpy(lastBytes, + value + putLen*4, + len - putLen*4); + return putWord(lastWord); +} + +bool SimpleProperties::Writer::add(Uint16 key, const char * value){ Uint32 head = StringValue; head <<= 16; @@ -46,9 +68,9 @@ SimpleProperties::Writer::add(Uint16 key, const char * value){ Uint32 strLen = strlen(value) + 1; // Including NULL-byte if(!putWord(htonl(strLen))) return false; - - const Uint32 valLen = (strLen + 3) / 4; - return putWords((Uint32*)value, valLen); + + return add(value, (int)strLen); + } bool @@ -60,9 +82,8 @@ SimpleProperties::Writer::add(Uint16 key, const void* value, int len){ return false; if(!putWord(htonl(len))) return false; - - const Uint32 valLen = (len + 3) / 4; - return putWords((Uint32*)value, valLen); + + return add((const char*)value, len); } SimpleProperties::Reader::Reader(){ @@ -392,6 +413,7 @@ UtilBufferWriter::putWords(const Uint32 * src, Uint32 len){ return (m_buf.append(src, 4 * len) == 0); } + Uint32 UtilBufferWriter::getWordsUsed() const { return m_buf.length() / 4;} |