How to do encode objects in to compact byte buffers and then decode them back in to objects on the receiver
Submitting
- [ ] Bug
- [x] Question
- [ ] Suggestion
- [ ] Other
Details
How to do encode objects in to compact byte buffers and then decode them back in to objects on the receiver
here is the libs i want to use https://github.com/phretaddin/schemapack
add this in my project
i know this libs have way in pre-process message on receive
wss.setMiddleware('onMessageReceive', (socket, message, next) => {});
useBinary option in libs already do binary but not good enough for me
by the way I like this libs
There is encodeDecodeEngine options in ClusterWS which has two functions check guide at the bottom, unfortunately this option does not work in Java library yet (should be fixed by next release), all other clients (Swift, JavaScript) support it properly. There is not a lot of documentations for that options as it does not have full support in ClusterWS, but it is literally two functions which get message and return encoded/decoded message back.
Also check wiki in Javascript client library and Swift
hi goriunov , thx for your answer but you can see this libs https://github.com/phretaddin/schemapack
in different message need to different schem so that encodeDecodeEngine cant support it
You can pass type when u use send method for example:
socket.send("hello world", {type: "player", data: {/* You object **/}})
and then in your encode function
encode: (message) => {
if(message.type === "player") {
return playerSchema.encode(message.data);
}
if(message.type === "...") {
return ...
}
}
In in your decode function in client you will need to listen to the message on the emit event and decode in each separate emit event (i have not tried that).
Thx for answer but it will be buffer encode twice or three times or to be string when options use useBinary or encodeDecodeEngine i need it efficient exchange of information。
For example the event or publish comes from or send to other side can use first bit to decide what is this than resolve binary by schem
Ohh, unfortunately there is no way to do that yet.
But event if you decode just your message it will still reduce size quite a bit compering to the default JSON size.
I will think about that. Probably add some functions to easier modify internal protocol