Skip to content

Easily encode / decode strings as null-terminated C strings.

License

Notifications You must be signed in to change notification settings

ExodusMovement/varstruct-cstring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

varstruct-cstring

npm Build Status JavaScript standard style

Easily encode / decode strings as C 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-cstring

Example

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

About

Easily encode / decode strings as null-terminated C strings.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •