Skip to content

Commit

Permalink
Add decoding of non-compact uints (#98)
Browse files Browse the repository at this point in the history
The encoder function were already there.
Also, add tests for non-compact uint encoding/decoding.
  • Loading branch information
ivan4th authored Oct 9, 2024
1 parent b4e4d99 commit dfa0cc4
Show file tree
Hide file tree
Showing 3 changed files with 276 additions and 376 deletions.
25 changes: 25 additions & 0 deletions decoder.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scale

import (
"encoding/binary"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -93,6 +94,30 @@ func DecodeByte(d *Decoder) (byte, int, error) {
return d.scratch[0], n, err
}

func DecodeUint16(d *Decoder) (uint16, int, error) {
n, err := d.read(d.scratch[:2])
if err != nil {
return 0, n, err
}
return binary.LittleEndian.Uint16(d.scratch[:2]), n, err
}

func DecodeUint32(d *Decoder) (uint32, int, error) {
n, err := d.read(d.scratch[:4])
if err != nil {
return 0, n, err
}
return binary.LittleEndian.Uint32(d.scratch[:4]), n, err
}

func DecodeUint64(d *Decoder) (uint64, int, error) {
n, err := d.read(d.scratch[:8])
if err != nil {
return 0, n, err
}
return binary.LittleEndian.Uint64(d.scratch[:8]), n, err
}

func DecodeCompact8(d *Decoder) (uint8, int, error) {
var (
value uint8
Expand Down
Loading

0 comments on commit dfa0cc4

Please sign in to comment.