pub struct TransportMsgHeader {
pub version: u8,
pub encrypt: bool,
pub route: RouteRule,
pub ttl: u8,
pub feature: u8,
pub meta: u8,
pub from_node: Option<u32>,
}Expand description
Fixed Header Fields
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|V=0|E|N| R | TTL | Feature | Meta |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Route destination (Opt) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FromNodeId (Opt) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+In there
-
Version (V) : 2 bits (now is 0)
-
Encrypt (E): 1 bits, If this bit is set, this msg should be encrypted
-
From Node (N) : 1 bits, If this bit is set, from node_id will occupy 32 bits in header
-
Route Type (R): 4 bits
- 0: Direct : which node received this msg will handle it, no route destination
- 1: ToNode : which node received this msg will route it to node_id
- 2: ToService : which node received this msg will route it to service meta
- 3: ToKey : which node received this msg will route it to key
- .. Not used
-
Ttl (TTL): 8 bits
-
Feature Id: 8 bits
-
Route destination (Route Destination): 32 bits (if R is not Direct)
- If route type is ToNode, this field is 32bit node_id
- If route type is ToService, this field is 32bit service meta
- If route type is ToKey, this field is 32bit key
-
From Node Id: 32 bits (optional if N bit is set)
Fields§
§version: u8§encrypt: bool§route: RouteRule§ttl: u8§feature: u8§meta: u8§from_node: Option<u32>Which can be anonymous or specific node
Implementations§
Source§impl TransportMsgHeader
impl TransportMsgHeader
pub fn is_secure(first_byte: u8) -> bool
Sourcepub fn new() -> TransportMsgHeader
pub fn new() -> TransportMsgHeader
Builds a message with the given service_id, route rule.
pub fn build(feature: u8, meta: u8, route: RouteRule) -> TransportMsgHeader
Sourcepub fn set_ttl(self, ttl: u8) -> TransportMsgHeader
pub fn set_ttl(self, ttl: u8) -> TransportMsgHeader
Set ttl
Sourcepub fn set_encrypt(self, encrypt: bool) -> TransportMsgHeader
pub fn set_encrypt(self, encrypt: bool) -> TransportMsgHeader
Set secure
Sourcepub fn set_from_node(self, from_node: Option<u32>) -> TransportMsgHeader
pub fn set_from_node(self, from_node: Option<u32>) -> TransportMsgHeader
Set from node
Sourcepub fn set_feature(self, feature: u8) -> TransportMsgHeader
pub fn set_feature(self, feature: u8) -> TransportMsgHeader
Set to feature
Sourcepub fn set_meta(self, meta: u8) -> TransportMsgHeader
pub fn set_meta(self, meta: u8) -> TransportMsgHeader
Set to service_id
Sourcepub fn set_route(self, route: RouteRule) -> TransportMsgHeader
pub fn set_route(self, route: RouteRule) -> TransportMsgHeader
Set rule
Sourcepub fn to_bytes(&self, output: &mut [u8]) -> Option<usize>
pub fn to_bytes(&self, output: &mut [u8]) -> Option<usize>
Converts the message to a byte representation and appends it to the given output vector.
§Arguments
output- A mutable vector of bytes to append the serialized message to.
§Returns
An Option containing the number of bytes written if the output vector was large enough, or None if the output vector was too small.
Sourcepub fn rewrite_ttl(buf: &mut [u8], new_ttl: u8) -> Option<()>
pub fn rewrite_ttl(buf: &mut [u8], new_ttl: u8) -> Option<()>
Rewrite the ttl in the given buffer with the new ttl.
§Arguments
buf- A mutable slice of bytes representing the buffer to rewrite the ttl in.new_ttl- The new ttl to use for rewriting the ttl.
§Returns
An Option containing () if the ttl was successfully rewritten,
or None if the buffer is too small to hold the new ttl.
Sourcepub fn decrease_ttl(buf: &mut [u8]) -> bool
pub fn decrease_ttl(buf: &mut [u8]) -> bool
Sourcepub fn serialize_size(&self) -> usize
pub fn serialize_size(&self) -> usize
Returns the size of the serialized message.
Trait Implementations§
Source§impl Clone for TransportMsgHeader
impl Clone for TransportMsgHeader
Source§fn clone(&self) -> TransportMsgHeader
fn clone(&self) -> TransportMsgHeader
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more