Remove custom serialization
This commit is contained in:
committed by
Greg Fitzgerald
parent
981e057363
commit
857dc2ba47
@@ -1,12 +1,9 @@
|
||||
//! Defines a composable Instruction type and a memory-efficient CompiledInstruction.
|
||||
|
||||
use crate::pubkey::Pubkey;
|
||||
use crate::shortvec::{deserialize_vec_bytes, encode_len, serialize_vec_bytes};
|
||||
use crate::system_instruction::SystemError;
|
||||
use bincode::{serialize, Error};
|
||||
use bincode::serialize;
|
||||
use serde::Serialize;
|
||||
use std::io::{Cursor, Read, Write};
|
||||
use std::mem::size_of;
|
||||
|
||||
/// Reasons the runtime might have rejected an instruction.
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
@@ -129,41 +126,4 @@ impl CompiledInstruction {
|
||||
accounts,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn serialize_with(mut writer: &mut Cursor<&mut [u8]>, ix: &Self) -> Result<(), Error> {
|
||||
writer.write_all(&[ix.program_ids_index])?;
|
||||
serialize_vec_bytes(&mut writer, &ix.accounts[..])?;
|
||||
serialize_vec_bytes(&mut writer, &ix.data[..])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn deserialize_from(mut reader: &mut Cursor<&[u8]>) -> Result<Self, Error> {
|
||||
let mut buf = [0];
|
||||
reader.read_exact(&mut buf)?;
|
||||
let program_ids_index = buf[0];
|
||||
let accounts = deserialize_vec_bytes(&mut reader)?;
|
||||
let data = deserialize_vec_bytes(&mut reader)?;
|
||||
Ok(CompiledInstruction {
|
||||
program_ids_index,
|
||||
accounts,
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn serialized_size(&self) -> Result<u64, Error> {
|
||||
let mut buf = [0; size_of::<u64>() + 1];
|
||||
let mut wr = Cursor::new(&mut buf[..]);
|
||||
let mut size = size_of::<u8>();
|
||||
|
||||
let len = self.accounts.len();
|
||||
encode_len(&mut wr, len)?;
|
||||
size += wr.position() as usize + (len * size_of::<u8>());
|
||||
|
||||
let len = self.data.len();
|
||||
wr.set_position(0);
|
||||
encode_len(&mut wr, len)?;
|
||||
size += wr.position() as usize + (len * size_of::<u8>());
|
||||
|
||||
Ok(size as u64)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user