kastnermario / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

YAML::Binary doesn't work on non-ascii char #102

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. void* buffer = new char[size];
2. // put something non-ascii in the buffer
3. YAML::Emitter out; out << YAML::Binary((char*) data, size);

What is the expected output? What do you see instead?
Emitting binary data with YAML::Binary((char*) data(), size) works fine for 
ascii char, but fails when dealing with true binary data. Method fails and 
returns a non-valid yaml node.

What version of the product are you using? On what operating system?
Currently latest version (0.2.6), but affects also previous version. OS is 
ubuntu linux 32bit 10.10

Please provide any additional information below.
I wrote a quick patch. Basically I use unsigned char instead of char for binary 
data

Original issue reported on code.google.com by nebir...@gmail.com on 8 Apr 2011 at 7:42

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks, applied, r1cc0a4031cb5.

In your opinion, is it worth having a (const char *) overload as well? 
Presumably reinterpret_cast<const unsigned char*> works fine, although it's not 
well-defined. But I'd imagine most people's binary data will be in unsigned 
char * format anyways?

Original comment by jbe...@gmail.com on 6 Sep 2011 at 5:41

GoogleCodeExporter commented 8 years ago
Issue 111 has been merged into this issue.

Original comment by jbe...@gmail.com on 6 Sep 2011 at 5:55

GoogleCodeExporter commented 8 years ago
I think there's no need to have such a method. unsigned char affects only 
non-ASCII char, and only the way that char are used like an int, as in 
YAML::Utils::WriteBinary(). For common use a simple cast  like 
YAML::Binary((char*) data, size) should work fine.

Also, I'm working (finally!) on the reverse convertion - parse a binary yaml, 
something like:

YAML::BinaryInput bin;
doc["data"] >> bin;

Take a look here https://github.com/nebirhos/yaml-cpp/tree/binary

Original comment by fradi...@gmail.com on 6 Sep 2011 at 9:48

GoogleCodeExporter commented 8 years ago
Cool!

By the way, I switched the repo from svn to hg, so I'm not sure if you can 
still pull the changes with your git mirror. (I don't know how github's svn 
mirror works.)

Original comment by jbe...@gmail.com on 6 Sep 2011 at 4:51