Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@emiw/redstone-protocol
Advanced tools
The protocol and parser the worker-client communication in redstone
import { encode, decode, createParser } from '@emiw/redstone-protocol';
// There are two sides to this module, the lower level encode/decode, and the higher level Parser class-ish.
// Encode/Decode
// Encoding
// IMPORTANT: `meta` must be JSON serializable, and data must be a buffer!
const encoded = encode({ state: 5, foo: 'bar' }, new Buffer('foo bar baz')); // encode(meta, data)
console.log(encoded); // "%7B%22state%22%3A5%2C%22foo%22%3A%22bar%22%7D:Zm9vIGJhciBiYXo=;"
// Decoding
const decoded = decode(encoded);
console.log(decoded); // "{ meta: { state: 5, foo: 'bar' }, data: <Buffer 66 6f 6f 20 62 61 72 20 62 61 7a> }"
console.log(decoded.data.toString('utf8'); // "foo bar baz"
// See below for more on the actual protocol.
// Parser
// The parser exists as a way to abstract away the process of storing chunks as the come in from a socket, extracting
// the packets, and parsing them.
const socket = getNetSocketSomehow();
const parser = createParser();
socket.on('data', parser.addChunk);
// WARNING: All of these events will be fired for every packet.
parser.on('packet', (packet) => {
// packet = { meta: ..., data: ... }
});
parser.on('meta', (meta) => {
// meta = ...
});
parser.on('data', (data) => {
// data = Buffer(...)
});
socket.write(encode({ foo: 'bar' }));
// There are a few abstractions for dealing with sockets. To use them, just pass in a socket to `createParser`:
const parser = createParser(socket); // This automatically does `socket.on('data', parser.addChunk)`
parser.write(meta, data); // same as parser.write(encode(meta, data));
The actual protocol has hastily implemented by @ariporad, and it could certainly be implemented better. But here's how it's implemented as of now:
There are three terms you need to know:
encodeURIComponent(JSON.stringify(meta))
).Packets are in the format: meta:data;
Here's an example packet (encode({ foo: 'bar' }, new Buffer('foo'))
)
%7B%22foo%22%3A%22bar%22%7D:Zm9v;
^^^^^^^^^^ Meta ^^^^^^^^^^^ ^^^^ <- Data
Here's a "null" packet:
:;
For ideas/discussion about improving the protocol, see the wiki page.
FAQs
The protocol and parser the worker-client communication in redstone
The npm package @emiw/redstone-protocol receives a total of 0 weekly downloads. As such, @emiw/redstone-protocol popularity was classified as not popular.
We found that @emiw/redstone-protocol demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.