pub fn as_vec(&self) -> Vec<u8> {
        match self {
            Message::NoticeResponse => vec![NOTICE_RESPONSE],
            Message::AuthenticationCleartextPassword => vec![AUTHENTICATION, 0, 0, 0, 8, 0, 0, 0, 3],
            Message::AuthenticationMD5Password => vec![AUTHENTICATION, 0, 0, 0, 12, 0, 0, 0, 5, 1, 1, 1, 1],
            Message::AuthenticationOk => vec![AUTHENTICATION, 0, 0, 0, 8, 0, 0, 0, 0],
            Message::ReadyForQuery => vec![READY_FOR_QUERY, 0, 0, 0, 5, EMPTY_QUERY_RESPONSE],
            Message::DataRow(row) => {
                let mut row_buff = BytesMut::with_capacity(256);
                for field in row.iter() {
                    let as_string = field;
                    row_buff.put_i32(as_string.len() as i32);
                    row_buff.extend_from_slice(as_string.as_str().as_bytes());
                }
                let mut len_buff = BytesMut::new();
                len_buff.put_u8(DATA_ROW);
                len_buff.put_i32(6 + row_buff.len() as i32);
                len_buff.put_i16(row.len() as i16);
                len_buff.extend_from_slice(&row_buff);
                len_buff.bytes().to_vec()
            }
            Message::RowDescription(description) => {
                let mut buff = BytesMut::with_capacity(256);
                for field in description.iter() {
                    buff.put_slice(field.name.as_str().as_bytes());
                    buff.put_u8(0); // end of c string
                    buff.put_i32(0); // table id
                    buff.put_i16(0); // column id
                    buff.put_i32(field.type_id);
                    buff.put_i16(field.type_size);
                    buff.put_i32(-1); // type modifier
                    buff.put_i16(0);
                }
                let mut len_buff = BytesMut::new();
                len_buff.put_u8(ROW_DESCRIPTION);
                len_buff.put_i32(6 + buff.len() as i32);
                len_buff.put_i16(description.len() as i16);
                len_buff.extend_from_slice(&buff);
                len_buff.to_vec()
            }
            Message::CommandComplete(command) => {
                let mut command_buff = BytesMut::with_capacity(256);
                command_buff.put_u8(COMMAND_COMPLETE);
                command_buff.put_i32(4 + command.len() as i32 + 1);
                command_buff.extend_from_slice(command.as_bytes());
                command_buff.put_u8(0);
                command_buff.to_vec()
            }
            Message::EmptyQueryResponse => vec![EMPTY_QUERY_RESPONSE, 0, 0, 0, 4],
            Message::ErrorResponse(severity, code, message) => {
                let mut error_response_buff = BytesMut::with_capacity(256);
                error_response_buff.put_u8(ERROR_RESPONSE);
                let mut message_buff = BytesMut::with_capacity(256);
                if let Some(severity) = severity.as_ref() {
                    message_buff.put_u8(SEVERITY);
                    message_buff.extend_from_slice(severity.as_bytes());
                    message_buff.put_u8(0);
                }
                if let Some(code) = code.as_ref() {
                    message_buff.put_u8(CODE);
                    message_buff.extend_from_slice(code.as_bytes());
                    message_buff.put_u8(0);
                }
                if let Some(message) = message.as_ref() {
                    message_buff.put_u8(MESSAGE);
                    message_buff.extend_from_slice(message.as_bytes());
                    message_buff.put_u8(0);
                }
                error_response_buff.put_i32(message_buff.len() as i32 + 4 + 1);
                error_response_buff.extend_from_slice(message_buff.as_ref());
                error_response_buff.put_u8(0);
                error_response_buff.to_vec()
            }
        }
    }
