packBytes Discussion #3
Replies: 2 comments 21 replies
-
Hey, do you use this library with uWebsockets.js? I am using it the following way instead of using json for communication between servers; // Node.js server
import WebSocket from 'websocket';
import { PackBytes, string } from 'packBytes';
const encoder = new PackBytes({ op: string, payload: string });
const ws = WebSocket('ws://localhost:3020');
ws.on('open', () => {
const msg = encoder.encode({ op: "subscribe", payload: "some-topic" });
ws.send(msg);
});
// uWebsockets.js server
import { App } from 'uWebsockets.js';
const app = App({ }).ws('/*', {
open: (ws) => {
const ping = encoder.encode({ op: "ping", payload: "connected" })
ws.send(ping);
},
message: (ws, message) => {
const decoded = encoder.decode(Buffer.from(message));
console.log(decoded); // { op: "subscribe", payload: "some-topic" }
}
}) What do you think about this? Any recommendations to improve this would be greatly appreciated. Thanks for this library, I love it. |
Beta Was this translation helpful? Give feedback.
-
Hey, I was trying to encode object that has the following shape: {
createdBy: 12,
id: 2,
posting: {
id: 2,
title: "Hello world"
},
members: [{name: "a", id: 2}]
} and the schema I used is the following: let schema = schemas({
new_chat: {
createdBy: bits(32),
id: bits(32),
posting: {
id: bits(32),
title: string
},
members: array({name: string, id: bits(32)})
}
}) But this gives me varInt max exceeded error. I tried to wrap that nested posting object in new PackBytes like this let schema = schemas({
new_chat: {
// other stuff
posting: new PackBytes({
id: bits(32),
title: string
})
}
}) Getting same error as above. Do you know how to write schema for objects like this? :) Thank you |
Beta Was this translation helpful? Give feedback.
-
👋 Welcome!
We’re using Discussions as a place to connect with other members of our community. We hope that you:
build together 💪.
To get started, comment below with an introduction of yourself and tell us about what you do with this community.
Beta Was this translation helpful? Give feedback.
All reactions