Initial commit

This commit is contained in:
Alex Emmet 2026-06-20 01:55:31 +02:00
commit 0bbcab5727
24 changed files with 1416 additions and 0 deletions

6
type-map/Cargo.toml Normal file
View file

@ -0,0 +1,6 @@
[package]
name = "type-map"
version = "0.1.0"
edition = "2024"
[dependencies]

28
type-map/src/lib.rs Normal file
View file

@ -0,0 +1,28 @@
use std::collections::HashMap;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CommTypeId(pub u8);
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct DataTypeId(pub u16);
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Version(pub u16);
/// A single protocol version's type dictionary.
/// Compiled into the client, or loaded by the host via the registry.
#[derive(Clone, Debug)]
pub struct TypeMap {
pub version: Version,
pub comm_types: HashMap<String, u8>,
pub data_types: HashMap<String, u16>,
}
impl TypeMap {
pub fn comm_id(&self, name: &str) -> Option<u8> {
self.comm_types.get(name).copied()
}
pub fn data_id(&self, name: &str) -> Option<u16> {
self.data_types.get(name).copied()
}
}