fn decode<B: Buf>(buf: B) -> io::Result<Option<Self>> {
        let h = proto::Header::decode(buf)
            .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;

        let name = if h.name.is_empty() {
            None
        } else {
            let n = Name::from_str(&h.name)
                .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
            Some(n)
        };

        if h.port <= 0 || h.port > std::u16::MAX as i32 {
            return Err(io::Error::new(
                io::ErrorKind::InvalidData,
                "Invalid port value",
            ));
        }

        let protocol = h.session_protocol.and_then(|p| {
            p.kind.map(|k| match k {
                proto::session_protocol::Kind::Http1(_) => SessionProtocol::Http1,
                proto::session_protocol::Kind::Http2(_) => SessionProtocol::Http2,
            })
        });

        Ok(Some(Self {
            port: h.port as u16,
            name,
            protocol,
        }))
    }
// Decodes a protobuf message from the buffer.
Decodes a protobuf message from the buffer.
Decodes a protobuf message from the buffer .
fn decode<B: Buf>(buf: B) -> io::Result<Option<Self>> {
        let h = proto::Header::decode(buf)
            .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
        let name = if h.name.is_empty() {
            None
        } else {
            let n = Name::from_str(&h.name)
                .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
            Some(n)
        };
        if h.port <= 0 || h.port > std::u16::MAX as i32 {
            return Err(io::Error::new(
                io::ErrorKind::InvalidData,
                "Invalid port value",
            ));
        }
        let protocol = h.session_protocol.and_then(|p| {
            p.kind.map(|k| match k {
                proto::session_protocol::Kind::Http1(_) => SessionProtocol::Http1,
                proto::session_protocol::Kind::Http2(_) => SessionProtocol::Http2,
            })
        });
        Ok(Some(Self {
            port: h.port as u16,
            name,
            protocol,
        }))
    }
fn decode < B : Buf > ( buf : B ) -> io :: Result < Option < Self > > { let h = proto :: Header :: decode ( buf ) . map_err ( | e | io :: Error :: new ( io :: ErrorKind :: InvalidData , e ) ) ? ; let name = if h . name . is_empty ( ) { None } else { let n = Name :: from_str ( & h . name ) . map_err ( | e | io :: Error :: new ( io :: ErrorKind :: InvalidData , e ) ) ? ; Some ( n ) } ; if h . port <= 0 || h . port > std :: u16 :: MAX as i32 { return Err ( io :: Error :: new ( io :: ErrorKind :: InvalidData , " " , ) ) ; } let protocol = h . session_protocol . and_then ( | p | { p . kind . map ( | k | match k { proto :: session_protocol :: Kind :: Http1 ( _ ) => SessionProtocol :: Http1 , proto :: session_protocol :: Kind :: Http2 ( _ ) => SessionProtocol :: Http2 , } ) } ) ; Ok ( Some ( Self { port : h . port as u16 , name , protocol , } ) ) }
Decodes a protobuf message from the buffer.
Decodes a protobuf message from the buffer .
buf
B
buf
B