[go: up one dir, main page]

File: cbordecode.py

package info (click to toggle)
duktape 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 20,496 kB
  • sloc: ansic: 203,676; python: 5,856; makefile: 476; cpp: 205
file content (24 lines) | stat: -rw-r--r-- 506 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python2

def main():
    import sys
    import cbor
    import json

    data = sys.stdin.read()
    print('LEN: %d' % len(data))
    sys.stdout.flush()
    print('HEX: ' + data.encode('hex'))
    sys.stdout.flush()
    doc = cbor.loads(data)
    print('REPR: ' + repr(doc))
    sys.stdout.flush()
    try:
        print('JSON: ' + json.dumps(doc))
        sys.stdout.flush()
    except:
        print('JSON: cannot encode')
        sys.stdout.flush()

if __name__ == '__main__':
    main()