pub fn encode(
        &self,
        row_index: usize,
        field_type: &FieldType,
        output: &mut Vec<u8>,
    ) -> Result<()> {
        use crate::codec::mysql::DecimalEncoder;
        use crate::codec::mysql::JsonEncoder;
        use codec::prelude::{CompactByteEncoder, NumberEncoder};

        match self {
            VectorValue::Int(ref vec) => {
                match vec[row_index] {
                    None => {
                        output.push(datum::NIL_FLAG);
                    }
                    Some(val) => {
                        // Always encode to INT / UINT instead of VAR INT to be efficient.
                        if field_type
                            .as_accessor()
                            .flag()
                            .contains(FieldTypeFlag::UNSIGNED)
                        {
                            output.push(datum::UINT_FLAG);
                            output.write_u64(val as u64)?;
                        } else {
                            output.push(datum::INT_FLAG);
                            output.write_i64(val)?;
                        }
                    }
                }
                Ok(())
            }
            VectorValue::Real(ref vec) => {
                match vec[row_index] {
                    None => {
                        output.push(datum::NIL_FLAG);
                    }
                    Some(val) => {
                        output.push(datum::FLOAT_FLAG);
                        output.write_f64(val.into_inner())?;
                    }
                }
                Ok(())
            }
            VectorValue::Decimal(ref vec) => {
                match &vec[row_index] {
                    None => {
                        output.push(datum::NIL_FLAG);
                    }
                    Some(val) => {
                        output.push(datum::DECIMAL_FLAG);
                        let (prec, frac) = val.prec_and_frac();
                        output.encode_decimal(val, prec, frac)?;
                    }
                }
                Ok(())
            }
            VectorValue::Bytes(ref vec) => {
                match &vec[row_index] {
                    None => {
                        output.push(datum::NIL_FLAG);
                    }
                    Some(ref val) => {
                        output.push(datum::COMPACT_BYTES_FLAG);
                        output.write_compact_bytes(val)?;
                    }
                }
                Ok(())
            }
            VectorValue::DateTime(ref vec) => {
                match &vec[row_index] {
                    None => {
                        output.push(datum::NIL_FLAG);
                    }
                    Some(ref val) => {
                        output.push(datum::UINT_FLAG);
                        output.write_u64(val.to_packed_u64())?;
                    }
                }
                Ok(())
            }
            VectorValue::Duration(ref vec) => {
                match &vec[row_index] {
                    None => {
                        output.push(datum::NIL_FLAG);
                    }
                    Some(ref val) => {
                        output.push(datum::DURATION_FLAG);
                        output.write_i64(val.to_nanos())?;
                    }
                }
                Ok(())
            }
            VectorValue::Json(ref vec) => {
                match &vec[row_index] {
                    None => {
                        output.push(datum::NIL_FLAG);
                    }
                    Some(ref val) => {
                        output.push(datum::JSON_FLAG);
                        output.encode_json(val)?;
                    }
                }
                Ok(())
            }
        }
    }
/// Encodes a single element into binary format.
Encodes a single element into binary format.
Encodes a single element into binary format .
pub fn encode(
        &self,
        row_index: usize,
        field_type: &FieldType,
        output: &mut Vec<u8>,
    ) -> Result<()> {
        use crate::codec::mysql::DecimalEncoder;
        use crate::codec::mysql::JsonEncoder;
        use codec::prelude::{CompactByteEncoder, NumberEncoder};
        match self {
            VectorValue::Int(ref vec) => {
                match vec[row_index] {
                    None => {
                        output.push(datum::NIL_FLAG);
                    }
                    Some(val) => {
                        // Always encode to INT / UINT instead of VAR INT to be efficient.
                        if field_type
                            .as_accessor()
                            .flag()
                            .contains(FieldTypeFlag::UNSIGNED)
                        {
                            output.push(datum::UINT_FLAG);
                            output.write_u64(val as u64)?;
                        } else {
                            output.push(datum::INT_FLAG);
                            output.write_i64(val)?;
                        }
                    }
                }
                Ok(())
            }
            VectorValue::Real(ref vec) => {
                match vec[row_index] {
                    None => {
                        output.push(datum::NIL_FLAG);
                    }
                    Some(val) => {
                        output.push(datum::FLOAT_FLAG);
                        output.write_f64(val.into_inner())?;
                    }
                }
                Ok(())
            }
            VectorValue::Decimal(ref vec) => {
                match &vec[row_index] {
                    None => {
                        output.push(datum::NIL_FLAG);
                    }
                    Some(val) => {
                        output.push(datum::DECIMAL_FLAG);
                        let (prec, frac) = val.prec_and_frac();
                        output.encode_decimal(val, prec, frac)?;
                    }
                }
                Ok(())
            }
            VectorValue::Bytes(ref vec) => {
                match &vec[row_index] {
                    None => {
                        output.push(datum::NIL_FLAG);
                    }
                    Some(ref val) => {
                        output.push(datum::COMPACT_BYTES_FLAG);
                        output.write_compact_bytes(val)?;
                    }
                }
                Ok(())
            }
            VectorValue::DateTime(ref vec) => {
                match &vec[row_index] {
                    None => {
                        output.push(datum::NIL_FLAG);
                    }
                    Some(ref val) => {
                        output.push(datum::UINT_FLAG);
                        output.write_u64(val.to_packed_u64())?;
                    }
                }
                Ok(())
            }
            VectorValue::Duration(ref vec) => {
                match &vec[row_index] {
                    None => {
                        output.push(datum::NIL_FLAG);
                    }
                    Some(ref val) => {
                        output.push(datum::DURATION_FLAG);
                        output.write_i64(val.to_nanos())?;
                    }
                }
                Ok(())
            }
            VectorValue::Json(ref vec) => {
                match &vec[row_index] {
                    None => {
                        output.push(datum::NIL_FLAG);
                    }
                    Some(ref val) => {
                        output.push(datum::JSON_FLAG);
                        output.encode_json(val)?;
                    }
                }
                Ok(())
            }
        }
    }
