atl::wire
atl::wire: the binary encoding of typed network messages and saved state.
Writer
Section titled "Writer"pub struct WriterBuilds a message's bytes, collecting the game objects it refers to separately.
Methods
pub fn new() -> WriterAn empty writer.
pub fn bytes(&mut self, b: &[u8])Appends raw bytes.
pub fn u8(&mut self, v: u8)Appends one byte.
pub fn u32(&mut self, v: u32)Appends a 32-bit integer (little-endian).
pub fn varint(&mut self, mut v: u64)Appends an unsigned integer in 7-bit variable-length form.
pub fn object(&mut self, v: Value) -> usizeStores a game object and returns its index, to be written in its place.
pub fn buffer(&self) -> &[u8]The bytes written so far.
pub fn objects(&self) -> &[Value]The game objects referred to by index.
Implements Default
Reader
Section titled "Reader"pub struct Reader<'a>Reads a message's bytes. Any read past the end or invalid data marks the reader as failed instead of trapping; failed reads return zeros.
Methods
pub fn new(bytes: &'a [u8], objects: Value) -> Reader<'a>Reads bytes; objects is the payload table holding the referenced game objects.
pub fn bytes_into(&mut self, out: &mut [u8]) -> boolReads out.len() raw bytes into out.
pub fn u8(&mut self) -> u8Reads one byte.
pub fn u32(&mut self) -> u32Reads a 32-bit integer.
pub fn varint(&mut self) -> u64Reads a variable-length integer.
pub fn count(&mut self) -> usizeReads an element count, failing if it's implausibly large for the remaining data.
pub fn view(&mut self, n: usize) -> &'a [u8]Reads n bytes as a slice of the input.
pub fn object(&mut self) -> ValueReads a game object written by Writer::object.
pub fn fail(&mut self)Marks the reader as failed.
pub fn ok(&self) -> boolTrue while every read has succeeded.
pub fn done(&self) -> boolTrue when everything succeeded and the whole input was consumed.
pub fn remaining(&self) -> usizeBytes left to read.
TypeInfo
Section titled "TypeInfo"pub struct TypeInfoA registered message type: its name hash, layout hash and printable name.
Fields
pub name: u32pub schema: u32pub display: &'static strImplements Clone, Copy, Debug
Packet
Section titled "Packet"pub struct PacketA decoded payload: its kind, its bytes, and the table holding its game objects.
Fields
pub kind: PacketKindpub bytes: Vec<u8>pub objects: ValueAssembler
Section titled "Assembler"pub struct AssemblerReassembles split messages. Packets from one sender arrive in order, so a new transfer from a sender abandons that sender's unfinished one.
Methods
pub fn add(&mut self, sender: &Value, chunk: &[u8], out: &mut Vec<u8>) -> AssembleResultAdds a chunk from sender. On Complete, out holds the whole message's bytes.
Implements Default
PacketKind
Section titled "PacketKind"pub enum PacketKindWhat a received payload is.
Variants
NoneWholeChunk
Implements Clone, Copy, Debug, Eq, PartialEq
AssembleResult
Section titled "AssembleResult"pub enum AssembleResultOutcome of adding a chunk.
Variants
PendingCompleteError
Implements Clone, Copy, Debug, Eq, PartialEq
UnpackError
Section titled "UnpackError"pub enum UnpackErrorWhy unpack_as failed.
Variants
NotPackedOtherTypeOtherDefinitionMalformed
Implements Clone, Copy, Debug, Eq, PartialEq
pub trait Codec: SizedHow a type is encoded: write, read, and schema, a hash of the type's layout used to reject messages from builds with a different definition. Implement it to send your own types.
Trait items
fn write(&self, w: &mut Writer)Appends the value.
fn read(r: &mut Reader) -> SelfReads a value. On malformed input, marks the reader failed.
fn schema() -> u32A hash of the type's layout.
Message
Section titled "Message"pub trait Message: Codec + 'staticA typed message or saved state: a struct with #[derive(atl::Message)].
Functions
Section titled "Functions"pub const fn fnv(s: &str) -> u32FNV-1a hash of a string.
pub const fn fnv_from(s: &str, mut h: u32) -> u32FNV-1a hash of a string, continuing from h.
pub const fn mix(h: u32, v: u32) -> u32Combines a hash with another value.
pub fn type_name<T: ?Sized>() -> &'static strThe compiler's name for type T, e.g. "my_mod::lamp::State".
pub fn type_info<M: Message>() -> TypeInfoThe TypeInfo of message type M.
pub fn register<M: Message>() -> TypeInfoRegisters M so a receiver can name it in error messages.
pub fn find_type(name: u32) -> Option<TypeInfo>The registered type with a name hash, or None.
pub fn encode_message<M: Message>(msg: &M) -> WriterEncodes a message: the type's name hash, its layout hash, then its fields.
pub fn encoded_size<M: Message>(msg: &M) -> usizeEncoded size of a message in bytes.
pub const fn packet_count_for(encoded: usize) -> usizeHow many packets a message of encoded bytes needs.
pub fn packet_count<M: Message>(msg: &M) -> usizeHow many packets a message needs.
pub fn pack<M: Message>(msg: &M) -> ValueEncodes a message as one value regardless of size, for storage (which has no packet limit).
pub fn packets<M: Message>(msg: &M, action: &str) -> Vec<Value>Encodes a message as one or more network payloads. Messages over CHUNK_BYTES are split into chunks (CHUNK_PREFIX + transfer id, index, count, bytes); the game objects travel with the last chunk. Logs an error and returns nothing above MAX_MESSAGE_BYTES.
pub fn read_packet(payload: &Value) -> PacketRecognizes and decodes a payload in any of the supported formats.
pub fn unpack_as<M: Message>(payload: &Value) -> Result<M, UnpackError>Decodes a whole payload as message type M.
Constants
Section titled "Constants"pub const COBS: bool = !cfg!(feature = "wire-base64")True when this build sends COBS (the default) rather than base64.
pub const PREFIX: &str = if COBS { "@atl2:" } else { "@atl1:" }Prefix of a whole message / of one chunk of a split message.
pub const CHUNK_PREFIX: &str = if COBS { "@atlc:" } else { "@atlk:" }pub const SERVER_INBOX: &str = "__atl_sv"The method names the SDK receives typed messages under, on the server and client.
pub const CLIENT_INBOX: &str = "__atl_cl"pub const CHUNK_BYTES: usize = if COBS { 60000 } else { 45000 }Encoded bytes per packet, keeping each packet under NETWORK_PACKET_LIMIT once encoded.
pub const MAX_MESSAGE_BYTES: usize = 1 << 20The largest message that can be sent split into packets (1 MiB).