Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Handle Date object packing
Browse files Browse the repository at this point in the history
  • Loading branch information
squamos committed Oct 30, 2012
1 parent 480376b commit 247366a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "msgpack",
"description": "A space-efficient object serialization library for node.js",
"version": "0.1.6",
"version": "0.1.7",
"homepage": "https://github.com/pgriess/node-msgpack",
"author": "Peter Griess <pg@std.in>",
"contributors": [
Expand Down
10 changes: 10 additions & 0 deletions src/msgpack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ v8_to_msgpack(Handle<Value> v8obj, msgpack_object *mo, msgpack_zone *mz,
mo->via.raw.ptr = (char*) msgpack_zone_malloc(mz, mo->via.raw.size);

DecodeWrite((char*) mo->via.raw.ptr, mo->via.raw.size, v8obj, UTF8);
} else if (v8obj->IsDate()) {
mo->type = MSGPACK_OBJECT_RAW;
Handle<Date> date = Handle<Date>::Cast(v8obj);
Handle<Function> func = Handle<Function>::Cast(date->Get(String::New("toISOString")));
Handle<Value> argv[0] = {};

This comment has been minimized.

Copy link
@godsflaw

godsflaw Jun 14, 2013

Collaborator

This throws compile errors on Windows.

This comment has been minimized.

Copy link
@sayantanhore

sayantanhore Jul 6, 2014

Getting the following error...
msgpack.cc(181): error C2466: cannot allocate an array of constant size 0 [C:\Users\Sayantan\node_modules\zerorpc\node_modules\msgpack\build\msgpackBinding.vcxproj

Handle<Value> result = func->Call(date, 0, argv);
mo->via.raw.size = static_cast<uint32_t>(DecodeBytes(result, UTF8));
mo->via.raw.ptr = (char*) msgpack_zone_malloc(mz, mo->via.raw.size);

DecodeWrite((char*) mo->via.raw.ptr, mo->via.raw.size, result, UTF8);
} else if (v8obj->IsArray()) {
Local<Object> o = v8obj->ToObject();
Local<Array> a = Local<Array>::Cast(o);
Expand Down
5 changes: 5 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ testEqual([1, 2, 3]);
testEqual([1, 'abc', false, null]);
testEqual({'a' : [1, 2, 3], 'b' : 'cdef', 'c' : {'nuts' : 'qqq'}});

// Make sure dates are handled properly
var date = new Date();
var dateWrapper = {d: date};
assert.deepEqual({d: date.toISOString()}, msgpack.unpack(msgpack.pack(dateWrapper)));

// Make sure we're catching circular references for arrays
var a = [1, 2, 3, 4];
a.push(a);
Expand Down

0 comments on commit 247366a

Please sign in to comment.