Skip to content

Commit

Permalink
Store block_height of Color ID in big endian
Browse files Browse the repository at this point in the history
  • Loading branch information
Yamaguchi committed Mar 24, 2024
1 parent 4f17079 commit 8b9f08b
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/new_index/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1377,31 +1377,43 @@ impl ColorIdRow {
}

fn prefix() -> Bytes {
bincode::serialize(&(b'B'))
bincode::options()
.with_big_endian()
.serialize(&(b'B'))
.unwrap()
}

fn filter_end(block_height: u32, color_id: &Option<ColorIdentifier>) -> Bytes {
let filter = if let Some(color_id) = color_id {
bincode::serialize(&(b'B', block_height, b'c', &serialize_color_id(&color_id)))
.unwrap()
bincode::options()
.with_big_endian()
.serialize(&(b'B', block_height, b'c', &serialize_color_id(&color_id)))
.unwrap()
} else {
bincode::serialize(&(b'B', block_height + 1, b'c'))
.unwrap()
bincode::options()
.with_big_endian()
.serialize(&(b'B', block_height + 1, b'c'))
.unwrap()
};
filter
}

pub fn into_row(self) -> DBRow {
let key = bincode::options()
.with_big_endian()
.serialize(&(b'B', self.key.block_height, b'c', &serialize_color_id(&self.key.color_id)))
.unwrap();
DBRow {
key: bincode::serialize(&(b'B', self.key.block_height, b'c', &serialize_color_id(&self.key.color_id))).unwrap(),
key: key,
value: vec![],
}
}

pub fn from_row(row: DBRow) -> Self {
let (_prefix, block_height, _prefix2, token_type, payload): (u8, u32, u8, u8, [u8; 32]) =
bincode::deserialize(&row.key).expect("failed to deserialize ColorIdRow");
bincode::options()
.with_big_endian()
.deserialize(&row.key).expect("failed to deserialize ColorIdRow");
ColorIdRow {
key: ColorIdKey {
block_height: block_height,
Expand Down

0 comments on commit 8b9f08b

Please sign in to comment.