canoser 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/README-CN.md +8 -1
- data/README.md +13 -3
- data/canoser.gemspec +4 -4
- data/canoser.sublime-project +16 -0
- data/lib/canoser/version.rb +1 -1
- metadata +15 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89fbb5634526ecc83a890a3f2598d834938028b509c0a0500eef8f17707cb178
|
4
|
+
data.tar.gz: 99b14d822421d7bf26b5eddff461c68efeddceb0c36511a1c34d594bc1699fd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70f34f92da5ba6330baabbd7d37e2ce1070f2d8216fb47a6ca04314d49920c9aaed91b4906a872eddbbed64ceac983dd94be7e2468874e1b97f93d9b5b7d0590
|
7
|
+
data.tar.gz: 2b105656dea17c9a1692da8cae2d82349d1e6b9780da33cae8e99f46c8a9221caca635bce96ba1473f8279f3253ef89ad35b70eb392068de1b36d6964f7b5402
|
data/.gitignore
CHANGED
data/README-CN.md
CHANGED
@@ -107,7 +107,7 @@ Map里的数据,如果没有定义类型,那么缺省是字节数组。下
|
|
107
107
|
define_field :addr, {}
|
108
108
|
end
|
109
109
|
class Map2 < Canoser::Struct
|
110
|
-
define_field :addr, {[Canoser::Uint8]
|
110
|
+
define_field :addr, {[Canoser::Uint8] => [Canoser::Uint8]}
|
111
111
|
end
|
112
112
|
```
|
113
113
|
|
@@ -144,4 +144,11 @@ bytes = obj.serialize
|
|
144
144
|
#反序列化
|
145
145
|
obj = AccountResource.deserialize(bytes)
|
146
146
|
```
|
147
|
+
### 从Struct对象中读取字段的值
|
148
|
+
对于所有通过define_field方法定义的字段,可以通过[field_name]获取该字段的值。比如:
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
obj[:authentication_key]
|
152
|
+
```
|
153
|
+
|
147
154
|
|
data/README.md
CHANGED
@@ -114,7 +114,7 @@ The default data type (if not defined) in the map is an array of Uint8. The foll
|
|
114
114
|
define_field :addr, {}
|
115
115
|
end
|
116
116
|
class Map2 < Canoser::Struct
|
117
|
-
define_field :addr, {[Canoser::Uint8]
|
117
|
+
define_field :addr, {[Canoser::Uint8] => [Canoser::Uint8]}
|
118
118
|
end
|
119
119
|
```
|
120
120
|
|
@@ -146,13 +146,23 @@ This example refers to the test code from canonical serialization in libra.
|
|
146
146
|
After defining Canoser::Struct, you don't need to implement serialization and deserialization code yourself, you can directly call the default implementation of the base class. Take the AccountResource structure as an example:
|
147
147
|
|
148
148
|
```ruby
|
149
|
-
|
149
|
+
# serialize an object
|
150
150
|
obj = AccountResource.new(authentication_key:[...],...)
|
151
151
|
bytes = obj.serialize
|
152
|
-
|
152
|
+
|
153
|
+
# deserialize an object form bytes
|
153
154
|
obj = AccountResource.deserialize(bytes)
|
154
155
|
```
|
155
156
|
|
157
|
+
### Get field value form object
|
158
|
+
For all fields defined by the "define_field" method, the value of this field of an object can be obtained via [field_name]. such as:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
obj[:authentication_key]
|
162
|
+
#or
|
163
|
+
obj["authentication_key"]
|
164
|
+
```
|
165
|
+
|
156
166
|
|
157
167
|
## Development
|
158
168
|
|
data/canoser.gemspec
CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["yuanxinyu.hangzhou@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{A ruby implementation of the canonical serialization for the Libra network.}
|
13
|
-
spec.description = %q{A ruby implementation of the canonical serialization for the Libra network.}
|
14
|
-
spec.homepage = "https://github.com/yuanxinyu/canoser.git"
|
13
|
+
spec.description = %q{A ruby implementation of the canonical serialization for the Libra network. Canonical serialization guarantees byte consistency when serializing an in-memory data structure. It is useful for situations where two parties want to efficiently compare data structures they independently maintain. It happens in consensus where independent validators need to agree on the state they independently compute. A cryptographic hash of the serialized data structure is what ultimately gets compared. In order for this to work, the serialization of the same data structures must be identical when computed by independent validators potentially running different implementations of the same spec in different languages.}
|
14
|
+
spec.homepage = "https://github.com/yuanxinyu/canoser-ruby.git"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
21
|
|
22
22
|
spec.metadata["homepage_uri"] = spec.homepage
|
23
|
-
spec.metadata["source_code_uri"] = "https://github.com/yuanxinyu/canoser.git"
|
24
|
-
spec.metadata["changelog_uri"] = "https://github.com/yuanxinyu/canoser.git"
|
23
|
+
spec.metadata["source_code_uri"] = "https://github.com/yuanxinyu/canoser-ruby.git"
|
24
|
+
spec.metadata["changelog_uri"] = "https://github.com/yuanxinyu/canoser-ruby.git"
|
25
25
|
else
|
26
26
|
raise "RubyGems 2.0 or newer is required to protect against " \
|
27
27
|
"public gem pushes."
|
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"folders":
|
3
|
+
[
|
4
|
+
{
|
5
|
+
"path": ".",
|
6
|
+
"folder_exclude_patterns": [".bundle",".idea","certs","coverage","tmp","log","pkg"],
|
7
|
+
"file_exclude_patterns": ["*.sublime-workspace","*.sqlite3","spec/examples.txt",".byebug_history",".DS_Store"]
|
8
|
+
}
|
9
|
+
],
|
10
|
+
"settings":
|
11
|
+
{
|
12
|
+
"translate_tabs_to_spaces": true,
|
13
|
+
"trim_trailing_white_space_on_save": true,
|
14
|
+
"tab_size": 2
|
15
|
+
}
|
16
|
+
}
|
data/lib/canoser/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: canoser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yuan xinyu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -67,6 +67,14 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '11.0'
|
69
69
|
description: A ruby implementation of the canonical serialization for the Libra network.
|
70
|
+
Canonical serialization guarantees byte consistency when serializing an in-memory
|
71
|
+
data structure. It is useful for situations where two parties want to efficiently
|
72
|
+
compare data structures they independently maintain. It happens in consensus where
|
73
|
+
independent validators need to agree on the state they independently compute. A
|
74
|
+
cryptographic hash of the serialized data structure is what ultimately gets compared.
|
75
|
+
In order for this to work, the serialization of the same data structures must be
|
76
|
+
identical when computed by independent validators potentially running different
|
77
|
+
implementations of the same spec in different languages.
|
70
78
|
email:
|
71
79
|
- yuanxinyu.hangzhou@gmail.com
|
72
80
|
executables: []
|
@@ -84,19 +92,20 @@ files:
|
|
84
92
|
- bin/console
|
85
93
|
- bin/setup
|
86
94
|
- canoser.gemspec
|
95
|
+
- canoser.sublime-project
|
87
96
|
- lib/canoser.rb
|
88
97
|
- lib/canoser/cursor.rb
|
89
98
|
- lib/canoser/field.rb
|
90
99
|
- lib/canoser/struct.rb
|
91
100
|
- lib/canoser/version.rb
|
92
|
-
homepage: https://github.com/yuanxinyu/canoser.git
|
101
|
+
homepage: https://github.com/yuanxinyu/canoser-ruby.git
|
93
102
|
licenses:
|
94
103
|
- MIT
|
95
104
|
metadata:
|
96
105
|
allowed_push_host: https://rubygems.org
|
97
|
-
homepage_uri: https://github.com/yuanxinyu/canoser.git
|
98
|
-
source_code_uri: https://github.com/yuanxinyu/canoser.git
|
99
|
-
changelog_uri: https://github.com/yuanxinyu/canoser.git
|
106
|
+
homepage_uri: https://github.com/yuanxinyu/canoser-ruby.git
|
107
|
+
source_code_uri: https://github.com/yuanxinyu/canoser-ruby.git
|
108
|
+
changelog_uri: https://github.com/yuanxinyu/canoser-ruby.git
|
100
109
|
post_install_message:
|
101
110
|
rdoc_options: []
|
102
111
|
require_paths:
|