[][src]Function cjdns_core::splice::re_encode

pub fn re_encode<L: LabelBits>(
    label: RoutingLabel<L>,
    scheme: &EncodingScheme,
    desired_form_num: Option<u8>
) -> Result<RoutingLabel<L>>

Re-encode a label to the encoding form specified by desired_form_num (or canonical if None).

This will re-encode a label to the encoding form specified by desired_form_num. This may return an error if the encoding form cannot be detected, you pass an invalid desired_form_num or if you try to re-encode the self route (0001). It will also return an error if re-encoding a label will make it too long (more than Label::max_bit_size() bits). If desired_form_num is None then it will re-encode the label into it's cannonical form, that is the smallest form which can hold that director.

let r = re_encode(l("0000.0000.0000.0015"), &schemes::V358, Some(0));
assert_eq!(r, Ok(l("0000.0000.0000.0015")));

let r = re_encode(l("0000.0000.0000.0015"), &schemes::V358, Some(1));
assert_eq!(r, Ok(l("0000.0000.0000.0086")));

let r = re_encode(l("0000.0000.0000.0015"), &schemes::V358, Some(2));
assert_eq!(r, Ok(l("0000.0000.0000.0404")));

let r = re_encode(l("0000.0000.0000.0404"), &schemes::V358, None);
assert_eq!(r, Ok(l("0000.0000.0000.0015")));

See: EncodingScheme_convertLabel()