-
Notifications
You must be signed in to change notification settings - Fork 670
/
parse.go
40 lines (36 loc) · 1000 Bytes
/
parse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package block
import (
"fmt"
)
func Parse(bytes []byte) (Block, bool, error) {
var (
block Block
requireBanff bool
)
parsedVersion, err := apricotCodec.Unmarshal(bytes, &block)
if err != nil {
parsedVersion, err = banffCodec.Unmarshal(bytes, &block)
requireBanff = true
}
if err != nil {
return nil, false, err
}
if parsedVersion != codecVersion {
return nil, false, fmt.Errorf("expected codec version %d but got %d", codecVersion, parsedVersion)
}
return block, requireBanff, block.initialize(bytes)
}
func ParseHeader(bytes []byte) (Header, error) {
header := statelessHeader{}
parsedVersion, err := banffCodec.Unmarshal(bytes, &header)
if err != nil {
return nil, err
}
if parsedVersion != codecVersion {
return nil, fmt.Errorf("expected codec version %d but got %d", codecVersion, parsedVersion)
}
header.bytes = bytes
return &header, nil
}