/// returns binary representation of a backend message
returns binary representation of a backend message
returns binary representation of a backend message
pub fn as_vec(&self) -> Vec<u8> {
        match self {
            Message::NoticeResponse => vec![NOTICE_RESPONSE],
            Message::AuthenticationCleartextPassword => vec![AUTHENTICATION, 0, 0, 0, 8, 0, 0, 0, 3],
            Message::AuthenticationMD5Password => vec![AUTHENTICATION, 0, 0, 0, 12, 0, 0, 0, 5, 1, 1, 1, 1],
            Message::AuthenticationOk => vec![AUTHENTICATION, 0, 0, 0, 8, 0, 0, 0, 0],
            Message::ReadyForQuery => vec![READY_FOR_QUERY, 0, 0, 0, 5, EMPTY_QUERY_RESPONSE],
            Message::DataRow(row) => {
                let mut row_buff = BytesMut::with_capacity(256);
                for field in row.iter() {
                    let as_string = field;
                    row_buff.put_i32(as_string.len() as i32);
                    row_buff.extend_from_slice(as_string.as_str().as_bytes());
                }
                let mut len_buff = BytesMut::new();
                len_buff.put_u8(DATA_ROW);
                len_buff.put_i32(6 + row_buff.len() as i32);
                len_buff.put_i16(row.len() as i16);
                len_buff.extend_from_slice(&row_buff);
                len_buff.bytes().to_vec()
            }
            Message::RowDescription(description) => {
                let mut buff = BytesMut::with_capacity(256);
                for field in description.iter() {
                    buff.put_slice(field.name.as_str().as_bytes());
                    buff.put_u8(0); // end of c string
                    buff.put_i32(0); // table id
                    buff.put_i16(0); // column id
                    buff.put_i32(field.type_id);
                    buff.put_i16(field.type_size);
                    buff.put_i32(-1); // type modifier
                    buff.put_i16(0);
                }
                let mut len_buff = BytesMut::new();
                len_buff.put_u8(ROW_DESCRIPTION);
                len_buff.put_i32(6 + buff.len() as i32);
                len_buff.put_i16(description.len() as i16);
                len_buff.extend_from_slice(&buff);
                len_buff.to_vec()
            }
            Message::CommandComplete(command) => {
                let mut command_buff = BytesMut::with_capacity(256);
                command_buff.put_u8(COMMAND_COMPLETE);
                command_buff.put_i32(4 + command.len() as i32 + 1);
                command_buff.extend_from_slice(command.as_bytes());
                command_buff.put_u8(0);
                command_buff.to_vec()
            }
            Message::EmptyQueryResponse => vec![EMPTY_QUERY_RESPONSE, 0, 0, 0, 4],
            Message::ErrorResponse(severity, code, message) => {
                let mut error_response_buff = BytesMut::with_capacity(256);
                error_response_buff.put_u8(ERROR_RESPONSE);
                let mut message_buff = BytesMut::with_capacity(256);
                if let Some(severity) = severity.as_ref() {
                    message_buff.put_u8(SEVERITY);
                    message_buff.extend_from_slice(severity.as_bytes());
                    message_buff.put_u8(0);
                }
                if let Some(code) = code.as_ref() {
                    message_buff.put_u8(CODE);
                    message_buff.extend_from_slice(code.as_bytes());
                    message_buff.put_u8(0);
                }
                if let Some(message) = message.as_ref() {
                    message_buff.put_u8(MESSAGE);
                    message_buff.extend_from_slice(message.as_bytes());
                    message_buff.put_u8(0);
                }
                error_response_buff.put_i32(message_buff.len() as i32 + 4 + 1);
                error_response_buff.extend_from_slice(message_buff.as_ref());
                error_response_buff.put_u8(0);
                error_response_buff.to_vec()
            }
        }
    }
