npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rbxts/bufferlayout

v1.0.0

Published

A simple and efficient way to manage buffers.

Downloads

4

Readme

BufferLayout

This package offers a simple and efficient way to manage buffers. It can be used to create buffer representations of certain data structurs like Vector2s, Vector3s, and CFrames. It can also be used to create custom data structures.

Features

  • Type Safety: Leveraging TypeScript for stronger typing, reducing runtime errors.
  • Data Validation: Includes methods for validating buffer data integrity, which can be disabled for performance.
  • Structured Buffers: A clean and readable way to manage buffers, ensuring efficient memory usage.

Installation

To install the package, use the following command:

npm install @rbxts/bufferlayout

Usage

Import the module and utilize the BufferLayout class to manage your data buffers.

import { BufferLayout, Primitives } from '@rbxts/bufferlayout';

// Step 1: Define your buffer layout
// For example, a layout with an Unsigned 8-bit integer and a 32-bit float
const myLayout = new BufferLayout(Primitives.U8, Primitives.F32);

// Step 2: Setting Configurations
// For example, enabling validation and setting a custom error handler
// You can also retrieve these configurations by calling `myLayout.getConfigs()`
myLayout.setConfigs({
  validation: {
    enabled: true,
    onError: (index, message) => warn(`Validation Error at index ${index}: ${message}`),
  },
});

// Step 3: Create a LayoutObject
// For example, initializing with values 255 (for U8) and 123.456 (for F32)
const myObject = myLayout.create(255, 123.456);

// Step 4: Perform read/write operations

// Write new values
myObject.write(100, 789.012);

// Read values
const [myU8Value, myF32Value] = myObject.read();

// Output the read values
print("U8 Value:", myU8Value); // Should output 100
print("F32 Value:", myF32Value); // Should output 789.012


// NOTES:

// 1. If validation is enabled, the following will throw a warning:
myObject.write(256, 789.012); // U8 value is out of range

// 2. You can access the buffer directly
const trueBuffer = myObject.buffer;

// 3. Release the buffer when done.
// This clears the buffer and returns it to the cache.
// Doing this saves performance because it does not need to be re-allocated.
myObject.release();

API Reference

BufferLayout

  • setConfigs(configs: Partial<LayoutConfigs>): Set configuration for buffer validation.
  • getConfigs(): Retrieve current configuration settings.
  • create(values: BufferLayoutTuple<T>): Create a new LayoutObject with the specified layout.

LayoutObject

  • write(values: BufferLayoutTuple<T>): Write data to the buffer.
  • read(): Read data from the buffer.
  • release(): Release the buffer, clearing and returning it to the cache.

LayoutConfigs

LayoutConfigs are configurations used in the BufferLayout class to manage buffer validation and other settings in the future.

type LayoutConfigs = {
  validation: {
	enabled: boolean;
	onError: (index: number, value: number) => void;
  };
};
  • validation
    • enabled
      • Type: boolean
      • Default: true
      • Description: Determines if validation is enabled. When true, buffer data will be checked for integrity based on the defined primitives.
    • onError
      • Type: Function (index: number, value: number) => void
      • Default: error(`Invalid value ${value} for field ${index}`)
      • Description: Callback function that is called when a validation error occurs. The function takes a string message as an argument, which describes the error.

Primitives

Primitives represent basic data types that can be used in buffer layouts. Each primitive type corresponds to a specific data type and size. String has been omitted from this package as (a) it is not a primitive type and (b) it is not a fixed-size data type. This package is designed to work with fixed-size data types.

U8

  • Description: Unsigned 8-bit integer
  • Byte Size: 1 byte
  • Value Range: [0, 255]

I8

  • Description: Signed 8-bit integer
  • Byte Size: 1 byte
  • Value Range: [-128, 127]

U16

  • Description: Unsigned 16-bit integer
  • Byte Size: 2 bytes
  • Value Range: [0, 65535]

I16

  • Description: Signed 16-bit integer
  • Byte Size: 2 bytes
  • Value Range: [-32768, 32767]

U32

  • Description: Unsigned 32-bit integer
  • Byte Size: 4 bytes
  • Value Range: [0, 4294967295]

I32

  • Description: Signed 32-bit integer
  • Byte Size: 4 bytes
  • Value Range: [-2147483648, 2147483647]

F32

  • Description: 32-bit float
  • Byte Size: 4 bytes
  • Value Range: Approximately [-3.4028235e38, 3.4028235e38]
  • Precision: ~7 decimal digits

F64

  • Description: 64-bit float
  • Byte Size: 8 bytes
  • Value Range: Approximately [-1.7976931348623157e308, 1.7976931348623157e308]
  • Precision: ~15 decimal digits