Struct ClientRoutingLabel

Source
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

Source

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);
Source

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());
Source

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")
};
Source

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

Source§

fn clone(&self) -> ClientRoutingLabel

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ClientRoutingLabel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ClientRoutingLabel

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for ClientRoutingLabel

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V