On Fri, 2008-10-03 at 02:29 +0530, Danushka Menikkumbura wrote:
> ...
> At the moment "data" is a std::string and the method "setData" assigns 
> the incoming string value to this std::string variable directly. When it 
> comes to binary data, we can see null terminators in the middle and 
> hence assigning the binary data stream to a std::string will definitely  
> truncate the data.

Where do you get the idea that std::string cannot handle embedded nul
characters?

Essentially the C++ std::string is a blob of bytes and a length so it is
perfectly capable of holding nul characters. The C++ standard talks
about "a sequence consisting of a varying number of arbitrary char-like
objects" [note it doesn't restrict the contents of those objects to be
non-null].

You might ask why do we have strings then and not just a vector<char> or
vector<wchar> and the real answer is only history (std::string came
first)

It is true that if you were to try to convert a std::string containing
the nul char to a c style char* string then it would be truncated at the
first 0.

>  So what we will have in the message is just a part of 
> the original binary data.
> 
> So, as a solution for this, we need to have two class level variables to 
> keep binary data.
> 
> 1. void* data;
> 2. long dataLength;
> 
> These two are enough to say all about our binary data dump. So, 
> obviously we need to have separate methods to get and set binary data.
> 
> We may make use of these changes to keep string data as well so that we 
> can drop the current std::string variable.
> 
> I can send you a patch if we are happy with this.
> 
> Danushka
> 

Reply via email to