fn encode(&mut self, values: &[Datum], comparable: bool) -> Result<()> {
        let mut find_min = false;
        for v in values {
            if find_min {
                return Err(invalid_type!(
                    "MinValue should be the last datum.".to_owned()
                ));
            }
            match *v {
                Datum::I64(i) => {
                    if comparable {
                        self.write_u8(INT_FLAG)?;
                        self.write_i64(i)?;
                    } else {
                        self.write_u8(VAR_INT_FLAG)?;
                        self.write_var_i64(i)?;
                    }
                }
                Datum::U64(u) => {
                    if comparable {
                        self.write_u8(UINT_FLAG)?;
                        self.write_u64(u)?;
                    } else {
                        self.write_u8(VAR_UINT_FLAG)?;
                        self.write_var_u64(u)?;
                    }
                }
                Datum::Bytes(ref bs) => {
                    if comparable {
                        self.write_u8(BYTES_FLAG)?;
                        self.write_comparable_bytes(bs)?;
                    } else {
                        self.write_u8(COMPACT_BYTES_FLAG)?;
                        self.write_compact_bytes(bs)?;
                    }
                }
                Datum::F64(f) => {
                    self.write_u8(FLOAT_FLAG)?;
                    self.write_f64(f)?;
                }
                Datum::Null => self.write_u8(NIL_FLAG)?,
                Datum::Min => {
                    self.write_u8(BYTES_FLAG)?; // for backward compatibility
                    find_min = true;
                }
                Datum::Max => self.write_u8(MAX_FLAG)?,
                Datum::Time(ref t) => {
                    self.write_u8(UINT_FLAG)?;
                    self.write_u64(t.to_packed_u64())?;
                }
                Datum::Dur(ref d) => {
                    self.write_u8(DURATION_FLAG)?;
                    self.write_i64(d.to_nanos())?;
                }
                Datum::Dec(ref d) => {
                    self.write_u8(DECIMAL_FLAG)?;
                    let (prec, frac) = d.prec_and_frac();
                    self.encode_decimal(d, prec, frac)?;
                }
                Datum::Json(ref j) => {
                    self.write_u8(JSON_FLAG)?;
                    self.encode_json(j)?;
                }
            }
        }
        Ok(())
    }
/// Encode values to buf slice.
Encode values to buf slice.
Encode values to buf slice .
fn encode(&mut self, values: &[Datum], comparable: bool) -> Result<()> {
        let mut find_min = false;
        for v in values {
            if find_min {
                return Err(invalid_type!(
                    "MinValue should be the last datum.".to_owned()
                ));
            }
            match *v {
                Datum::I64(i) => {
                    if comparable {
                        self.write_u8(INT_FLAG)?;
                        self.write_i64(i)?;
                    } else {
                        self.write_u8(VAR_INT_FLAG)?;
                        self.write_var_i64(i)?;
                    }
                }
                Datum::U64(u) => {
                    if comparable {
                        self.write_u8(UINT_FLAG)?;
                        self.write_u64(u)?;
                    } else {
                        self.write_u8(VAR_UINT_FLAG)?;
                        self.write_var_u64(u)?;
                    }
                }
                Datum::Bytes(ref bs) => {
                    if comparable {
                        self.write_u8(BYTES_FLAG)?;
                        self.write_comparable_bytes(bs)?;
                    } else {
                        self.write_u8(COMPACT_BYTES_FLAG)?;
                        self.write_compact_bytes(bs)?;
                    }
                }
                Datum::F64(f) => {
                    self.write_u8(FLOAT_FLAG)?;
                    self.write_f64(f)?;
                }
                Datum::Null => self.write_u8(NIL_FLAG)?,
                Datum::Min => {
                    self.write_u8(BYTES_FLAG)?; // for backward compatibility
                    find_min = true;
                }
                Datum::Max => self.write_u8(MAX_FLAG)?,
                Datum::Time(ref t) => {
                    self.write_u8(UINT_FLAG)?;
                    self.write_u64(t.to_packed_u64())?;
                }
                Datum::Dur(ref d) => {
                    self.write_u8(DURATION_FLAG)?;
                    self.write_i64(d.to_nanos())?;
                }
                Datum::Dec(ref d) => {
                    self.write_u8(DECIMAL_FLAG)?;
                    let (prec, frac) = d.prec_and_frac();
                    self.encode_decimal(d, prec, frac)?;
                }
                Datum::Json(ref j) => {
                    self.write_u8(JSON_FLAG)?;
                    self.encode_json(j)?;
                }
            }
        }
        Ok(())
    }
fn encode ( & mut self , values : & [ Datum ] , comparable : bool ) -> Result < ( ) > { let mut find_min = false ; for v in values { if find_min { return Err ( invalid_type ! ( " " to_owned ( ) ) ) ; } match * v { Datum :: I64 ( i ) => { if comparable { self . write_u8 ( INT_FLAG ) ? ; self . write_i64 ( i ) ? ; } else { self . write_u8 ( VAR_INT_FLAG ) ? ; self . write_var_i64 ( i ) ? ; } } Datum :: U64 ( u ) => { if comparable { self . write_u8 ( UINT_FLAG ) ? ; self . write_u64 ( u ) ? ; } else { self . write_u8 ( VAR_UINT_FLAG ) ? ; self . write_var_u64 ( u ) ? ; } } Datum :: Bytes ( ref bs ) => { if comparable { self . write_u8 ( BYTES_FLAG ) ? ; self . write_comparable_bytes ( bs ) ? ; } else { self . write_u8 ( COMPACT_BYTES_FLAG ) ? ; self . write_compact_bytes ( bs ) ? ; } } Datum :: F64 ( f ) => { self . write_u8 ( FLOAT_FLAG ) ? ; self . write_f64 ( f ) ? ; } Datum :: Null => self . write_u8 ( NIL_FLAG ) ? , Datum :: Min => { self . write_u8 ( BYTES_FLAG ) ? ; // for backward compatibility find_min = true ; } Datum :: Max => self . write_u8 ( MAX_FLAG ) ? , Datum :: Time ( ref t ) => { self . write_u8 ( UINT_FLAG ) ? ; self . write_u64 ( t . to_packed_u64 ( ) ) ? ; } Datum :: Dur ( ref d ) => { self . write_u8 ( DURATION_FLAG ) ? ; self . write_i64 ( d . to_nanos ( ) ) ? ; } Datum :: Dec ( ref d ) => { self . write_u8 ( DECIMAL_FLAG ) ? ; let ( prec , frac ) = d . prec_and_frac ( ) ; self . encode_decimal ( d , prec , frac ) ? ; } Datum :: Json ( ref j ) => { self . write_u8 ( JSON_FLAG ) ? ; self . encode_json ( j ) ? ; } } } Ok ( ( ) ) }
Encode values to buf slice.
Encode values to buf slice .
&mut self
values
&[Datum]
comparable
bool
&mut self
values
&[Datum]
comparable
bool