Make String Zcash serialization consistent with deserialization
After recent changes, serialization was `write_string`, but deserialization was `zcash_deserialize`.
This commit is contained in:
parent
5b2f1cdfd5
commit
7b13d5573a
|
@ -71,13 +71,6 @@ pub trait WriteZcashExt: io::Write {
|
||||||
self.write_u16::<BigEndian>(addr.port())
|
self.write_u16::<BigEndian>(addr.port())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write a string in Bitcoin format.
|
|
||||||
#[inline]
|
|
||||||
fn write_string(&mut self, string: &str) -> io::Result<()> {
|
|
||||||
self.write_compactsize(string.len() as u64)?;
|
|
||||||
self.write_all(string.as_bytes())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convenience method to write exactly 32 u8's.
|
/// Convenience method to write exactly 32 u8's.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn write_32_bytes(&mut self, bytes: &[u8; 32]) -> io::Result<()> {
|
fn write_32_bytes(&mut self, bytes: &[u8; 32]) -> io::Result<()> {
|
||||||
|
|
|
@ -99,6 +99,22 @@ pub fn zcash_serialize_bytes_external_count<W: io::Write>(
|
||||||
writer.write_all(&vec)
|
writer.write_all(&vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Write a Bitcoin-encoded UTF-8 `&str`.
|
||||||
|
impl ZcashSerialize for &str {
|
||||||
|
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
|
||||||
|
let str_bytes = self.as_bytes();
|
||||||
|
writer.write_compactsize(str_bytes.len() as u64)?;
|
||||||
|
writer.write_all(str_bytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Write a Bitcoin-encoded UTF-8 `String`.
|
||||||
|
impl ZcashSerialize for String {
|
||||||
|
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
|
||||||
|
self.as_str().zcash_serialize(&mut writer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The maximum length of a Zcash message, in bytes.
|
/// The maximum length of a Zcash message, in bytes.
|
||||||
///
|
///
|
||||||
/// This value is used to calculate safe preallocation limits for some types
|
/// This value is used to calculate safe preallocation limits for some types
|
||||||
|
|
|
@ -228,7 +228,7 @@ impl Codec {
|
||||||
writer.write_socket_addr(*from_addr)?;
|
writer.write_socket_addr(*from_addr)?;
|
||||||
|
|
||||||
writer.write_u64::<LittleEndian>(nonce.0)?;
|
writer.write_u64::<LittleEndian>(nonce.0)?;
|
||||||
writer.write_string(&user_agent)?;
|
user_agent.zcash_serialize(&mut writer)?;
|
||||||
writer.write_u32::<LittleEndian>(start_height.0)?;
|
writer.write_u32::<LittleEndian>(start_height.0)?;
|
||||||
writer.write_u8(*relay as u8)?;
|
writer.write_u8(*relay as u8)?;
|
||||||
}
|
}
|
||||||
|
@ -245,9 +245,9 @@ impl Codec {
|
||||||
reason,
|
reason,
|
||||||
data,
|
data,
|
||||||
} => {
|
} => {
|
||||||
writer.write_string(&message)?;
|
message.zcash_serialize(&mut writer)?;
|
||||||
writer.write_u8(*ccode as u8)?;
|
writer.write_u8(*ccode as u8)?;
|
||||||
writer.write_string(&reason)?;
|
reason.zcash_serialize(&mut writer)?;
|
||||||
if let Some(data) = data {
|
if let Some(data) = data {
|
||||||
writer.write_all(data)?;
|
writer.write_all(data)?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue