Skip to main content

Built and signed on GitHub Actions

TypeScript implementation of SLIP (Serial Line Internet Protocol)

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
a year ago (1.3.0)

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Deno-PLC / SLIP

TypeScript implementation of SLIP (Serial Line Internet Protocol)

Installation

Use JSR: JSR

Usage

Encoder

import { encodeSLIP } from "@deno-plc/slip";

const myData = new Uint8Array(/* ... */);

const myEncodedData = encodeSLIP(myData);

Decoder

import { SLIPDecoder } from "@deno-plc/slip";

const decoder = new SLIPDecoder();

const recvData = new Uint8Array(/* ... */);

for (const packet of decoder.decode(recvData)) {
    // ...
}

Note that the SLIPDecoder must be instantiated in order to handle fragmented packets (which is the purpose of SLIP)

Streams

You can also pipe your data through the provided transform streams.

import { SLIPEncoderStream, SLIPDecoderStream } from "@deno-plc/slip";

/* ... */.pipeThrough(new SLIPEncoderStream()).pipeTo(/* ... */);

/* ... */.pipeThrough(new SLIPDecoderStream()).pipeTo(/* ... */);

Encoder options

const options = {
    // When enabled an 0xc0 (SLIP.END) is inserted at the frame start.
    terminateStart: true,
};
encodeSLIP(myData, options);
// or
new SLIPEncoderStream(options);

Decoder options

const decoder = new SLIPDecoder();
// if you are using the stream decoder, use `SLIPDecoderStream.decoder`

// Default value should be fine for most use cases.
// In case you have alternating big and small packets you
// might want to set this to the size of the biggest packets
// in order to prevent unnecessary memory allocations
decoder.max_carry_oversize = 200;

// When enabled (default), empty packets are ignored
decoder.ignore_empty_packets = false;

0xC0 frame start?

If you are using RS232 or a similar transport medium, you should send an empty packet (only contains the 0xC0 termination code) before doing anything useful in order to terminate any previously disrupted transmissions. On such raw transport layers you might also wish to add some kind of validation (for example a CRC8 checksum). Although supported (SLIPEncoderOptions.terminateStart), adding a 0xC0 to the beginning of every frame is not required. If you do so (or the software at the other end) make sure to not set the SLIPDecoder.ignore_empty_packets to false because additional termination codes effectively emit empty frames.

License (LGPL-2.1-or-later)

(C) 2023 - 2024 Hans Schallmoser

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or see https://www.gnu.org/licenses/

Built and signed on
GitHub Actions
View transparency log

Add Package

deno add jsr:@deno-plc/slip

Import symbol

import * as slip from "@deno-plc/slip";

---- OR ----

Import directly with a jsr specifier

import * as slip from "jsr:@deno-plc/slip";

Add Package

npx jsr add @deno-plc/slip

Import symbol

import * as slip from "@deno-plc/slip";

Add Package

yarn dlx jsr add @deno-plc/slip

Import symbol

import * as slip from "@deno-plc/slip";

Add Package

pnpm dlx jsr add @deno-plc/slip

Import symbol

import * as slip from "@deno-plc/slip";

Add Package

bunx jsr add @deno-plc/slip

Import symbol

import * as slip from "@deno-plc/slip";