-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unslab announcer record + use unslabEncode helper (#192)
* Unslab announcer record * Use encodeUnslab helper
- Loading branch information
Showing
3 changed files
with
21 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const b4a = require('b4a') | ||
const cenc = require('compact-encoding') | ||
|
||
function encodeUnslab (enc, m) { | ||
// Faster than unslab(c.encode(enc, data)) because it avoids the mem copy. | ||
// Makes sense to put in compact-encoding when we need it in other modules too | ||
const state = cenc.state() | ||
enc.preencode(state, m) | ||
state.buffer = b4a.allocUnsafeSlow(state.end) | ||
enc.encode(state, m) | ||
return state.buffer | ||
} | ||
|
||
module.exports = { | ||
encodeUnslab | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters