Cleanup redundant AsFixedBytes and FixedLength traits (#3131)

* no need for AsFixedBytes we can just use AsRef<[u8]>

* cleanup FixedLength trait

* revert this change for now

* fix store tests

* cleanup and fix tests after rebase

* fix tests

* update based on PR review
less hard-coded values now

* cleanup
This commit is contained in:
Antioch Peverell
2020-01-29 13:41:50 +00:00
committed by GitHub
parent 83a2649946
commit 616dad43fd
15 changed files with 112 additions and 265 deletions
+1 -1
View File
@@ -21,7 +21,7 @@
//! stream and make sure we get the right number of bytes out.
use crate::core::ser;
use crate::core::ser::{FixedLength, ProtocolVersion};
use crate::core::ser::ProtocolVersion;
use crate::msg::{
read_body, read_discard, read_header, read_item, write_message, Msg, MsgHeader,
MsgHeaderWrapper,
+4 -6
View File
@@ -19,7 +19,7 @@ use crate::core::core::hash::Hash;
use crate::core::core::BlockHeader;
use crate::core::pow::Difficulty;
use crate::core::ser::{
self, FixedLength, ProtocolVersion, Readable, Reader, StreamingReader, Writeable, Writer,
self, ProtocolVersion, Readable, Reader, StreamingReader, Writeable, Writer,
};
use crate::core::{consensus, global};
use crate::types::{
@@ -262,6 +262,9 @@ pub struct MsgHeader {
}
impl MsgHeader {
// 2 magic bytes + 1 type byte + 8 bytes (msg_len)
pub const LEN: usize = 2 + 1 + 8;
/// Creates a new message header.
pub fn new(msg_type: Type, len: u64) -> MsgHeader {
MsgHeader {
@@ -272,11 +275,6 @@ impl MsgHeader {
}
}
impl FixedLength for MsgHeader {
// 2 magic bytes + 1 type byte + 8 bytes (msg_len)
const LEN: usize = 2 + 1 + 8;
}
impl Writeable for MsgHeader {
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ser::Error> {
ser_multiwrite!(