Skip to content

Commit

Permalink
docs: add exemple of how encode decode using hex (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
leandroandrade authored Dec 8, 2022
1 parent 5cfdf2d commit a690317
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ var msgpack = require('msgpack5')() // namespace our extensions

msgpack.register(0x42, MyType, mytipeEncode, mytipeDecode)

console.log(encode({ 'hello': 'world' }).toString('hex'))
const hex = encode({ 'hello': 'world' }).toString('hex')
console.log(hex)
// 81a568656c6c6fa5776f726c64
const obj = decode(Buffer.from(hex, 'hex'))
console.log(obj)
// { hello: 'world' }

console.log(decode(encode({ 'hello': 'world' })))
// { hello: 'world' }
console.log(encode(a).toString('hex'))
Expand Down
7 changes: 6 additions & 1 deletion example.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ const decode = msgpack.decode

msgpack.register(0x42, MyType, mytipeEncode, mytipeDecode)

console.log(encode({ hello: 'world' }).toString('hex'))
const hex = encode({ hello: 'world' }).toString('hex')
console.log(hex)
// 81a568656c6c6fa5776f726c64
const obj = decode(Buffer.from(hex, 'hex'))
console.log(obj)
// { hello: 'world' }

console.log(decode(encode({ hello: 'world' })))
// { hello: 'world' }
console.log(encode(a).toString('hex'))
Expand Down

0 comments on commit a690317

Please sign in to comment.