Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Dunitrust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nodes
rust
Dunitrust
Commits
94040c47
Commit
94040c47
authored
6 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[opti] blockchain-dal: serialize TreeNodeId like u32
parent
8de73078
No related branches found
No related tags found
1 merge request
!109
Resolve "Fork resolution algorithm"
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs
+58
-1
58 additions, 1 deletion
...dules/blockchain/blockchain-dal/src/entities/fork_tree.rs
with
58 additions
and
1 deletion
lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs
+
58
−
1
View file @
94040c47
...
...
@@ -16,12 +16,69 @@
//! Describe fork tree
use
dubp_documents
::{
BlockHash
,
BlockId
,
Blockstamp
};
use
serde
::
de
::{
self
,
Deserialize
,
Deserializer
,
Visitor
};
use
serde
::{
Serialize
,
Serializer
};
use
std
::
collections
::{
HashMap
,
HashSet
};
use
std
::
fmt
;
#[derive(Debug,
Copy,
Clone,
PartialEq,
Eq,
Hash
,
Serialize,
Deserialize
)]
#[derive(Debug,
Copy,
Clone,
PartialEq,
Eq,
Hash)]
/// unique identifier of tree node
pub
struct
TreeNodeId
(
pub
usize
);
impl
Serialize
for
TreeNodeId
{
fn
serialize
<
S
>
(
&
self
,
serializer
:
S
)
->
Result
<
S
::
Ok
,
S
::
Error
>
where
S
:
Serializer
,
{
serializer
.serialize_u32
(
self
.0
as
u32
)
}
}
struct
TreeNodeIdVisitor
;
impl
<
'de
>
Visitor
<
'de
>
for
TreeNodeIdVisitor
{
type
Value
=
TreeNodeId
;
fn
expecting
(
&
self
,
formatter
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
formatter
.write_str
(
"an integer between -2^31 and 2^31"
)
}
fn
visit_u8
<
E
>
(
self
,
value
:
u8
)
->
Result
<
TreeNodeId
,
E
>
where
E
:
de
::
Error
,
{
Ok
(
TreeNodeId
(
value
as
usize
))
}
fn
visit_u32
<
E
>
(
self
,
value
:
u32
)
->
Result
<
TreeNodeId
,
E
>
where
E
:
de
::
Error
,
{
Ok
(
TreeNodeId
(
value
as
usize
))
}
fn
visit_u64
<
E
>
(
self
,
value
:
u64
)
->
Result
<
TreeNodeId
,
E
>
where
E
:
de
::
Error
,
{
use
std
::
usize
;
if
value
>=
usize
::
MIN
as
u64
&&
value
<=
usize
::
MAX
as
u64
{
Ok
(
TreeNodeId
(
value
as
usize
))
}
else
{
Err
(
E
::
custom
(
format!
(
"u32 out of range: {}"
,
value
)))
}
}
}
impl
<
'de
>
Deserialize
<
'de
>
for
TreeNodeId
{
fn
deserialize
<
D
>
(
deserializer
:
D
)
->
Result
<
TreeNodeId
,
D
::
Error
>
where
D
:
Deserializer
<
'de
>
,
{
deserializer
.deserialize_u32
(
TreeNodeIdVisitor
)
}
}
#[derive(Debug,
Clone,
Serialize,
Deserialize)]
/// Tree node
pub
struct
TreeNode
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment