-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
Feature Request: Support for CBOR | MessagePack #514
Comments
Message Pack seems not hard to implement, but I need to rename Protocol Buffer related functions before. I'll try this feature, but cannot sure when. |
If you don't have enough time to wait next Protocol Buffer implementation, you can send a PR and I'll review it with pleasure. I saw spec documents of MessagePack and it seems good to challenge. You can reference how About CBOR... well, it seems so hard and would better to wait next Protocol Buffer implementation. |
@samchon Heya, there's no urgency on this, just thought it might be a cool feature, particularly if you can get faster PluginsGiven there's many many different encoding schemes (json, xml, protobuf, msgpack, bson, cbor, csv, etc), perhaps something like the following might be good way to allow users to plugin any encoder but still get the type assertions. import typia from 'typia'
import * as msgpack from '@msgpack/msgpack'
typia.codec('msgpack', { // or json, xml, csv, maybe protobuf (would need to figure out the IDL for it)
encode: (data) => msgpack.encode(data),
decode: (data) => msgpack.decode(data)
})
const encoded = typia.encode<T>('msgpack', data)
const decoded = typia.decode<T>('msgpack', encoded) Encodeconst encoded = typia.encode<string>('msgpack', 'hello') Transpiles to const encoded = (codec, value) => {
// assert BEFORE encode
if(!(typeof value === 'string')) throw Error('todo: diagnostics')
const codec = typia.get_codec(codec)
return codec.encode(data)
}('msgpack', 'hello') Decodeconst decoded = typia.decode<string>('msgpack', encoded) Transpiles to const decoded = (codec, encoded) => {
const codec = typia.get_codec(codec)
const value = codec.decode(encoded)
// assert AFTER decode
if(!(typeof value === 'string')) throw Error('todo: diagnostics')
}('msgpack', encoded) UsecasePossible fast check / verify for http request bodies (for varying content mime types) typia.codec('application/json', {
encode: (data) => {...},
decode: (data) => {...}
})
typia.codec('application/msgpack', {
encode: (data) => {...},
decode: (data) => {...}
})
typia.codec('text/xml', {
encode: (data) => {...},
decode: (data) => {...}
})
function decodeBody<T>(request: HttpRequest): T {
return typia.decode<T>(request.headers.contentType, request.body)
} This may also help remove the need for explicit methods like |
https://github.com/samchon/typia/releases/tag/v5.0.0 Completed to implement Protocol Buffer functions. Will try this feature at end of this year. If someone who wants to try it earlier than me, it is okay. |
Close as no one had challenged. |
Feature Request
As Typia is looking to support Protocol Buffers, was wondering if similar codecs would be possible for either CBOR RFC 8949 or MessagePack.
Both CBOR and MessagePack provide compact JSON binary serialization, and whose data structures may be a bit more representative of types expressible in structural languages like TypeScript (as it's just binary JSON). Also, as Typia would have forward knowledge of types, there may be potential to implement extremely fast encode() / decode() that wouldn't be possible using plain JavaScript implementations.
Primary Usecase
Reference Links
https://msgpack.org/index.html
https://cbor.io/
Current Implementations
https://www.npmjs.com/package/@msgpack/msgpack
https://www.npmjs.com/package/cbor
For consideration.
The text was updated successfully, but these errors were encountered: