Skip to content

Commit

Permalink
serialize account data without allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Nov 20, 2024
1 parent d82e65a commit 71c0390
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
20 changes: 20 additions & 0 deletions yellowstone-grpc-proto/src/plugin/filter/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use {
},
},
base64::{engine::general_purpose::STANDARD as base64_engine, Engine},
bytes::buf::BufMut,
prost::encoding::{encode_key, encode_varint, WireType},
solana_sdk::{
pubkey::{ParsePubkeyError, Pubkey},
signature::{ParseSignatureError, Signature},
Expand Down Expand Up @@ -1047,6 +1049,24 @@ impl FilterAccountsDataSlice {
len
}
}

pub fn slice_encode_raw(&self, tag: u32, source: &[u8], buf: &mut impl BufMut) {
let len = self.get_slice_len(source) as u64;
if len > 0 {
encode_key(tag, WireType::LengthDelimited, buf);
encode_varint(len, buf);

if self.0.is_empty() {
buf.put_slice(source);
} else {
for data_slice in self.0.iter() {
if source.len() >= data_slice.end {
buf.put_slice(&source[data_slice.start..data_slice.end]);
}
}
}
}
}
}

#[cfg(test)]
Expand Down
5 changes: 1 addition & 4 deletions yellowstone-grpc-proto/src/plugin/filter/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,7 @@ impl FilteredUpdateAccount {
if account.rent_epoch != 0u64 {
::prost::encoding::uint64::encode(5u32, &account.rent_epoch, buf);
}
let data = data_slice.get_slice(&account.data);
if !data.is_empty() {
prost_bytes_encode_raw(6u32, data.as_ref(), buf);
}
data_slice.slice_encode_raw(6u32, &account.data, buf);
if account.write_version != 0u64 {
::prost::encoding::uint64::encode(7u32, &account.write_version, buf);
}
Expand Down

0 comments on commit 71c0390

Please sign in to comment.