Skip to content

Commit

Permalink
ParseNetwork helper
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Aug 26, 2024
1 parent 451d517 commit 4869e10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 7 additions & 0 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import (
var ErrNoData = errors.New("no data")
var ErrMapblockVersion = errors.New("mapblock version unsupported")

func ParseNetwork(ser_ver uint8, data []byte) (*types.MapBlock, error) {
offsetData := make([]byte, len(data)+1)
offsetData[0] = ser_ver
copy(offsetData[1:], data)
return Parse(offsetData)
}

func Parse(data []byte) (*types.MapBlock, error) {
if len(data) == 0 {
return nil, ErrNoData
Expand Down
6 changes: 1 addition & 5 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,7 @@ func TestParseNetworkBlock(t *testing.T) {
t.Error(err)
}

offsetData := make([]byte, len(data)+1)
offsetData[0] = 28
copy(offsetData[1:], data)

mb, err := Parse(offsetData)
mb, err := ParseNetwork(28, data)

if err != nil {
t.Error(err)
Expand Down

0 comments on commit 4869e10

Please sign in to comment.