/// Encodes a list of ALPN protocols into a slice of bytes.
///
/// `boring` requires that the list of protocols be encoded in the wire format.
Encodes a list of ALPN protocols into a slice of bytes.
`boring` requires that the list of protocols be encoded in the wire format.
Encodes a list of ALPN protocols into a slice of bytes . ` boring ` requires that the list of protocols be encoded in the wire format .
fn serialize_alpn(protocols: &[Vec<u8>]) -> Result<Vec<u8>> {
    // Allocate a buffer to hold the encoded protocols.
    let mut bytes = {
        // One additional byte for each protocol's length prefix.
        let cap = protocols.len() + protocols.iter().map(Vec::len).sum::<usize>();
        Vec::with_capacity(cap)
    };
    // Encode each protocol as a length-prefixed string.
    for p in protocols {
        if p.is_empty() {
            continue;
        }
        if p.len() > 255 {
            return Err("ALPN protocols must be less than 256 bytes".into());
        }
        bytes.push(p.len() as u8);
        bytes.extend(p);
    }
    Ok(bytes)
}
fn serialize_alpn ( protocols : & [ Vec < u8 > ] ) -> Result < Vec < u8 > > { // Allocate a buffer to hold the encoded protocols. let mut bytes = { // One additional byte for each protocol's length prefix. let cap = protocols . len ( ) + protocols . iter ( ) . map ( Vec :: len ) . sum :: < usize > ( ) ; Vec :: with_capacity ( cap ) } ; // Encode each protocol as a length-prefixed string. for p in protocols { if p . is_empty ( ) { continue ; } if p . len ( ) > 255 { return Err ( " " . into ( ) ) ; } bytes . push ( p . len ( ) as u8 ) ; bytes . extend ( p ) ; } Ok ( bytes ) }
Encodes a list of ALPN protocols into a slice of bytes.
Encodes a list of ALPN protocols into a slice of bytes .
protocols
&[Vec<u8>]