pub struct ClientRoutingLabel {
pub encodable_data: [EncodableData; 5],
pub encoding_system: Base32,
}
Expand description
Struct containing data to encode and what encoding system to use.
Consist of 2 properties: encodable_data
and encoding_system
.
encodable_data
should be an array of 5 EncodableData items. The Default
implementation should be used for creating this struct to ensure each item
in the encodable_data
contains the proper num_bits
value.
§Examples
use amazon_cloudfront_client_routing_lib::client_routing_label::ClientRoutingLabel;
let mut client_routing_label = ClientRoutingLabel::default();
client_routing_label.encodable_data[0].value = 1; // sdk version
client_routing_label.encodable_data[1].value = 1; // is ipv6
client_routing_label.encodable_data[2].value = 9340004030419828736; // client subnet
client_routing_label.encodable_data[3].value = 48; // subnet mask
client_routing_label.encodable_data[4].value = 8517775255794402596; // cgid
Fields§
§encodable_data: [EncodableData; 5]
§encoding_system: Base32
Implementations§
Source§impl ClientRoutingLabel
impl ClientRoutingLabel
Sourcepub fn set_data(
&mut self,
client_subnet_encoding_data: ClientSubnetEncodingData,
cgid: u64,
)
pub fn set_data( &mut self, client_subnet_encoding_data: ClientSubnetEncodingData, cgid: u64, )
Sets client subnet and cgid data in ClientRoutingLabel
.
Takes in 2 parameters: client_subnet_encoding_data
and cgid
.
client_subnet_encoding_data
should be a ClientSubnetEncodingData
struct and has the formatted values for is_ipv6
, client_subnet
, and
subnet_mask
.
§Examples:
use amazon_cloudfront_client_routing_lib::client_routing_label::ClientRoutingLabel;
use amazon_cloudfront_client_routing_lib::ip::ClientSubnetEncodingData;
let cgid = 8517775255794402596;
let client_subnet_encoding_data = ClientSubnetEncodingData {
is_ipv6: 0,
client_subnet: 6148494311290830848,
subnet_mask: 24,
};
let mut client_routing_label = ClientRoutingLabel::default();
client_routing_label.set_data(client_subnet_encoding_data, cgid);
Sourcepub fn encode(&mut self) -> String
pub fn encode(&mut self) -> String
Encodes encodable_data
and returns encoded client routing label
Calls the encode function of encoding_system
. Each EncodableData
item in encodable_data
is formatted to the proper number of bits and
encoded into a string.
§Examples:
use amazon_cloudfront_client_routing_lib::client_routing_label::ClientRoutingLabel;
use amazon_cloudfront_client_routing_lib::ip::ClientSubnetEncodingData;
let cgid = 8517775255794402596;
let client_subnet_encoding_data = ClientSubnetEncodingData {
is_ipv6: 0,
client_subnet: 6148494311290830848,
subnet_mask: 24,
};
let mut client_routing_label = ClientRoutingLabel::default();
client_routing_label.set_data(client_subnet_encoding_data, cgid);
assert_eq!("abfku6xaaaaaaaamhmnjxo5hdzrje", client_routing_label.encode());
Sourcepub fn decode(
&mut self,
client_routing_label: &[u8],
) -> Result<DecodedClientRoutingLabel, DecodeLengthError>
pub fn decode( &mut self, client_routing_label: &[u8], ) -> Result<DecodedClientRoutingLabel, DecodeLengthError>
Decodes client_routing_label
and returns a result containing either a
DecodedClientRoutingLabel
or a DecodeLengthError
if the
client_routing_label
is invalid.
§Examples:
use amazon_cloudfront_client_routing_lib::client_routing_label::ClientRoutingLabel;
let mut client_routing_label = ClientRoutingLabel::default();
let decode_result = client_routing_label.decode(b"abfku6xaaaaaaaamhmnjxo5hdzrje");
match decode_result {
Ok(decoded_client_routing_label) => {
assert_eq!(1, decoded_client_routing_label.client_sdk_version);
assert_eq!(false, decoded_client_routing_label.is_ipv6);
assert_eq!([85, 83, 215, 0, 0, 0, 0, 0], decoded_client_routing_label.client_subnet);
assert_eq!(24, decoded_client_routing_label.subnet_mask);
assert_eq!(8517775255794402596, decoded_client_routing_label.cgid);
},
Err(_e) => panic!("Decoding experienced an error when it shouldn't have")
};
Sourcepub fn get_total_num_bits(&mut self) -> u8
pub fn get_total_num_bits(&mut self) -> u8
Returns total num bits a label contains.
Iterates over each item in encodable_data
and sums the num_bits
for
each item, then returns that sum.
§Examples:
use amazon_cloudfront_client_routing_lib::client_routing_label::ClientRoutingLabel;
let mut client_routing_label = ClientRoutingLabel::default();
assert_eq!(145, client_routing_label.get_total_num_bits());
Trait Implementations§
Source§impl Clone for ClientRoutingLabel
impl Clone for ClientRoutingLabel
Source§fn clone(&self) -> ClientRoutingLabel
fn clone(&self) -> ClientRoutingLabel
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more