1.1.3 • Published 5 months ago

dataproto v1.1.3

Weekly downloads
-
License
GPL3
Repository
-
Last release
5 months ago

DataReader, DataWriter

Read from and write to a data buffer, with static typing

import { DataReader, DataWriter } from 'dataproto'

const writer = new DataWriter()

writer.int(123)
writer.string('Hello world!')

const buffer = writer.build() // Uint8Array(17) [0, 0, 0, 123, 12, ...]

const reader = new DataReader(buffer)

console.assert(reader.int() == 123)
console.assert(reader.string() == 'Hello World!')

Schemas

This is meant for situations where the type to be written cannot be known ahead of time. For performance reasons, don't use this unless you have to.

import { DataReader, DataWriter } from 'dataproto'

const Schema = {a: String, b: [Int, 3]}

const writer = new DataWriter()

writer.write(Schema, {a: 'Hello', b: [1, 2, 3]})

// Save to a file
fs.writeFileSync('./someObject.dat', writer.build())

// Read file again
const reader = new DataReader(fs.readFileSync('./someObject.dat'))

console.log(reader.read(Schema)) // {a: 'Hello', b: [1, 2, 3]}
1.1.3

5 months ago

1.1.2

5 months ago

1.1.1

7 months ago

1.1.0

7 months ago

1.0.9

7 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

12 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago