d2-datawrapper
Simple byte array reader / writer for D2
Install
npm i -S d2-datawrapper
Release Note
1.2.5
- D2 var Short & Long support
- Writer can write in existing buffer
1.1.0
- Fixed UTF reading with gived offset
- Fixed reading with gived offset
- Fixed reading values
Features
- D2 - Read/Write varInt
- D2 - Read/Write varShort
- D2 - Read/Write varLong
- D2 - Get/Set flag
- D2 - Int64
- Read/Write Bytes
- Read/Write Byte
- Read/Write Boolean
- Read/Write Char
- Read/Write Sbyte
- Read/Write Short
- Read/Write Ushort
- Read/Write Int
- Read/Write Uint
- Read/Write Long
- Read/Write Ulong
- Read/Write UTF(8) string
Test
Code
'use strict'const writer = require('d2-datawrapper/writer')const reader = require('d2-datawrapper/reader') var parse = new writer()parse.writeUTF('Hey !')parse.writeShort(2)parse.writeInt(666)parse.writeLong(1234567890)parse.writeByte(1)parse.writeUTF('End ^^') var parsed = new reader(parse.buffer) console.log(parsed.readUTF() + '\n' +parsed.readShort() + '\n' +parsed.readInt() + '\n' +parsed.readLong() + '\n' +parsed.readByte() + '\n' +parsed.readUTF())
Output
Hey !
2
666
1234567890
1
End ^^