pub fn datum_size(datum: &Datum) -> usize {
    match datum {
        Datum::Null => 1,
        Datum::False => 1,
        Datum::True => 1,
        Datum::Int16(_) => 1 + size_of::<i16>(),
        Datum::Int32(_) => 1 + size_of::<i32>(),
        Datum::Int64(_) => 1 + size_of::<i64>(),
        Datum::Float32(_) => 1 + size_of::<u32>(),
        Datum::Float64(_) => 1 + size_of::<u64>(),
        Datum::Date(_) => 1 + 8,
        Datum::Time(_) => 1 + 8,
        Datum::Timestamp(_) => 1 + 16,
        Datum::TimestampTz(_) => 1 + 16,
        Datum::Interval(_) => 1 + size_of::<i32>() + size_of::<i128>(),
        Datum::Bytes(bytes) => {
            // We use a variable length representation of slice length.
            let bytes_for_length = match bytes.len() {
                0..=255 => 1,
                256..=65535 => 2,
                65536..=4294967295 => 4,
                _ => 8,
            };
            1 + bytes_for_length + bytes.len()
        }
        Datum::String(string) => {
            // We use a variable length representation of slice length.
            let bytes_for_length = match string.len() {
                0..=255 => 1,
                256..=65535 => 2,
                65536..=4294967295 => 4,
                _ => 8,
            };
            1 + bytes_for_length + string.len()
        }
        Datum::Uuid(_) => 1 + size_of::<uuid::Bytes>(),
        Datum::Array(array) => {
            1 + size_of::<u8>()
                + array.dims.data.len()
                + size_of::<u64>()
                + array.elements.data.len()
        }
        Datum::List(list) => 1 + size_of::<u64>() + list.data.len(),
        Datum::Map(dict) => 1 + size_of::<u64>() + dict.data.len(),
        Datum::JsonNull => 1,
        Datum::Dummy => 1,
        Datum::Numeric(d) => {
            let mut d = d.0.clone();
            // Values must be reduced to determine appropriate number of
            // coefficient units.
            numeric::cx_datum().reduce(&mut d);
            // 4 = 1 bit each for tag, digits, exponent, bits
            4 + (d.coefficient_units().len() * 2)
        }
    }
}
/// Number of bytes required by the datum.
///
/// This is used to optimistically pre-allocate buffers for packing rows.
Number of bytes required by the datum.
This is used to optimistically pre-allocate buffers for packing rows.
Number of bytes required by the datum . This is used to optimistically pre - allocate buffers for packing rows .
pub fn datum_size(datum: &Datum) -> usize {
    match datum {
        Datum::Null => 1,
        Datum::False => 1,
        Datum::True => 1,
        Datum::Int16(_) => 1 + size_of::<i16>(),
        Datum::Int32(_) => 1 + size_of::<i32>(),
        Datum::Int64(_) => 1 + size_of::<i64>(),
        Datum::Float32(_) => 1 + size_of::<u32>(),
        Datum::Float64(_) => 1 + size_of::<u64>(),
        Datum::Date(_) => 1 + 8,
        Datum::Time(_) => 1 + 8,
        Datum::Timestamp(_) => 1 + 16,
        Datum::TimestampTz(_) => 1 + 16,
        Datum::Interval(_) => 1 + size_of::<i32>() + size_of::<i128>(),
        Datum::Bytes(bytes) => {
            // We use a variable length representation of slice length.
            let bytes_for_length = match bytes.len() {
                0..=255 => 1,
                256..=65535 => 2,
                65536..=4294967295 => 4,
                _ => 8,
            };
            1 + bytes_for_length + bytes.len()
        }
        Datum::String(string) => {
            // We use a variable length representation of slice length.
            let bytes_for_length = match string.len() {
                0..=255 => 1,
                256..=65535 => 2,
                65536..=4294967295 => 4,
                _ => 8,
            };
            1 + bytes_for_length + string.len()
        }
        Datum::Uuid(_) => 1 + size_of::<uuid::Bytes>(),
        Datum::Array(array) => {
            1 + size_of::<u8>()
                + array.dims.data.len()
                + size_of::<u64>()
                + array.elements.data.len()
        }
        Datum::List(list) => 1 + size_of::<u64>() + list.data.len(),
        Datum::Map(dict) => 1 + size_of::<u64>() + dict.data.len(),
        Datum::JsonNull => 1,
        Datum::Dummy => 1,
        Datum::Numeric(d) => {
            let mut d = d.0.clone();
            // Values must be reduced to determine appropriate number of
            // coefficient units.
            numeric::cx_datum().reduce(&mut d);
            // 4 = 1 bit each for tag, digits, exponent, bits
            4 + (d.coefficient_units().len() * 2)
        }
    }
}
pub fn datum_size ( datum : & Datum ) -> usize { match datum { Datum :: Null => 1 , Datum :: False => 1 , Datum :: True => 1 , Datum :: Int16 ( _ ) => 1 + size_of :: < i16 > ( ) , Datum :: Int32 ( _ ) => 1 + size_of :: < i32 > ( ) , Datum :: Int64 ( _ ) => 1 + size_of :: < i64 > ( ) , Datum :: Float32 ( _ ) => 1 + size_of :: < u32 > ( ) , Datum :: Float64 ( _ ) => 1 + size_of :: < u64 > ( ) , Datum :: Date ( _ ) => 1 + 8 , Datum :: Time ( _ ) => 1 + 8 , Datum :: Timestamp ( _ ) => 1 + 16 , Datum :: TimestampTz ( _ ) => 1 + 16 , Datum :: Interval ( _ ) => 1 + size_of :: < i32 > ( ) + size_of :: < i128 > ( ) , Datum :: Bytes ( bytes ) => { // We use a variable length representation of slice length. let bytes_for_length = match bytes . len ( ) { 0 ..= 255 => 1 , 256 ..= 65535 => 2 , 65536 ..= 4294967295 => 4 , _ => 8 , } ; 1 + bytes_for_length + bytes . len ( ) } Datum :: String ( string ) => { // We use a variable length representation of slice length. let bytes_for_length = match string . len ( ) { 0 ..= 255 => 1 , 256 ..= 65535 => 2 , 65536 ..= 4294967295 => 4 , _ => 8 , } ; 1 + bytes_for_length + string . len ( ) } Datum :: Uuid ( _ ) => 1 + size_of :: < uuid :: Bytes > ( ) , Datum :: Array ( array ) => { 1 + size_of :: < u8 > ( ) + array . dims . data . len ( ) + size_of :: < u64 > ( ) + array . elements . data . len ( ) } Datum :: List ( list ) => 1 + size_of :: < u64 > ( ) + list . data . len ( ) , Datum :: Map ( dict ) => 1 + size_of :: < u64 > ( ) + dict . data . len ( ) , Datum :: JsonNull => 1 , Datum :: Dummy => 1 , Datum :: Numeric ( d ) => { let mut d = d . 0 . clone ( ) ; // Values must be reduced to determine appropriate number of // coefficient units. numeric :: cx_datum ( ) . reduce ( & mut d ) ; // 4 = 1 bit each for tag, digits, exponent, bits 4 + ( d . coefficient_units ( ) . len ( ) * 2 ) } } }
Number of bytes required by the datum.
Number of bytes required by the datum .
datum
&Datum
datum
&Datum