pub enum MessageType {
Null,
Get,
Reply,
Error,
Shutdown,
Unknown,
}
Expand description
A listing of all the different kinds of message types that a Message can be composed of.
§Description
The Message Type variants are put at the beginning of a network message, and determine what kind of message the network message will be. Each variant of the MessageType enum maps to a u8 integer, a MessageType variant can also be created from a u8 integer.
§u8 Variant Mappings
Null == 0
Get == 1
Reply == 2
Error == 3
Shutdown == 4
Unknown >= 5
§Examples
use network_audio_protocol::MessageType;
let message_type: MessageType = MessageType::from(1);
assert_eq!(message_type, MessageType::Get);
assert_eq!(message_type.to_string(), String::from("Get"));
println!("Message Type: {}, maps to: {}", message_type, message_type.as_u8());
The above code creates a MessageType
variant from the u8 integer 1
, confirms that it is
equal to MessageType::Get
, turns the MessageType
into a String
, and compares it to
another string value, and finally prints the MessageType
and its corresponding u8 value
Variants§
Null
The Null
variant is used to create a null, or empty message.
Get
The Get
variant is used to create a message that contains a request within it.
Reply
The Reply
variant is used to create a message that contains data to fufill a Get
request.
Error
The Error
variant is used to create a message indicating an error occurred.
Shutdown
The Shutdown
variant is used to create a shutdown / termination message.
Unknown
The Unkown
variant is not used to make any messages, but rather to represent a message of
an unknown type.