Skip to content

Commit

Permalink
docs: minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
hansSchall committed May 2, 2024
1 parent f461afd commit 5961774
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Deno-PLC / SLIP

[![JSR Scope](https://jsr.io/badges/@deno-plc)](https://jsr.io/@deno-plc)
# [Deno-PLC](https://github.com/deno-plc) / [SLIP](https://jsr.io/@deno-plc/slip)

TypeScript implementation of
[SLIP (Serial Line Internet Protocol)](https://en.wikipedia.org/wiki/Serial_Line_Internet_Protocol)

## Installation

Use JSR:
[![JSR](https://jsr.io/badges/@deno-plc/slip)](https://jsr.io/@deno-plc/slip)

## Usage
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deno-plc/slip",
"version": "1.2.0",
"version": "1.2.1",
"exports": "./mod.ts",
"fmt": {
"indentWidth": 4
Expand Down
10 changes: 8 additions & 2 deletions src/slip.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export enum SLIP {
ESC_ESC = 221,
}

/**
* SLIP encoder
*/
export function encodeSLIP(chunk: Uint8Array): Uint8Array {
if (chunk.indexOf(SLIP.END) === -1 && chunk.indexOf(SLIP.ESC) === -1) {
// fast forward
Expand Down Expand Up @@ -67,8 +70,6 @@ export function encodeSLIP(chunk: Uint8Array): Uint8Array {
* SLIP decoder (needs to be instantiated to handle fragmented packets)
*/
export class SLIPDecoder {
constructor() {
}
/**
* Default value should be fine for most use cases.
* In case you have alternating big and small packets you
Expand All @@ -80,6 +81,11 @@ export class SLIPDecoder {
#carry = new Uint8Array(0);
#carrySize = 0;
#esc = false;

/**
* Call this for every chunk of data you receive
* @returns Generator of the packets that were encoded within the chunk and previously received incomplete ones
*/
public *decode(chunk: Uint8Array): Generator<Uint8Array> {
// maximum amount of data that might be be cached
// = the amount that is carried + the new data
Expand Down

0 comments on commit 5961774

Please sign in to comment.