protobuf_bytes
v1.0.1
Published
JS implementation of protobuf_bytes
Downloads
1
Readme
Protobuf Bytes for nodeJS
Contents
Install
To use protobuf_bytes, install package via npm install.
npm install protobuf_bytes
Get protobuf
The protobuf file is located here.
Examples
const { Bytes } = require('protobuf_bytes');
function fillArrayBuffer(buffer, offset, step, func) {
const dataView = new DataView(buffer);
for (let i = offset; i < buffer.byteLength; i += step) {
func(dataView, i);
}
}
const buffer = new ArrayBuffer(12);
let i = 0;
fillArrayBuffer(buffer, 0, 1, (dataView, idx) => {
dataView.setUint8(idx, i);
i++;
});
const data = new Uint8Array(buffer);
const b = new Bytes({
type: BytesType.BYTES_TYPE_8U_C1,
bigendian: false,
data: data
});
for (let i = 0; i < b.length(); i++) {
console.log(b.dataAt(i));
}
// [ 0 ]
// [ 1 ]
// [ 2 ]
// [ 3 ]
// [ 4 ]
// [ 5 ]
// [ 6 ]
// [ 7 ]
// [ 8 ]
// [ 9 ]
// [ 10 ]
// [ 11 ]
const b2 = new Bytes({
type: BytesType.BYTES_TYPE_8U_C3,
data: data
});
for (let i = 0; i < b2.length(); i++) {
console.log(b2.dataAt(i));
}
// [ 0, 1, 2 ]
// [ 3, 4, 5 ]
// [ 6, 7, 8 ]
// [ 9, 10, 11 ]
APIs
Please reads docs/apis.md.