Merge pull request #627 from RCasatta/bigendian
Bigendian fixes and CI test
This commit is contained in:
commit
df4d70a37e
|
@ -43,6 +43,25 @@ jobs:
|
|||
env: ${{ matrix.env }}
|
||||
run: ./contrib/test.sh
|
||||
|
||||
Cross:
|
||||
name: Cross testing
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Crate
|
||||
uses: actions/checkout@v2
|
||||
- name: Checkout Toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: stable
|
||||
override: true
|
||||
- name: Install target
|
||||
run: rustup target add s390x-unknown-linux-gnu
|
||||
- name: install cross
|
||||
run: cargo install cross
|
||||
- name: run cross test
|
||||
run: cross test --target s390x-unknown-linux-gnu
|
||||
|
||||
Docs:
|
||||
name: Docs
|
||||
runs-on: ubuntu-latest
|
||||
|
|
|
@ -338,7 +338,7 @@ macro_rules! impl_int_encodable{
|
|||
impl Decodable for $ty {
|
||||
#[inline]
|
||||
fn consensus_decode<D: io::Read>(mut d: D) -> Result<Self, Error> {
|
||||
ReadExt::$meth_dec(&mut d).map($ty::from_le)
|
||||
ReadExt::$meth_dec(&mut d)
|
||||
}
|
||||
}
|
||||
impl Encodable for $ty {
|
||||
|
@ -347,7 +347,7 @@ macro_rules! impl_int_encodable{
|
|||
&self,
|
||||
mut s: S,
|
||||
) -> Result<usize, io::Error> {
|
||||
s.$meth_enc(self.to_le())?;
|
||||
s.$meth_enc(*self)?;
|
||||
Ok(mem::size_of::<$ty>())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,8 +70,13 @@ impl Address {
|
|||
}
|
||||
|
||||
fn addr_to_be(addr: [u16; 8]) -> [u16; 8] {
|
||||
[addr[0].to_be(), addr[1].to_be(), addr[2].to_be(), addr[3].to_be(),
|
||||
addr[4].to_be(), addr[5].to_be(), addr[6].to_be(), addr[7].to_be()]
|
||||
// consensus_encode always encodes in LE, and we want to encode in BE.
|
||||
// this utility fn swap bytes before encoding so that the encoded result will be BE
|
||||
let mut result = addr.clone();
|
||||
for i in 0..8 {
|
||||
result[i] = result[i].swap_bytes();
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
impl Encodable for Address {
|
||||
|
@ -82,7 +87,10 @@ impl Encodable for Address {
|
|||
) -> Result<usize, io::Error> {
|
||||
let len = self.services.consensus_encode(&mut s)?
|
||||
+ addr_to_be(self.address).consensus_encode(&mut s)?
|
||||
+ self.port.to_be().consensus_encode(s)?;
|
||||
|
||||
// consensus_encode always encodes in LE, and we want to encode in BE.
|
||||
//TODO `len += io::Write::write(&mut e, &self.port.to_be_bytes())?;` when MSRV >= 1.32
|
||||
+ self.port.swap_bytes().consensus_encode(s)?;
|
||||
Ok(len)
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +101,7 @@ impl Decodable for Address {
|
|||
Ok(Address {
|
||||
services: Decodable::consensus_decode(&mut d)?,
|
||||
address: addr_to_be(Decodable::consensus_decode(&mut d)?),
|
||||
port: u16::from_be(Decodable::consensus_decode(d)?)
|
||||
port: u16::swap_bytes(Decodable::consensus_decode(d)?)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -268,7 +276,10 @@ impl Encodable for AddrV2Message {
|
|||
len += self.time.consensus_encode(&mut e)?;
|
||||
len += VarInt(self.services.as_u64()).consensus_encode(&mut e)?;
|
||||
len += self.addr.consensus_encode(&mut e)?;
|
||||
len += self.port.to_be().consensus_encode(e)?;
|
||||
|
||||
// consensus_encode always encodes in LE, and we want to encode in BE.
|
||||
//TODO `len += io::Write::write(&mut e, &self.port.to_be_bytes())?;` when MSRV >= 1.32
|
||||
len += self.port.swap_bytes().consensus_encode(e)?;
|
||||
Ok(len)
|
||||
}
|
||||
}
|
||||
|
@ -279,7 +290,7 @@ impl Decodable for AddrV2Message {
|
|||
time: Decodable::consensus_decode(&mut d)?,
|
||||
services: ServiceFlags::from(VarInt::consensus_decode(&mut d)?.0),
|
||||
addr: Decodable::consensus_decode(&mut d)?,
|
||||
port: u16::from_be(Decodable::consensus_decode(d)?),
|
||||
port: u16::swap_bytes(Decodable::consensus_decode(d)?),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@ macro_rules! construct_uint {
|
|||
fn cmp(&self, other: &$name) -> ::core::cmp::Ordering {
|
||||
// We need to manually implement ordering because we use little-endian
|
||||
// and the auto derive is a lexicographic ordering(i.e. memcmp)
|
||||
// which with numbers is equivilant to big-endian
|
||||
// which with numbers is equivalent to big-endian
|
||||
for i in 0..$n_words {
|
||||
if self[$n_words - 1 - i] < other[$n_words - 1 - i] { return ::core::cmp::Ordering::Less; }
|
||||
if self[$n_words - 1 - i] > other[$n_words - 1 - i] { return ::core::cmp::Ordering::Greater; }
|
||||
|
|
Loading…
Reference in New Issue