Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
kanishkatn committed May 22, 2023
1 parent 8277ae1 commit 04a5bcb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/scale/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,39 @@ SCALE uses a compact encoding for variable width unsigned integers.
| `Compact<u64>` | `uint` |
| `Compact<u128>` | `*big.Int` |

### BitVec

SCALE uses a bit vector to encode a sequence of booleans. The bit vector is encoded as a compact length followed by a byte array.
The byte array is a sequence of bytes where each bit represents a boolean value.

**Note: This is a work in progress.**
The current implementation of BitVec is just bare bones. It does not implement any of the methods of the `BitVec` type in Rust.

```go
import (
"fmt"
"github.com/ChainSafe/gossamer/pkg/scale"
)

func ExampleBitVec() {
bitvec := NewBitVec([]bool{true, false, true, false, true, false, true, false})
bytes, err := scale.Marshal(bitvec)
if err != nil {
panic(err)
}

var unmarshaled BitVec
err = scale.Unmarshal(bytes, &unmarshaled)
if err != nil {
panic(err)
}

// [true false true false true false true false]
fmt.Printf("%v", unmarshaled.Bits())
}
```


## Usage

### Basic Example
Expand Down

0 comments on commit 04a5bcb

Please sign in to comment.