mcollina / hyperemitter

Horizontally Scalable EventEmitter powered by a Merkle DAG
ISC License
70 stars 2 forks source link

Add support for more Encoders #7

Closed mcdonnelldean closed 9 years ago

mcdonnelldean commented 9 years ago

Encoding should be configurable, obviously this has an impact on the implicit schema checking code. Proposed encoders are:

Do we need any more? Should be support XML?

mcollina commented 9 years ago

How about we should support any encoder/decoder that is compatible with levelup, using the same api:

https://github.com/mafintosh/protocol-buffers#leveldb-encoding-compatibility https://github.com/mcollina/msgpack5#levelup-support

mcdonnelldean commented 9 years ago

Sounds good. What about the issue of schema's, we currently match against Protobuf's schema.

mcollina commented 9 years ago

Basically whatever you put into hyper.message that has an encode and decode function should work, as in levelup.

mcdonnelldean commented 9 years ago

That's not how we are doing the schema check though, unless I misunderstand. We are using protobouf's object directly and checking it like an array:

https://github.com/mcollina/hyperemitter/blob/master/hyperemitter.js#L109-L116

mcollina commented 9 years ago

yes, but if it quacks like a duck, it's a duck. messages is a Object, with each property being a supported event. In that object, all properties are Object themselves that have an encode() https://github.com/mcollina/hyperemitter/blob/master/hyperemitter.js#L120 and decode() https://github.com/mcollina/hyperemitter/blob/master/hyperemitter.js#L297

mcdonnelldean commented 9 years ago

This assumes we have an object sent to us in that shape. So in the case say msgpack to we provide an interface their to export all types so the user doesn't have to do the transform themselves? Interestingly this would open up HyperEmitter to have different encoders on a per message basis.

mcdonnelldean commented 9 years ago

Also perhaps something like emitter.registerType(type)

mcollina commented 9 years ago

if you do:

hyper.messages.MyMsgPackMsg = msgpack()

you will be good to go.

mcdonnelldean commented 9 years ago

Ok, let me play with this tomorrow night and come up with a WIP PR to discuss.

mcdonnelldean commented 9 years ago

Started with #15

mcollina commented 9 years ago

Implemented in 1.2.0.