forked from hypergeometric/notepack
-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
msgpack-lite supports Custom Extension Types (Codecs). There's a project that I'd love to switch to this faster lib, but it uses a codec.
(Thanks for maintaining this fork btw!)
msgpack-lite's API for that is okay and maybe the best choice for an easy migration path, but you could also consider some class API like:
// impl
exports.ToMsgPackSym = const ToMsgPackSym = Symbol("notepack.tomsgpack");
// in `_encode`
if (typeof value[ToMsgPackSym] === "function") {
bytes.push(value.constructor[MsgPackTypeSym], ...value[ToMsgPackSym](value));
}
// usage
class MyClass {
static [notepack.MsgPackTypeSym] = 0x00;
[notepack.ToMsgPackSym]() {
return /*something*/;
}
[notepack.FromMsgPackSym](bytes) {
return new MyClass(/*something*/);
}
}
notepack.registerType(MyClass);VasiliyIsaichkin and Domiii
Metadata
Metadata
Assignees
Labels
No labels