You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pkg/scale/README.md
+192-4Lines changed: 192 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,7 +82,7 @@ SCALE uses a compact encoding for variable width unsigned integers.
82
82
### Basic Example
83
83
84
84
Basic example which encodes and decodes a `uint`.
85
-
```
85
+
```go
86
86
import (
87
87
"fmt"
88
88
"github.com/ChainSafe/gossamer/pkg/scale"
@@ -111,7 +111,7 @@ func ExampleBasic() {
111
111
112
112
Use the `scale` struct tag for struct fields to conform to specific encoding sequence of struct field values. A struct tag of `"-"` will be omitted from encoding and decoding.
113
113
114
-
```
114
+
```go
115
115
import (
116
116
"fmt"
117
117
"github.com/ChainSafe/gossamer/pkg/scale"
@@ -159,7 +159,7 @@ result := scale.NewResult(int32(0), int32(0)
159
159
result.Set(scale.Ok, 10)
160
160
```
161
161
162
-
```
162
+
```go
163
163
import (
164
164
"fmt"
165
165
"github.com/ChainSafe/gossamer/pkg/scale"
@@ -213,7 +213,7 @@ func ExampleResult() {
213
213
A `VaryingDataType` is analogous to a Rust enum. A `VaryingDataType` needs to be constructed using the `NewVaryingDataType` constructor. `VaryingDataTypeValue` is an
214
214
interface with one `Index() uint` method that needs to be implemented. The returned `uint` index should be unique per type and needs to be the same index as defined in the Rust enum to ensure interopability. To set the value of the `VaryingDataType`, the `VaryingDataType.Set()` function should be called with an associated `VaryingDataTypeValue`.
See `varying_data_type_nested_example.go` for a working example of a custom `VaryingDataType` with another custom `VaryingDataType` as a value of the parent `VaryingDataType`. In the case of nested `VaryingDataTypes`, a custom type needs to be created for the child `VaryingDataType` because it needs to fulfill the `VaryingDataTypeValue` interface.
331
+
332
+
```go
333
+
import (
334
+
"fmt"
335
+
"reflect"
336
+
337
+
"github.com/ChainSafe/gossamer/pkg/scale"
338
+
)
339
+
340
+
// ParentVDT is a VaryingDataType that consists of multiple nested VaryingDataType
341
+
// instances (aka. a rust enum containing multiple enum options)
342
+
typeParentVDT scale.VaryingDataType
343
+
344
+
// Set will set a VaryingDataTypeValue using the underlying VaryingDataType
0 commit comments