Skip to content

Commit

Permalink
Revert length FromBytes changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGackstatter committed Mar 11, 2024
1 parent 5f56f3d commit b0e23ff
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions block_id.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions commitment_id.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion epoch_index.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type EpochIndex uint32

func EpochIndexFromBytes(b []byte) (EpochIndex, int, error) {
if len(b) < EpochIndexLength {
return 0, 0, ierrors.New("invalid epoch index size")
return 0, 0, ierrors.Errorf("invalid length for epoch index, expected at least %d bytes, got %d bytes", EpochIndexLength, len(b))
}

return EpochIndex(binary.LittleEndian.Uint32(b)), EpochIndexLength, nil
Expand Down
4 changes: 2 additions & 2 deletions gen/identifier.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func IsValid{{.Name}}(b []byte) error {

func {{.Name}}FromBytes(bytes []byte) ({{.Name}}, int, error) {
var {{.Receiver}} {{.Name}}
if err := IsValid{{.Name}}(bytes); err != nil {
return {{.Receiver}}, 0, err
if len(bytes) < {{.Name}}Length {
return {{.Receiver}}, 0, ierrors.Errorf("invalid length for {{firstLower .Name}}, expected at least %d bytes, got %d bytes", {{.Name}}Length, len(bytes))
}
copy({{.Receiver}}[:], bytes)

Expand Down
2 changes: 1 addition & 1 deletion gen/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type {{.Name}}Index uint32

func {{.Name}}IndexFromBytes(b []byte) ({{.Name}}Index, int, error) {
if len(b) < {{.Name}}IndexLength {
return 0, 0, ierrors.New("invalid {{firstLower .Name}} index size")
return 0, 0, ierrors.Errorf("invalid length for {{firstLower .Name}} index, expected at least %d bytes, got %d bytes", {{.Name}}IndexLength, len(b))
}

return {{.Name}}Index(binary.LittleEndian.Uint32(b)), {{.Name}}IndexLength, nil
Expand Down
4 changes: 2 additions & 2 deletions gen/slot_identifier.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ func IsValid{{.Name}}(b []byte) error {

// {{.Name}}FromBytes returns a new {{.Name}} represented by the passed bytes.
func {{.Name}}FromBytes(b []byte) ({{.Name}}, int, error) {
if err := IsValid{{.Name}}(b); err != nil {
return Empty{{.Name}}, 0, err
if len(b) < {{.Name}}Length {
return Empty{{.Name}}, 0, ierrors.Errorf("invalid length for {{firstLower .Name}}, expected at least %d bytes, got %d bytes", {{.Name}}Length, len(b))
}

return {{.Name}}(b), {{.Name}}Length, nil
Expand Down
4 changes: 2 additions & 2 deletions identifier.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions identifier_account.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions identifier_anchor.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions output_id.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions signed_transaction_id.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion slot_index.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type SlotIndex uint32

func SlotIndexFromBytes(b []byte) (SlotIndex, int, error) {
if len(b) < SlotIndexLength {
return 0, 0, ierrors.New("invalid slot index size")
return 0, 0, ierrors.Errorf("invalid length for slot index, expected at least %d bytes, got %d bytes", SlotIndexLength, len(b))
}

return SlotIndex(binary.LittleEndian.Uint32(b)), SlotIndexLength, nil
Expand Down
4 changes: 2 additions & 2 deletions transaction_id.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b0e23ff

Please sign in to comment.