Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Messagepack support. #19

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/com/cognitect/transit_with_msgpack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

"use strict";

goog.require("com.cognitect.transit");

var transit = com.cognitect.transit,
org_reader_func = transit.reader,
org_writer_func = transit.writer;

transit.reader = function (type, opts) {
if (type === "msgpack") {
var json_reader = org_reader_func("json", opts),
old_read_func = json_reader.read;
json_reader.read = function (bytes) {
var unpacked = msgpack.unpack(bytes),
unpacked_string = JSON.stringify(unpacked);
return old_read_func.call(json_reader, unpacked_string);
};
return json_reader;
}
return org_reader_func(type, opts);
};

transit.writer = function (type, opts) {
if (type === "msgpack") {
var json_writer = opts === undefined ? org_writer_func("json") : org_writer_func("json", opts),
old_write_func = json_writer.write;
json_writer.write = function (obj, opts_i) {
var transit_json = opts_i === undefined ? old_write_func.call(json_writer, obj) : old_write_func.call(json_writer, obj, opts_i);
return msgpack.pack(JSON.parse(transit_json));
};
return json_writer;
}
return org_writer_func(type, opts);
};