Permalink
Browse files

applied https://github.com/pgriess/node-msgpack/pull/22.diff

  • Loading branch information...
1 parent 4c430f7 commit 063391900cc52e350238d2aa535a5c09b794456f @jakob-stoeck jakob-stoeck committed Jan 19, 2012
Showing with 22 additions and 10 deletions.
  1. +13 −2 lib/msgpack.js
  2. +9 −8 src/msgpack.cc
View
@@ -2,8 +2,19 @@
var buffer = require('buffer');
var events = require('events');
-var mpBindings = require('../build/default/mpBindings');
-var sys = require('sys');
+var mpBindings;
+try {
+ // Node v0.5.5 or later
+ mpBindings = require(__dirname + "/../build/Release/mpBindings");
+} catch(e) {
+ mpBindings = require(__dirname + '/../build/default/mpBindings');
+}
+var sys;
+try {
+ sys = require('util');
+} catch (e) {
+ sys = require('sys');
+}
var pack = mpBindings.pack;
var unpack = mpBindings.unpack;
View
@@ -108,16 +108,16 @@ class MsgpackCycle {
#define DBG_PRINT_BUF(buf, name) \
do { \
fprintf(stderr, "Buffer %s has %lu bytes:\n", \
- (name), (buf)->length() \
+ (name), Buffer::Length(buf) \
); \
- for (uint32_t i = 0; i * 16 < (buf)->length(); i++) { \
+ for (uint32_t i = 0; i * 16 < Buffer::Length(buf); i++) { \
fprintf(stderr, " "); \
for (uint32_t ii = 0; \
- ii < 16 && (i * 16) + ii < (buf)->length(); \
+ ii < 16 && (i * 16) + ii < Buffer::Length(buf); \
ii++) { \
fprintf(stderr, "%s%2.2hhx", \
(ii > 0 && (ii % 2 == 0)) ? " " : "", \
- (buf)->data()[i * 16 + ii] \
+ Buffer::Data(buf)[i * 16 + ii] \
); \
} \
fprintf(stderr, "\n"); \
@@ -176,6 +176,7 @@ v8_to_msgpack(Handle<Value> v8obj, msgpack_object *mo, msgpack_zone *mz,
} else if (Buffer::HasInstance(v8obj)) {
Local<Object> buf = v8obj->ToObject();
+
mo->type = MSGPACK_OBJECT_RAW;
mo->via.raw.size = Buffer::Length(buf);
mo->via.raw.ptr = Buffer::Data(buf);
@@ -289,7 +290,7 @@ pack(const Arguments &args) {
}
Buffer *bp = Buffer::New(sb._sbuf.size);
- memcpy(bp->data(), sb._sbuf.data, sb._sbuf.size);
+ memcpy(Buffer::Data(bp), sb._sbuf.data, sb._sbuf.size);
return scope.Close(bp->handle_);
}
@@ -311,19 +312,19 @@ unpack(const Arguments &args) {
String::New("First argument must be a Buffer")));
}
- Buffer *buf = ObjectWrap::Unwrap<Buffer>(args[0]->ToObject());
+ Local<Object> buf = args[0]->ToObject();
MsgpackZone mz;
msgpack_object mo;
size_t off = 0;
- switch (msgpack_unpack(buf->data(), buf->length(), &off, &mz._mz, &mo)) {
+ switch (msgpack_unpack(Buffer::Data(buf), Buffer::Length(buf), &off, &mz._mz, &mo)) {
case MSGPACK_UNPACK_EXTRA_BYTES:
case MSGPACK_UNPACK_SUCCESS:
try {
msgpack_unpack_template->GetFunction()->Set(
msgpack_bytes_remaining_symbol,
- Integer::New(buf->length() - off)
+ Integer::New(Buffer::Length(buf) - off)
);
return scope.Close(msgpack_to_v8(&mo));
} catch (MsgpackException e) {

0 comments on commit 0633919

Please sign in to comment.