Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/exodusmovement/varstruct-cstring
Easily encode / decode strings as null-terminated C strings.
https://github.com/exodusmovement/varstruct-cstring
Last synced: 8 days 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 (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-05-12T23:08:28.000Z (over 1 year ago)
- Last Synced: 2024-04-24T20:13:28.566Z (7 months 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
=================[![npm](https://img.shields.io/npm/v/varstruct-cstring.svg?style=flat-square)](https://www.npmjs.com/package/varstruct-cstring)
[![Build Status](https://img.shields.io/github/workflow/status/ExodusMovement/varstruct-cstring/CI/master?style=flat-square)](https://github.com/ExodusMovement/varstruct-cstring/actions?query=branch%3Amaster)
[![JavaScript standard style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](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