Last active
November 21, 2019 10:20
-
-
Save Igosuki/74c44f6788f17283bffabf5fede64b1e to your computer and use it in GitHub Desktop.
Reading NodeJS JSON encoded buffers in Python.
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
const j = '{"type":"Buffer","data":[93,204,151,170,0,0,194,155,10,119,139,1,10,13,41,43]}' | |
const buffer = Buffer.from(JSON.parse(j).data) | |
console.log(JSON.stringify(buffer)); // verify that a buffer is stringified as the string above by default | |
console.log('buffer string value : ' + buffer.toString('hex')) // concat with str | |
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
from struct import * | |
import binascii | |
import json | |
json_str = '{"type":"Buffer","data":[93,204,151,170,0,0,194,155,10,119,139,1,10,13,41,43]}' | |
a = bytearray(json.loads(json_str)['data']) | |
print(binascii.hexlify(bytearray(a))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment