c: msgpack_pack_object

This commit is contained in:
frsyuki
2009-02-24 16:37:47 +09:00
parent aaaaecb8ba
commit bdd13859b6
7 changed files with 106 additions and 25 deletions

View File

@@ -5,27 +5,33 @@
int main(void)
{
// this is target object
msgpack::type::tuple<int, bool, std::string> src(1, true, "example");
// any classes that implements write(const char*,size_t) can be a buffer
// serialize the object into the buffer.
// any classes that implements write(const char*,size_t) can be a buffer.
std::stringstream buffer;
msgpack::pack(buffer, src);
// send the buffer ...
buffer.seekg(0);
// deserialize the buffer into msgpack::object type
msgpack::zone mempool;
// deserialize the buffer into msgpack::object instance.
std::string str(buffer.str());
msgpack::object deserialized =
msgpack::unpack(str.data(), str.size(), mempool);
// msgpack::object supports ostream
// deserialized object is valid during the msgpack::zone instance alive.
msgpack::zone mempool;
msgpack::object deserialized;
msgpack::unpack(str.data(), str.size(), NULL, &mempool, &deserialized);
// msgpack::object supports ostream.
std::cout << deserialized << std::endl;
// convert msgpack::object type into the original type
// convert msgpack::object instance into the original type.
// if the type is mismatched, it throws msgpack::type_error exception.
msgpack::type::tuple<int, bool, std::string> dst;
msgpack::convert(dst, deserialized);
deserialized.convert(&dst);
return 0;
}

View File

@@ -84,7 +84,6 @@ struct fwriter {
void write(const char* buf, size_t buflen)
{
size_t count = fwrite(buf, buflen, 1, m_fp);
//if(fwrite(buf, buflen, 1, m_fp) < 1) {
if(count < 1) {
std::cout << buflen << std::endl;
std::cout << count << std::endl;