fn append_bitstring(builder: &mut BuilderData, string: &str) -> ClientResult<()> {
    let mut num_str = string.trim();

    // Try parse direct binary form
    if num_str.starts_with("n") || num_str.starts_with("N") {
        parse_string(builder, &num_str[1..], false, 2, num_str.len() - 1)?;
        return Ok(());
    }

    // Escape from decorations
    if num_str.starts_with("x{") || num_str.starts_with("X{") {
        if !num_str.ends_with("}") {
            return Err(Error::serialization_error(
                "Missing terminating `}`",
                string,
            ));
        }
        num_str = &num_str[2..num_str.len() - 1];
    } else if num_str.starts_with("x") || num_str.starts_with("X") {
        num_str = &num_str[1..];
    }

    // Check if there is a tagged representation
    if num_str.ends_with("_") {
        num_str = &num_str[0..num_str.len() - 1];
        // Escape from trailing zeros because of BuilderData doesn't support this
        while num_str.ends_with("0") {
            num_str = &num_str[0..num_str.len() - 1];
        }
        // Check if the bitstring isn't empty
        if num_str != "" && num_str != "8" {
            let mut number = BigUint::from_str_radix(num_str, 16)
                .map_err(|err| Error::serialization_error(err, string))?;
            // If hex string has an odd len, we need to pad it with zero bits at the end
            if (num_str.len() & 1) != 0 {
                number.shl_assign(4);
            }
            let bytes = number.to_bytes_be();
            builder
                .append_bitstring(&bytes)
                .map_err(|err| Error::serialization_error(err, string))?;
        }
    } else {
        // Here is an untagged representation
        let size = num_str.len() * 4;
        parse_string(builder, num_str, false, 16, size)?;
    }
    Ok(())
}
/// Append bitstring canonical (extended with `n` prefix) representation.
Append bitstring canonical (extended with `n` prefix) representation.
Append bitstring canonical ( extended with ` n ` prefix ) representation .
fn append_bitstring(builder: &mut BuilderData, string: &str) -> ClientResult<()> {
    let mut num_str = string.trim();
    // Try parse direct binary form
    if num_str.starts_with("n") || num_str.starts_with("N") {
        parse_string(builder, &num_str[1..], false, 2, num_str.len() - 1)?;
        return Ok(());
    }
    // Escape from decorations
    if num_str.starts_with("x{") || num_str.starts_with("X{") {
        if !num_str.ends_with("}") {
            return Err(Error::serialization_error(
                "Missing terminating `}`",
                string,
            ));
        }
        num_str = &num_str[2..num_str.len() - 1];
    } else if num_str.starts_with("x") || num_str.starts_with("X") {
        num_str = &num_str[1..];
    }
    // Check if there is a tagged representation
    if num_str.ends_with("_") {
        num_str = &num_str[0..num_str.len() - 1];
        // Escape from trailing zeros because of BuilderData doesn't support this
        while num_str.ends_with("0") {
            num_str = &num_str[0..num_str.len() - 1];
        }
        // Check if the bitstring isn't empty
        if num_str != "" && num_str != "8" {
            let mut number = BigUint::from_str_radix(num_str, 16)
                .map_err(|err| Error::serialization_error(err, string))?;
            // If hex string has an odd len, we need to pad it with zero bits at the end
            if (num_str.len() & 1) != 0 {
                number.shl_assign(4);
            }
            let bytes = number.to_bytes_be();
            builder
                .append_bitstring(&bytes)
                .map_err(|err| Error::serialization_error(err, string))?;
        }
    } else {
        // Here is an untagged representation
        let size = num_str.len() * 4;
        parse_string(builder, num_str, false, 16, size)?;
    }
    Ok(())
}
fn append_bitstring ( builder : & mut BuilderData , string : & str ) -> ClientResult < ( ) > { let mut num_str = string . trim ( ) ; // Try parse direct binary form if num_str . starts_with ( " " ) || num_str . starts_with ( " " ) { parse_string ( builder , & num_str [ 1 .. ] , false , 2 , num_str . len ( ) - 1 ) ? ; return Ok ( ( ) ) ; } // Escape from decorations if num_str . starts_with ( " " ) || num_str . starts_with ( " " ) { if ! num_str . ends_with ( " " ) { return Err ( Error :: serialization_error ( " " , string , ) ) ; } num_str = & num_str [ 2 .. num_str . len ( ) - 1 ] ; } else if num_str . starts_with ( " " ) || num_str . starts_with ( " " ) { num_str = & num_str [ 1 .. ] ; } // Check if there is a tagged representation if num_str . ends_with ( " " ) { num_str = & num_str [ 0 .. num_str . len ( ) - 1 ] ; // Escape from trailing zeros because of BuilderData doesn't support this while num_str . ends_with ( " " ) { num_str = & num_str [ 0 .. num_str . len ( ) - 1 ] ; } // Check if the bitstring isn't empty if num_str != " " && num_str != " " { let mut number = BigUint :: from_str_radix ( num_str , 16 ) . map_err ( | err | Error :: serialization_error ( err , string ) ) ? ; // If hex string has an odd len, we need to pad it with zero bits at the end if ( num_str . len ( ) & 1 ) != 0 { number . shl_assign ( 4 ) ; } let bytes = number . to_bytes_be ( ) ; builder . append_bitstring ( & bytes ) . map_err ( | err | Error :: serialization_error ( err , string ) ) ? ; } } else { // Here is an untagged representation let size = num_str . len ( ) * 4 ; parse_string ( builder , num_str , false , 16 , size ) ? ; } Ok ( ( ) ) }
Append bitstring canonical (extended with `n` prefix) representation.
Append bitstring canonical ( extended with ` n ` prefix ) representation .
builder
&mut BuilderData
string
&str