https://github.com/exodusmovement/varstruct-cstring
Easily encode / decode strings as null-terminated C strings.
https://github.com/exodusmovement/varstruct-cstring
Last synced: 3 months ago
JSON representation
Easily encode / decode strings as null-terminated C strings.
- Host: GitHub
- URL: https://github.com/exodusmovement/varstruct-cstring
- Owner: ExodusMovement
- License: mit
- Created: 2016-10-17T19:50:06.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-05-12T23:08:28.000Z (about 2 years ago)
- Last Synced: 2024-04-24T20:13:28.566Z (about 1 year ago)
- Language: JavaScript
- Size: 83 KB
- Stars: 2
- Watchers: 29
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
varstruct-cstring
=================[](https://www.npmjs.com/package/varstruct-cstring)
[](https://github.com/ExodusMovement/varstruct-cstring/actions?query=branch%3Amaster)
[](http://standardjs.com)Easily encode / decode strings as [C strings](https://en.wikibooks.org/wiki/C_Programming/Strings), that is, null-terminated `\0`.
This is useful to retain compatibility with data structures written in other languages.Install
-------npm i --save varstruct #must install varstruct first
npm i --save varstruct-cstringExample
-------```js
const vstruct = require('varstruct')
const cstring = require('varstruct-cstring')const strings = vstruct([
{ name: 'first', type: cstring(16) },
{ name: 'last', type: cstring(16) }
])const data = {
first: 'Satoshi',
last: 'Nakamoto'
}const buffer = strings.encode(data)
console.log(buffer.toString('hex')) // => '5361746f7368690000000000000000004e616b616d6f746f0000000000000000'const decodedData = strings.decode(buffer)
console.dir(decodedData) // => { first: 'Satoshi', last: 'Nakamoto' }
```License
-------MIT Copyright Exodus Movement, Inc. 2016