Function airmash_protocol::to_bytes [] [src]

pub fn to_bytes<T>(value: &T) -> Result<Vec<u8>, Error> where
    T: Serialize, 

Serializes a struct to a byte vector, returning an Error when the struct cannot be serialized.

Example

// Create a packet to be sent to the server
let packet = ClientPacket::TeamChat(TeamChat {
    text: "The enemy has our flag!".to_string()
});
 
// Serialize the packet
let bytes = to_bytes(&packet).unwrap();
 
// Send packet to server here...