Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Support node v6 #22

Merged
merged 5 commits into from almost 2 years ago

7 participants

Keiji, Yoshimi Acácio Thomas Fritz Mathieu Lecarme Błażej Pawlak Christopher Mooney Jaye Marshall
Keiji, Yoshimi

support node v6.0 or later. This changes include jmars's node v4 support.

Acácio

+1 up-voting this bug/issue.
The node.js support is becoming a bit long in the tooth... :-/

Mathieu Lecarme

+1

Thomas Fritz

even if it might get compatible with v0.6 sometime, msgpack is no longer faster than plain JSON.parse and JSON.stringify.
Run the benchmarks on your own!

Mathieu Lecarme

msgpack is not a "faster than JSON", it's more compact and handles raw binary, true flotting point. I don't wont to base64 my JPEG to put it in JSON format. Redis scripting handles msgpack format https://github.com/antirez/lua-cmsgpack , I want to test it from nodejs.

Thomas Fritz

@athoune Excatly. Did not want to say that since it is not faster anymore it should not be used. Just thought to state somewhere that is isn't faster than native JSON anymore for those who used it just because of that reason

Christopher Mooney godsflaw merged commit 8caf6d6 into from
Christopher Mooney godsflaw closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 22 additions and 10 deletions. Show diff stats Hide diff stats

  1. +13 2 lib/msgpack.js
  2. +9 8 src/msgpack.cc
15 lib/msgpack.js
@@ -2,8 +2,19 @@
2 2
3 3 var buffer = require('buffer');
4 4 var events = require('events');
5   -var mpBindings = require('../build/default/mpBindings');
6   -var sys = require('sys');
  5 +var mpBindings;
  6 +try {
  7 + // Node v0.5.5 or later
  8 + mpBindings = require(__dirname + "/../build/Release/mpBindings");
  9 +} catch(e) {
  10 + mpBindings = require(__dirname + '/../build/default/mpBindings');
  11 +}
  12 +var sys;
  13 +try {
  14 + sys = require('util');
  15 +} catch (e) {
  16 + sys = require('sys');
  17 +}
7 18
8 19 var pack = mpBindings.pack;
9 20 var unpack = mpBindings.unpack;
17 src/msgpack.cc
@@ -108,16 +108,16 @@ class MsgpackCycle {
108 108 #define DBG_PRINT_BUF(buf, name) \
109 109 do { \
110 110 fprintf(stderr, "Buffer %s has %lu bytes:\n", \
111   - (name), (buf)->length() \
  111 + (name), Buffer::Length(buf) \
112 112 ); \
113   - for (uint32_t i = 0; i * 16 < (buf)->length(); i++) { \
  113 + for (uint32_t i = 0; i * 16 < Buffer::Length(buf); i++) { \
114 114 fprintf(stderr, " "); \
115 115 for (uint32_t ii = 0; \
116   - ii < 16 && (i * 16) + ii < (buf)->length(); \
  116 + ii < 16 && (i * 16) + ii < Buffer::Length(buf); \
117 117 ii++) { \
118 118 fprintf(stderr, "%s%2.2hhx", \
119 119 (ii > 0 && (ii % 2 == 0)) ? " " : "", \
120   - (buf)->data()[i * 16 + ii] \
  120 + Buffer::Data(buf)[i * 16 + ii] \
121 121 ); \
122 122 } \
123 123 fprintf(stderr, "\n"); \
@@ -176,6 +176,7 @@ v8_to_msgpack(Handle<Value> v8obj, msgpack_object *mo, msgpack_zone *mz,
176 176 } else if (Buffer::HasInstance(v8obj)) {
177 177 Local<Object> buf = v8obj->ToObject();
178 178
  179 +
179 180 mo->type = MSGPACK_OBJECT_RAW;
180 181 mo->via.raw.size = Buffer::Length(buf);
181 182 mo->via.raw.ptr = Buffer::Data(buf);
@@ -289,7 +290,7 @@ pack(const Arguments &args) {
289 290 }
290 291
291 292 Buffer *bp = Buffer::New(sb._sbuf.size);
292   - memcpy(bp->data(), sb._sbuf.data, sb._sbuf.size);
  293 + memcpy(Buffer::Data(bp), sb._sbuf.data, sb._sbuf.size);
293 294
294 295 return scope.Close(bp->handle_);
295 296 }
@@ -311,19 +312,19 @@ unpack(const Arguments &args) {
311 312 String::New("First argument must be a Buffer")));
312 313 }
313 314
314   - Buffer *buf = ObjectWrap::Unwrap<Buffer>(args[0]->ToObject());
  315 + Local<Object> buf = args[0]->ToObject();
315 316
316 317 MsgpackZone mz;
317 318 msgpack_object mo;
318 319 size_t off = 0;
319 320
320   - switch (msgpack_unpack(buf->data(), buf->length(), &off, &mz._mz, &mo)) {
  321 + switch (msgpack_unpack(Buffer::Data(buf), Buffer::Length(buf), &off, &mz._mz, &mo)) {
321 322 case MSGPACK_UNPACK_EXTRA_BYTES:
322 323 case MSGPACK_UNPACK_SUCCESS:
323 324 try {
324 325 msgpack_unpack_template->GetFunction()->Set(
325 326 msgpack_bytes_remaining_symbol,
326   - Integer::New(buf->length() - off)
  327 + Integer::New(Buffer::Length(buf) - off)
327 328 );
328 329 return scope.Close(msgpack_to_v8(&mo));
329 330 } catch (MsgpackException e) {

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.