Skip to content

Commit

Permalink
chore: upgrade molecule
Browse files Browse the repository at this point in the history
  • Loading branch information
driftluo committed Jan 27, 2021
1 parent 2a62fb4 commit 67ad2c0
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 69 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
MOLC := moleculec
MOLC_VERSION := 0.6.0
MOLC_VERSION := 0.7.0

MOL_FILES := \
src/protocol_select/protocol_select.mol \
tentacle/src/protocol_select/protocol_select.mol \
secio/src/handshake/handshake.mol \

MOL_RUST_FILES := $(patsubst %.mol,%_mol.rs,${MOL_FILES})
Expand Down
2 changes: 1 addition & 1 deletion secio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tokio = { version = "1.0", features = ["io-util"] }
tokio-util = { version = "0.6.0", features = ["codec"] }
log = "0.4.1"

molecule = "0.6.0"
molecule = "0.7.0"

unsigned-varint = "0.3"
bs58 = "0.3.0"
Expand Down
34 changes: 15 additions & 19 deletions secio/src/handshake/handshake_mol.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated by Molecule 0.6.0
// Generated by Molecule 0.7.0

use molecule::prelude::*;
#[derive(Clone)]
Expand Down Expand Up @@ -1214,22 +1214,20 @@ impl<'r> molecule::prelude::Reader<'r> for ProposeReader<'r> {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
}
let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
if offset_first % 4 != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
return ve!(Self, OffsetsNotMatch);
}
let field_count = offset_first / 4 - 1;
if slice_len < offset_first {
return ve!(Self, HeaderIsBroken, offset_first, slice_len);
}
let field_count = offset_first / molecule::NUMBER_SIZE - 1;
if field_count < Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
} else if !compatible && field_count > Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
};
let header_size = molecule::NUMBER_SIZE * (field_count + 1);
if slice_len < header_size {
return ve!(Self, HeaderIsBroken, header_size, slice_len);
}
let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..]
.chunks(molecule::NUMBER_SIZE)
.take(field_count)
let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
.chunks_exact(molecule::NUMBER_SIZE)
.map(|x| molecule::unpack_number(x) as usize)
.collect();
offsets.push(total_size);
Expand Down Expand Up @@ -1510,22 +1508,20 @@ impl<'r> molecule::prelude::Reader<'r> for ExchangeReader<'r> {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
}
let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
if offset_first % 4 != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
return ve!(Self, OffsetsNotMatch);
}
let field_count = offset_first / 4 - 1;
if slice_len < offset_first {
return ve!(Self, HeaderIsBroken, offset_first, slice_len);
}
let field_count = offset_first / molecule::NUMBER_SIZE - 1;
if field_count < Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
} else if !compatible && field_count > Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
};
let header_size = molecule::NUMBER_SIZE * (field_count + 1);
if slice_len < header_size {
return ve!(Self, HeaderIsBroken, header_size, slice_len);
}
let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..]
.chunks(molecule::NUMBER_SIZE)
.take(field_count)
let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
.chunks_exact(molecule::NUMBER_SIZE)
.map(|x| molecule::unpack_number(x) as usize)
.collect();
offsets.push(total_size);
Expand Down
34 changes: 14 additions & 20 deletions secio/src/handshake/handshake_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,14 @@ impl Propose {
)
.build();

Bytes::from(
handshake_mol::Propose::new_builder()
.rand(rand)
.pubkey(pubkey)
.exchanges(exchange)
.ciphers(ciphers)
.hashes(hashes)
.build()
.as_slice()
.to_owned(),
)
handshake_mol::Propose::new_builder()
.rand(rand)
.pubkey(pubkey)
.exchanges(exchange)
.ciphers(ciphers)
.hashes(hashes)
.build()
.as_bytes()
}

/// Decode with molecule
Expand Down Expand Up @@ -103,14 +100,11 @@ impl Exchange {
.set(self.signature.into_iter().map(Into::into).collect())
.build();

Bytes::from(
handshake_mol::Exchange::new_builder()
.epubkey(epubkey)
.signature(signature)
.build()
.as_slice()
.to_owned(),
)
handshake_mol::Exchange::new_builder()
.epubkey(epubkey)
.signature(signature)
.build()
.as_bytes()
}

/// Decode with molecule
Expand Down Expand Up @@ -163,7 +157,7 @@ impl PublicKey {
let pubkey = handshake_mol::PublicKey::new_builder()
.set(secp256k1)
.build();
Bytes::from(pubkey.as_slice().to_owned())
pubkey.as_bytes()
}

/// Decode with molecule
Expand Down
2 changes: 1 addition & 1 deletion tentacle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async-std = { version = "1", features = ["unstable"], optional = true }
async-io = { version = "1", optional = true }

multiaddr = { path = "../multiaddr", package = "tentacle-multiaddr", version = "0.2.0" }
molecule = "0.6.0"
molecule = "0.7.0"

# upnp
igd = { version = "0.11", optional = true }
Expand Down
13 changes: 5 additions & 8 deletions tentacle/src/protocol_select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,11 @@ impl ProtocolInfo {
.set(versions)
.build();

Bytes::from(
protocol_select_mol::ProtocolInfo::new_builder()
.name(name)
.support_versions(versions)
.build()
.as_slice()
.to_owned(),
)
protocol_select_mol::ProtocolInfo::new_builder()
.name(name)
.support_versions(versions)
.build()
.as_bytes()
}

/// Decode with molecule
Expand Down
31 changes: 13 additions & 18 deletions tentacle/src/protocol_select/protocol_select_mol.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated by Molecule 0.6.0
// Generated by Molecule 0.7.0

use molecule::prelude::*;
#[derive(Clone)]
Expand Down Expand Up @@ -438,17 +438,14 @@ impl<'r> molecule::prelude::Reader<'r> for StringVecReader<'r> {
);
}
let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
if offset_first % 4 != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
return ve!(Self, OffsetsNotMatch);
}
let item_count = offset_first / 4 - 1;
let header_size = molecule::NUMBER_SIZE * (item_count + 1);
if slice_len < header_size {
return ve!(Self, HeaderIsBroken, header_size, slice_len);
if slice_len < offset_first {
return ve!(Self, HeaderIsBroken, offset_first, slice_len);
}
let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..]
.chunks(molecule::NUMBER_SIZE)
.take(item_count)
let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
.chunks_exact(molecule::NUMBER_SIZE)
.map(|x| molecule::unpack_number(x) as usize)
.collect();
offsets.push(total_size);
Expand Down Expand Up @@ -768,22 +765,20 @@ impl<'r> molecule::prelude::Reader<'r> for ProtocolInfoReader<'r> {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
}
let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
if offset_first % 4 != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
return ve!(Self, OffsetsNotMatch);
}
let field_count = offset_first / 4 - 1;
if slice_len < offset_first {
return ve!(Self, HeaderIsBroken, offset_first, slice_len);
}
let field_count = offset_first / molecule::NUMBER_SIZE - 1;
if field_count < Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
} else if !compatible && field_count > Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
};
let header_size = molecule::NUMBER_SIZE * (field_count + 1);
if slice_len < header_size {
return ve!(Self, HeaderIsBroken, header_size, slice_len);
}
let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..]
.chunks(molecule::NUMBER_SIZE)
.take(field_count)
let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
.chunks_exact(molecule::NUMBER_SIZE)
.map(|x| molecule::unpack_number(x) as usize)
.collect();
offsets.push(total_size);
Expand Down

0 comments on commit 67ad2c0

Please sign in to comment.