fuwaneko / node-protobuf

Google Protocol Buffers wrapper for Node.js [UNMAINTAINED]
179 stars 42 forks source link

allow JS code to override the serialized format some #35

Closed cleverca22 closed 10 years ago

cleverca22 commented 10 years ago

if an object of protobuf type CPPTYPE_STRING contains a .toProtobuf method that returns a Buffer

use that return value for the serialized stream

fuwaneko commented 10 years ago

Interesting, could you show a use case please?

cleverca22 commented 10 years ago

https://gist.github.com/cleverca22/c4673cb45b827190dee9

with this, you can serialize an ObjectId in a Mongoose document and store it as a 12 byte bytes field in protobuf rather then a 24 byte hex string

it can likely also be used on plain mongodb with the same idea