Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Commit

Permalink
Implementation of trait for row data
Browse files Browse the repository at this point in the history
  • Loading branch information
chotchki committed Sep 24, 2021
1 parent f20b728 commit d6cb4f8
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/engine/io/row_formats/row_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use super::super::super::objects::Table;
use super::super::super::transactions::TransactionId;
use super::null_mask::NullMaskError;
use super::{InfoMask, ItemPointer, ItemPointerError, NullMask};
use crate::engine::io::format_traits::{Parseable, Serializable};
use crate::engine::io::{ConstEncodedSize, EncodedSize, SelfEncodedSize};
use crate::engine::objects::types::{BaseSqlTypes, BaseSqlTypesError, SqlTypeDefinition};
use crate::engine::objects::SqlTuple;
Expand Down Expand Up @@ -61,24 +62,6 @@ impl RowData {
.ok_or_else(|| RowDataError::UnexpectedNull(name.to_string()))
}

pub fn serialize(&self, buffer: &mut impl BufMut) {
buffer.put_u64_le(self.min.get_u64());
buffer.put_u64_le(self.max.unwrap_or_else(|| TransactionId::new(0)).get_u64());
self.item_pointer.serialize(buffer);

//If there is null we add it to the flags and write a nullmask
let mut mask = InfoMask::empty();
if self.user_data.iter().any(|x| x.is_none()) {
mask = InfoMask::HAS_NULL;
buffer.put_u8(mask.bits());
buffer.put(NullMask::serialize(&self.user_data));
} else {
buffer.put_u8(mask.bits());
}

self.user_data.serialize(buffer);
}

pub fn parse(table: Arc<Table>, row_buffer: &mut impl Buf) -> Result<RowData, RowDataError> {
if row_buffer.remaining() < TransactionId::encoded_size() {
return Err(RowDataError::MissingMinData(
Expand Down Expand Up @@ -186,6 +169,26 @@ impl EncodedSize<&SqlTuple> for RowData {
}
}

impl Serializable for RowData {
fn serialize(&self, buffer: &mut impl BufMut) {
buffer.put_u64_le(self.min.get_u64());
buffer.put_u64_le(self.max.unwrap_or_else(|| TransactionId::new(0)).get_u64());
self.item_pointer.serialize(buffer);

//If there is null we add it to the flags and write a nullmask
let mut mask = InfoMask::empty();
if self.user_data.iter().any(|x| x.is_none()) {
mask = InfoMask::HAS_NULL;
buffer.put_u8(mask.bits());
buffer.put(NullMask::serialize(&self.user_data));
} else {
buffer.put_u8(mask.bits());
}

self.user_data.serialize(buffer);
}
}

#[derive(Debug, Error)]
pub enum RowDataError {
#[error(transparent)]
Expand Down

0 comments on commit d6cb4f8

Please sign in to comment.