README
transport-protocol
This protocol describes communication between native applications and browsers.
The project is platform-independent, so it can be used in Node.js, Deno, and web browser environments.
Install
npm install --save @fructo/transport-protocol
Protocol
Message structure:
- Header [4 bytes] - Contains message length in selected byte order. The length does not include the header.
- Body [N bytes]
Encoding
import { MessagesEncoder } from '@fructo/transport-protocol';
const encoder = new MessagesEncoder();
const encodedMessage = encoder.encode({ header: 'my-header' });
Decoding
import { MessagesDecoder } from '@fructo/transport-protocol';
const decoder = new MessagesDecoder();
for (const decodedMessage of decoder.decode(partialChunk)) {
}
Endianness
By default, MessagesEncoder
and MessagesDecoder
use native byte order, but it is possible to force them to use a specific order:
const encoder = new MessagesEncoder({ endianness: 'little-endian' });
const decoder = new MessagesDecoder({ endianness: 'big-endian' });