pub fn as_vec ( & self ) -> Vec < u8 > { match self { Message :: NoticeResponse => vec ! [ NOTICE_RESPONSE ] , Message :: AuthenticationCleartextPassword => vec ! [ AUTHENTICATION 0 0 0 8 0 0 0 3 ] , Message :: AuthenticationMD5Password => vec ! [ AUTHENTICATION 0 0 0 12 0 0 0 5 1 1 1 1 ] , Message :: AuthenticationOk => vec ! [ AUTHENTICATION 0 0 0 8 0 0 0 0 ] , Message :: ReadyForQuery => vec ! [ READY_FOR_QUERY 0 0 0 5 EMPTY_QUERY_RESPONSE ] , Message :: DataRow ( row ) => { let mut row_buff = BytesMut :: with_capacity ( 256 ) ; for field in row . iter ( ) { let as_string = field ; row_buff . put_i32 ( as_string . len ( ) as i32 ) ; row_buff . extend_from_slice ( as_string . as_str ( ) . as_bytes ( ) ) ; } let mut len_buff = BytesMut :: new ( ) ; len_buff . put_u8 ( DATA_ROW ) ; len_buff . put_i32 ( 6 + row_buff . len ( ) as i32 ) ; len_buff . put_i16 ( row . len ( ) as i16 ) ; len_buff . extend_from_slice ( & row_buff ) ; len_buff . bytes ( ) . to_vec ( ) } Message :: RowDescription ( description ) => { let mut buff = BytesMut :: with_capacity ( 256 ) ; for field in description . iter ( ) { buff . put_slice ( field . name . as_str ( ) . as_bytes ( ) ) ; buff . put_u8 ( 0 ) ; // end of c string buff . put_i32 ( 0 ) ; // table id buff . put_i16 ( 0 ) ; // column id buff . put_i32 ( field . type_id ) ; buff . put_i16 ( field . type_size ) ; buff . put_i32 ( - 1 ) ; // type modifier buff . put_i16 ( 0 ) ; } let mut len_buff = BytesMut :: new ( ) ; len_buff . put_u8 ( ROW_DESCRIPTION ) ; len_buff . put_i32 ( 6 + buff . len ( ) as i32 ) ; len_buff . put_i16 ( description . len ( ) as i16 ) ; len_buff . extend_from_slice ( & buff ) ; len_buff . to_vec ( ) } Message :: CommandComplete ( command ) => { let mut command_buff = BytesMut :: with_capacity ( 256 ) ; command_buff . put_u8 ( COMMAND_COMPLETE ) ; command_buff . put_i32 ( 4 + command . len ( ) as i32 + 1 ) ; command_buff . extend_from_slice ( command . as_bytes ( ) ) ; command_buff . put_u8 ( 0 ) ; command_buff . to_vec ( ) } Message :: EmptyQueryResponse => vec ! [ EMPTY_QUERY_RESPONSE 0 0 0 4 ] , Message :: ErrorResponse ( severity , code , message ) => { let mut error_response_buff = BytesMut :: with_capacity ( 256 ) ; error_response_buff . put_u8 ( ERROR_RESPONSE ) ; let mut message_buff = BytesMut :: with_capacity ( 256 ) ; if let Some ( severity ) = severity . as_ref ( ) { message_buff . put_u8 ( SEVERITY ) ; message_buff . extend_from_slice ( severity . as_bytes ( ) ) ; message_buff . put_u8 ( 0 ) ; } if let Some ( code ) = code . as_ref ( ) { message_buff . put_u8 ( CODE ) ; message_buff . extend_from_slice ( code . as_bytes ( ) ) ; message_buff . put_u8 ( 0 ) ; } if let Some ( message ) = message . as_ref ( ) { message_buff . put_u8 ( MESSAGE ) ; message_buff . extend_from_slice ( message . as_bytes ( ) ) ; message_buff . put_u8 ( 0 ) ; } error_response_buff . put_i32 ( message_buff . len ( ) as i32 + 4 + 1 ) ; error_response_buff . extend_from_slice ( message_buff . as_ref ( ) ) ; error_response_buff . put_u8 ( 0 ) ; error_response_buff . to_vec ( ) } } }
returns binary representation of a backend message
returns binary representation of a backend message
&self
&self