| Crates.io | byte-transcoder |
| lib.rs | byte-transcoder |
| version | 0.0.6 |
| created_at | 2024-09-25 06:02:08.313403+00 |
| updated_at | 2025-04-02 06:16:26.220002+00 |
| description | A Rust+Typescript library to transcode higher-level data types to/from bytes. |
| homepage | https://www.toddgriffin.me/ |
| repository | https://github.com/goddtriffin/byte-transcoder-rs |
| max_upload_size | |
| id | 1386024 |
| size | 27,850 |
A Rust+Typescript library to transcode higher-level data types to/from bytes.
Supported data types:
u8/u16/u32/u64i8/i16/i32/i64stringuuidWraps a byte slice ([u8] in Rust, Uint8Array in Typescript) and exposes
easy-to-use retrieval functions for primitives.
Can manually specify endianness.
Typescript only.
Helps write primitives to a Uint8Array.
Can manually specify endianness.
Read examples/, tests/, and src-ts/**/*.test.ts for more examples!
type Payload = { gameId: string; joinCode: string };
const bytes = new Uint8Array([
// <your binary data>
]);
const byteReader = new ByteReader(bytes);
const payload: Payload = {
gameId: byteReader.readUuid(),
joinCode: byteReader.readString()
};
struct Payload {
game_id: Uuid,
join_code: String,
}
let bytes: Vec<u8> = vec![
// <your binary data>
];
let mut byte_reader = ByteReader::new(bytes);
let payload = Payload {
game_id: byte_reader.read_uuid()?,
join_code: byte_reader.read_string()?,
}
type Payload = { gameId: string; joinCode: string };
const payload: Payload = {
gameId: "24399a6c-c4a9-4053-9b2d-4199107fb567",
joinCode: "12345"
};
const byteWriter = new ByteWriter();
byteWriter.writeUuid(payload.gameId);
byteWriter.writeString(payload.joinCode);
const bytes: Uint8Array = byteWriter.getBytes();
There is no need for a Rust version of ByteWriter as integers types already have .to_le_bytes() and .to_be_bytes() (and .to_ne_bytes()).
Project is under active maintenance - even if there are no recent commits! Please submit an issue / bug request if the library needs updating for any reason!
I have only implemented the exact functions I need for the projects that I'm currently building. If there is anything missing that you would like to see implemented, please submit a PR! Or if you're lazy, submit a Feature Request and I'll implement it lol
make lintmake testmake fixMade with 🤬 and 🥲 by Todd Everett Griffin.