mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-07-30 20:11:23 +00:00
write for entry
This commit is contained in:
@@ -206,7 +206,7 @@ fn main() {
|
|||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
if let Some(out_file_path) = ::std::env::args().nth(1) {
|
if let Some(out_file_path) = ::std::env::args().nth(1) {
|
||||||
for node in initial_tree_vec.into_iter() {
|
for node in initial_tree_vec.into_iter() {
|
||||||
node.write(&mut buf);
|
node.write(&mut buf).expect("Failed to write data");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut file = std::fs::File::create(&out_file_path)
|
let mut file = std::fs::File::create(&out_file_path)
|
||||||
|
20
src/entry.rs
20
src/entry.rs
@@ -1,4 +1,4 @@
|
|||||||
use byteorder::{LittleEndian, ReadBytesExt};
|
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||||
|
|
||||||
use crate::{EntryKind, NodeData, Error, EntryLink, MAX_NODE_DATA_SIZE};
|
use crate::{EntryKind, NodeData, Error, EntryLink, MAX_NODE_DATA_SIZE};
|
||||||
|
|
||||||
@@ -67,6 +67,24 @@ impl Entry {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn write<W: std::io::Write>(&self, w: &mut W) -> std::io::Result<()> {
|
||||||
|
match self.kind {
|
||||||
|
EntryKind::Node(EntryLink::Stored(left), EntryLink::Stored(right)) => {
|
||||||
|
w.write_u8(0)?;
|
||||||
|
w.write_u32::<LittleEndian>(left)?;
|
||||||
|
w.write_u32::<LittleEndian>(right)?;
|
||||||
|
},
|
||||||
|
EntryKind::Leaf => {
|
||||||
|
w.write_u8(1)?;
|
||||||
|
},
|
||||||
|
_ => { return Err(std::io::Error::from(std::io::ErrorKind::InvalidData)); }
|
||||||
|
}
|
||||||
|
|
||||||
|
self.data.write(w)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn from_bytes<T: AsRef<[u8]>>(consensus_branch_id: u32, buf: T) -> std::io::Result<Self> {
|
pub fn from_bytes<T: AsRef<[u8]>>(consensus_branch_id: u32, buf: T) -> std::io::Result<Self> {
|
||||||
let mut cursor = std::io::Cursor::new(buf);
|
let mut cursor = std::io::Cursor::new(buf);
|
||||||
Self::read(consensus_branch_id, &mut cursor)
|
Self::read(consensus_branch_id, &mut cursor)
|
||||||
|
Reference in New Issue
Block a user