Skip to main content
Module

x/byte_type/mod.ts>UnsizedType

😋 A small helper module for working with different raw types in javascript
Latest
class UnsizedType
implements Unsized<T>
Re-export
Abstract
import { UnsizedType } from "https://deno.land/x/byte_type@0.4.0/mod.ts";

UnsizedType<T> is one of the two base classes for implementing a codec.

This is the most common used class for when you do not know the size of your struct.

Constructors

new
UnsizedType(byteAlignment: number)

Methods

protected
alignOffset(options: Options)

Align the offset of Options.byteOffset to the nearest integer divisable by UnsizedType<T>.byteAlignment

protected
incrementOffset(options: Options, byteSize: number)

Increment offset by the provided byteSize

read(dt: DataView, options?: Options): T

Read a aligned value from the provided buffer and optional byte offset

Implementors be aware

  • This is a function that is automatically implemented but may not be correct all the time.
  • This function only works in a vacuum. This means that it will only work on single types.
  • Composable types may not give the correct result and need to be written from scratch.
abstract
readPacked(dt: DataView, options?: Options): T

Read a value from the provided buffer while consuming as little bytes as possible. This method is used for data over the network or when reading memory that may not be aligned

Implementors be aware!

  • This method is the base functionality of Unsized<T>.read() if that method is not overridden.
  • This method does not automatically offset or align the Options.byteOffset. You need to do this yourself.
write(
value: T,
options?: Options,
): void

Write a value into the provided buffer at a optional offset that is automatically aligned

Implementors be aware

  • This is a function that is automatically implemented but may not be correct all the time.
  • This function only works in a vacuum. This means that it will only work on single types.
  • Composable types may not give the correct result and need to be written from scratch.
abstract
writePacked(
value: T,
options?: Options,
): void

write a value into the provided buffer while consuming as little bytes as possible. This method is used for data over the network or when writing memory that may not be aligned

Implementors be aware!

  • This method is the base functionality of Unsized<T>.write() if it's not implemented
  • This method does not automatically offset or align the Options.byteOffset. You need to do this yourself