@serialport/parser-slip-encoder
Advanced tools
Comparing version 9.0.7 to 9.1.0
@@ -6,2 +6,18 @@ # Change Log | ||
# [9.1.0](https://github.com/serialport/node-serialport/compare/v9.0.8...v9.1.0) (2021-05-28) | ||
### Bug Fixes | ||
* parser-slip-encoder had a breaking change ([#2254](https://github.com/serialport/node-serialport/issues/2254)) ([c89b600](https://github.com/serialport/node-serialport/commit/c89b6004308ede97c10e18f1b2fb4d40041ff752)) | ||
### Features | ||
* Add slip decoder to parser-slip-encoder ([#2196](https://github.com/serialport/node-serialport/issues/2196)) ([85297bc](https://github.com/serialport/node-serialport/commit/85297bc3d13cdc3beeee52e5badb0016ee6f24f5)) | ||
## [9.0.7](https://github.com/serialport/node-serialport/compare/v9.0.6...v9.0.7) (2021-02-22) | ||
@@ -8,0 +24,0 @@ |
@@ -1,73 +0,6 @@ | ||
const { Transform } = require('stream') | ||
const SlipEncoder = require('./encoder') | ||
const SlipDecoder = require('./decoder') | ||
const END = 0xc0 | ||
const ESC = 0xdb | ||
const ESC_END = 0xdc | ||
const ESC_ESC = 0xdd | ||
/** | ||
* A transform stream that emits SLIP-encoded data for each incoming packet. | ||
* @extends Transform | ||
* @summary Runs in O(n) time, adding a 0xC0 character at the end of each | ||
* received packet and escaping characters, according to RFC 1055. Adds another | ||
* 0xC0 character at the beginning if the `bluetoothQuirk` option is truthy (as | ||
* per the Bluetooth Core Specification 4.0, Volume 4, Part D, Chapter 3 "SLIP Layer"). | ||
* Runs in O(n) time. | ||
* @example | ||
// Read lines from a text file, then SLIP-encode each and send them to a serial port | ||
const SerialPort = require('serialport') | ||
const SlipEncoder = require('@serialport/parser-slip-encoder') | ||
const Readline = require('parser-readline') | ||
const fileReader = require('fs').createReadStream('/tmp/some-file.txt'); | ||
const port = new SerialPort('/dev/tty-usbserial1') | ||
const lineParser = fileReader.pipe(new Readline({ delimiter: '\r\n' })); | ||
const encoder = fileReader.pipe(new SlipEncoder({ bluetoothQuirk: false })); | ||
encoder.pipe(port); | ||
*/ | ||
class SlipEncoderParser extends Transform { | ||
constructor(options = {}) { | ||
super(options) | ||
if (options.bluetoothQuirk) { | ||
this._bluetoothQuirk = true | ||
} | ||
} | ||
_transform(chunk, encoding, cb) { | ||
const chunkLength = chunk.length | ||
if (this._bluetoothQuirk && chunkLength === 0) { | ||
// Edge case: push no data. Bluetooth-quirky SLIP parsers don't like | ||
// lots of 0xC0s together. | ||
return cb() | ||
} | ||
// Allocate memory for the worst-case scenario: all bytes are escaped, | ||
// plus start and end separators. | ||
const encoded = Buffer.alloc(chunkLength * 2 + 2) | ||
let j = 0 | ||
if (this._bluetoothQuirk) { | ||
encoded[j++] = END | ||
} | ||
for (let i = 0; i < chunkLength; i++) { | ||
let byte = chunk[i] | ||
if (byte === END) { | ||
encoded[j++] = ESC | ||
byte = ESC_END | ||
} else if (byte === ESC) { | ||
encoded[j++] = ESC | ||
byte = ESC_ESC | ||
} | ||
encoded[j++] = byte | ||
} | ||
encoded[j++] = END | ||
cb(null, encoded.slice(0, j)) | ||
} | ||
} | ||
module.exports = SlipEncoderParser | ||
module.exports = SlipEncoder | ||
module.exports.SlipEncoder = SlipEncoder | ||
module.exports.SlipDecoder = SlipDecoder |
{ | ||
"name": "@serialport/parser-slip-encoder", | ||
"main": "lib", | ||
"version": "9.0.7", | ||
"version": "9.1.0", | ||
"engines": { | ||
@@ -17,3 +17,3 @@ "node": ">=10.0.0" | ||
"funding": "https://opencollective.com/serialport/donate", | ||
"gitHead": "cdda51fef862270d03b595c84617beec9cdb18a1" | ||
"gitHead": "2cd5648c88e85d69533803ad99053c9c0e7defda" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7967
7
154
1