Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use prefix in serialize/deserialize of serde. #3340

Merged
merged 1 commit into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 176 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions massa-models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ lazy_static = "1.4"
num_enum = "0.5"
rust_decimal = "1.26"
serde = { version = "1.0", features = ["derive"] }
serde_with = "2.1.0"
thiserror = "1.0"
num = { version = "0.4", features = ["serde"] }
directories = "4.0"
Expand Down
5 changes: 4 additions & 1 deletion massa-models/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use nom::{
IResult,
};
use serde::{Deserialize, Serialize};
use serde_with::{DeserializeFromStr, SerializeDisplay};
use std::convert::TryInto;
use std::fmt::Formatter;
use std::ops::Bound::{Excluded, Included};
Expand All @@ -35,7 +36,9 @@ use std::str::FromStr;
const BLOCK_ID_SIZE_BYTES: usize = massa_hash::HASH_SIZE_BYTES;

/// block id
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
#[derive(
Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, SerializeDisplay, DeserializeFromStr,
)]
pub struct BlockId(pub Hash);

impl PreHashed for BlockId {}
Expand Down
5 changes: 4 additions & 1 deletion massa-models/src/endorsement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ use nom::{
IResult,
};
use serde::{Deserialize, Serialize};
use serde_with::{DeserializeFromStr, SerializeDisplay};
use std::ops::Bound::{Excluded, Included};
use std::{fmt::Display, str::FromStr};

/// Endorsement ID size in bytes
pub const ENDORSEMENT_ID_SIZE_BYTES: usize = massa_hash::HASH_SIZE_BYTES;

/// endorsement id
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
#[derive(
Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, SerializeDisplay, DeserializeFromStr,
)]
pub struct EndorsementId(Hash);

const ENDORSEMENTID_PREFIX: char = 'E';
Expand Down
6 changes: 4 additions & 2 deletions massa-models/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ use massa_serialization::{
DeserializeError, Deserializer, Serializer, U64VarIntDeserializer, U64VarIntSerializer,
};
use massa_signature::PublicKey;
use serde::{Deserialize, Serialize};
use serde_with::{DeserializeFromStr, SerializeDisplay};
use std::ops::Bound::Included;

/// `NodeId` wraps a public key to uniquely identify a node.
#[derive(Clone, Copy, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
#[derive(
Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd, SerializeDisplay, DeserializeFromStr,
)]
pub struct NodeId(PublicKey);

const NODEID_PREFIX: char = 'N';
Expand Down
5 changes: 4 additions & 1 deletion massa-models/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use nom::{
};
use num_enum::{IntoPrimitive, TryFromPrimitive};
use serde::{Deserialize, Serialize};
use serde_with::{DeserializeFromStr, SerializeDisplay};
use std::convert::TryInto;
use std::fmt::Formatter;
use std::{ops::Bound::Included, ops::RangeInclusive, str::FromStr};
Expand All @@ -37,7 +38,9 @@ pub const OPERATION_ID_SIZE_BYTES: usize = massa_hash::HASH_SIZE_BYTES;
pub const OPERATION_ID_PREFIX_SIZE_BYTES: usize = 17;

/// operation id
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
#[derive(
Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, SerializeDisplay, DeserializeFromStr,
)]
pub struct OperationId(Hash);

const OPERATIONID_PREFIX: char = 'O';
Expand Down