pub fn encode ( & self , row_index : usize , field_type : & FieldType , output : & mut Vec < u8 > , ) -> Result < ( ) > { use crate :: codec :: mysql :: DecimalEncoder ; use crate :: codec :: mysql :: JsonEncoder ; use codec :: prelude :: { CompactByteEncoder , NumberEncoder } ; match self { VectorValue :: Int ( ref vec ) => { match vec [ row_index ] { None => { output . push ( datum :: NIL_FLAG ) ; } Some ( val ) => { // Always encode to INT / UINT instead of VAR INT to be efficient. if field_type . as_accessor ( ) . flag ( ) . contains ( FieldTypeFlag :: UNSIGNED ) { output . push ( datum :: UINT_FLAG ) ; output . write_u64 ( val as u64 ) ? ; } else { output . push ( datum :: INT_FLAG ) ; output . write_i64 ( val ) ? ; } } } Ok ( ( ) ) } VectorValue :: Real ( ref vec ) => { match vec [ row_index ] { None => { output . push ( datum :: NIL_FLAG ) ; } Some ( val ) => { output . push ( datum :: FLOAT_FLAG ) ; output . write_f64 ( val . into_inner ( ) ) ? ; } } Ok ( ( ) ) } VectorValue :: Decimal ( ref vec ) => { match & vec [ row_index ] { None => { output . push ( datum :: NIL_FLAG ) ; } Some ( val ) => { output . push ( datum :: DECIMAL_FLAG ) ; let ( prec , frac ) = val . prec_and_frac ( ) ; output . encode_decimal ( val , prec , frac ) ? ; } } Ok ( ( ) ) } VectorValue :: Bytes ( ref vec ) => { match & vec [ row_index ] { None => { output . push ( datum :: NIL_FLAG ) ; } Some ( ref val ) => { output . push ( datum :: COMPACT_BYTES_FLAG ) ; output . write_compact_bytes ( val ) ? ; } } Ok ( ( ) ) } VectorValue :: DateTime ( ref vec ) => { match & vec [ row_index ] { None => { output . push ( datum :: NIL_FLAG ) ; } Some ( ref val ) => { output . push ( datum :: UINT_FLAG ) ; output . write_u64 ( val . to_packed_u64 ( ) ) ? ; } } Ok ( ( ) ) } VectorValue :: Duration ( ref vec ) => { match & vec [ row_index ] { None => { output . push ( datum :: NIL_FLAG ) ; } Some ( ref val ) => { output . push ( datum :: DURATION_FLAG ) ; output . write_i64 ( val . to_nanos ( ) ) ? ; } } Ok ( ( ) ) } VectorValue :: Json ( ref vec ) => { match & vec [ row_index ] { None => { output . push ( datum :: NIL_FLAG ) ; } Some ( ref val ) => { output . push ( datum :: JSON_FLAG ) ; output . encode_json ( val ) ? ; } } Ok ( ( ) ) } } }
Encodes a single element into binary format.
Encodes a single element into binary format .
&self
row_index
usize
field_type
&FieldType
output
&mut Vec<u8>
&self
row_index
usize
field_type
&FieldType
output
&mut Vec<u8>