protobuf_bytes
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i protobuf_bytes

Weekly Downloads

2

Version

1.0.1

License

BSD-3-Clause

Unpacked Size

21.5 kB

Total Files

5

Last publish

Collaborators

  • chokobole