1.1.3 • Published 2 years ago

dataproto v1.1.3

Weekly downloads
-
License
GPL3
Repository
-
Last release
2 years 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

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago