summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
0ad8fde)
The spec is a bit mum on feature endianness, so I suppose it falls
under the "everything is big endian unless otherwise specified"
clause, but we were treating it as little.
/// appears.
pub struct Features<T: FeatureContext> {
#[cfg(not(test))]
/// appears.
pub struct Features<T: FeatureContext> {
#[cfg(not(test))]
+ /// Note that, for convinience, flags is LITTLE endian (despite being big-endian on the wire)
flags: Vec<u8>,
// Used to test encoding of diverse msgs
#[cfg(test)]
flags: Vec<u8>,
// Used to test encoding of diverse msgs
#[cfg(test)]
impl<T: FeatureContext> Writeable for Features<T> {
fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
w.size_hint(self.flags.len() + 2);
impl<T: FeatureContext> Writeable for Features<T> {
fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
w.size_hint(self.flags.len() + 2);
+ (self.flags.len() as u16).write(w)?;
+ for f in self.flags.iter().rev() { // We have to swap the endianness back to BE for writing
+ f.write(w)?;
+ }
+ Ok(())
}
}
impl<R: ::std::io::Read, T: FeatureContext> Readable<R> for Features<T> {
fn read(r: &mut R) -> Result<Self, DecodeError> {
}
}
impl<R: ::std::io::Read, T: FeatureContext> Readable<R> for Features<T> {
fn read(r: &mut R) -> Result<Self, DecodeError> {
+ let mut flags: Vec<u8> = Readable::read(r)?;
+ flags.reverse(); // Swap to big-endian
- flags: Readable::read(r)?,
mark: PhantomData,
})
}
}
mark: PhantomData,
})
}
}
/// An init message to be sent or received from a peer
pub struct Init {
pub(crate) features: InitFeatures,
/// An init message to be sent or received from a peer
pub struct Init {
pub(crate) features: InitFeatures,