refactor(identity): follow naming conventions for conversion methods

This PR renames some method names that don't follow Rust naming conventions or behave differently from what the name suggests:
- Enforce "try" prefix on all methods that return `Result`.
- Enforce "encode" method name for methods that return encoded bytes.
- Enforce "to_bytes" method name for methods that return raw bytes.
- Enforce "decode" method name for methods that convert encoded key.
- Enforce "from_bytes" method name for methods that convert raw bytes.

Pull-Request: #3775.
This commit is contained in:
DrHuangMHT
2023-04-14 16:55:13 +08:00
committed by GitHub
parent 8ffcff9624
commit 058c2d85ec
23 changed files with 490 additions and 109 deletions

View File

@ -169,7 +169,7 @@ where
.map(|addr| addr.to_vec())
.collect();
let pubkey_bytes = info.public_key.to_protobuf_encoding();
let pubkey_bytes = info.public_key.encode_protobuf();
let message = proto::Identify {
agentVersion: Some(info.agent_version),
@ -235,7 +235,7 @@ impl TryFrom<proto::Identify> for Info {
addrs
};
let public_key = PublicKey::from_protobuf_encoding(&msg.publicKey.unwrap_or_default())?;
let public_key = PublicKey::try_decode_protobuf(&msg.publicKey.unwrap_or_default())?;
let observed_addr = match parse_multiaddr(msg.observedAddr.unwrap_or_default()) {
Ok(a) => a,
@ -386,7 +386,7 @@ mod tests {
publicKey: Some(
identity::Keypair::generate_ed25519()
.public()
.to_protobuf_encoding(),
.encode_protobuf(),
),
};