0.0.1 β€’ Published 9 months ago

@wecandobetter/binay-buffer v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Binary Buffer πŸ’Ύ

Binary Buffer is a versatile TypeScript library that provides tools for creating, manipulating, and serializing binary data buffers. It simplifies the process of working with binary data by offering an intuitive API for defining data structures, serializing data, and managing byte sequences.

Features πŸš€

  • βš™οΈ Flexible Type System: Define custom data types using a simple and extensible API.
  • πŸ”„ Serialization and Deserialization: Serialize and deserialize complex data structures with ease.
  • πŸ“š Easy-to-Use API: Create, read, and manipulate binary data using an intuitive and well-documented API.
  • ⚑ High Performance: Optimized for speed, making it suitable for performance-critical applications.
  • πŸ“œ MIT Licensed: Use it freely in both open-source and commercial projects.

Installation πŸ“¦

To install the Binary Buffer library, use npm:

npm install @wecandobetter/binary-buffer

Usage Example 🌟

import { BufferBuilder } from "@wecandobetter/binary-buffer";
import { string, uint8 } from "@wecandobetter/binary-buffer/dist/types.js";

// Create a BufferBuilder instance
const builder = new BufferBuilder();

// Register built-in types
builder.registerType(uint8);
builder.registerType(string);

// Define your data structure using the built-in types
const descriptor = {
  age: "uint8",
  name: "string",
};

// Create a builder function
const build = builder.createBuilder(descriptor);

// Build the binary buffer using the builder function
const { buffer, ops, copy } = build({
  age: 42,
  name: "John Doe",
});

// Get the values
ops.age.get(); // 42
ops.name.get(); // "John Doe"

// Set the values
ops.age.set(43);
ops.name.set("Jane Doe");

// Copy the buffer
const copiedBuffer = copy();

See the example and unit tests for more usage examples.

Built-in Types

Type KeyDescriptionByte LengthRangeNotes
uint8Unsigned 8-bit integer10 to 255
uint16Unsigned 16-bit integer20 to 65535
uint32Unsigned 32-bit integer40 to 4294967295
int8Signed 8-bit integer1-128 to 127
int16Signed 16-bit integer2-32768 to 32767
int32Signed 32-bit integer4-2147483648 to 2147483647
float3232-bit floating point number41.401298464324817e-45 to 3.4028234663852886e+38
float6464-bit floating point number85e-324 to 1.7976931348623157e+308
booleanBoolean value1true or false
stringUnicode stringVariableVariableLength prefix (2 bytes)
T[]Array of values of type TVariableVariableLength prefix (4 bytes)

Roadmap πŸ—ΊοΈ

  • Support browser, Deno, and Bun environments
  • Some kind of benchmarking

Contributing 🀝

Contributions, issues, and feature requests are welcome! For major changes, please open an issue first to discuss what you would like to change.

If you find Binary Buffer helpful, consider starring the repository ⭐ and contributing to its development. Feel free to report issues or submit pull requests to help us make it even better!

License πŸ“œ

Binary Buffer is licensed under the MIT License.

0.0.1

9 months ago