Expand description
Networking — custom packets as raw bytes over named channels.
Yog never puts NBT on the wire: a packet payload is just Vec<u8>, so mod
authors serialize with whatever is fastest for them (bincode, protobuf,
FlatBuffers, plain bytes). NBT is only ever built when something must be
handed to the game itself.
For ergonomic typed packets, use the packet! macro:
use yog_network::{packet, Packet};
packet! {
pub struct TeleportPacket {
x: f64,
y: f64,
z: f64,
player: String,
}
}
let pkt = TeleportPacket { x: 0.0, y: 64.0, z: 0.0, player: "Steve".into() };
let bytes = pkt.encode();
let decoded = TeleportPacket::decode(&bytes).unwrap();
assert_eq!(decoded.player, "Steve");Macros§
- packet
- Declare a typed packet struct whose fields are automatically encoded/decoded.
Structs§
- Packet
Event - A packet received on a channel.
Traits§
- Packet
- A typed packet that can be encoded to / decoded from a raw byte buffer.
- Packet
Field - Encode/decode a single field to/from a byte buffer.