Skip to content

Commit b60a0cd

Browse files
authored
Merge pull request #164 from cloudstruct/docs/protocol-common
docs: inline docs for protocol/common package
2 parents e3d7a30 + 95d2390 commit b60a0cd

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

protocol/common/types.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
1+
// The common package contains types used by multiple mini-protocols
12
package common
23

34
import (
45
"github.com/cloudstruct/go-ouroboros-network/utils"
56
"github.com/fxamacker/cbor/v2"
67
)
78

9+
// The Point type represents a point on the blockchain. It consists of a slot number and block hash
810
type Point struct {
911
// Tells the CBOR decoder to convert to/from a struct and a CBOR array
1012
_ struct{} `cbor:",toarray"`
1113
Slot uint64
1214
Hash []byte
1315
}
1416

17+
// NewPoint returns a Point object with the specified slot number and block hash
1518
func NewPoint(slot uint64, blockHash []byte) Point {
1619
return Point{
1720
Slot: slot,
1821
Hash: blockHash,
1922
}
2023
}
2124

25+
// NewPointOrigin returns an "empty" Point object which represents the origin of the blockchain
2226
func NewPointOrigin() Point {
2327
return Point{}
2428
}
2529

26-
// A "point" can sometimes be empty, but the CBOR library gets grumpy about this
27-
// when doing automatic decoding from an array, so we have to handle this case specially
30+
// UnmarshalCBOR is a helper function for decoding a Point object from CBOR. The object content can vary,
31+
// so we need to do some special handling when decoding. It is not intended to be called directly.
2832
func (p *Point) UnmarshalCBOR(data []byte) error {
2933
var tmp []interface{}
3034
if err := cbor.Unmarshal(data, &tmp); err != nil {
@@ -37,6 +41,8 @@ func (p *Point) UnmarshalCBOR(data []byte) error {
3741
return nil
3842
}
3943

44+
// MarshalCBOR is a helper function for encoding a Point object to CBOR. The object content can vary, so we
45+
// need to do some special handling when encoding. It is not intended to be called directly.
4046
func (p *Point) MarshalCBOR() ([]byte, error) {
4147
var data []interface{}
4248
if p.Slot == 0 && p.Hash == nil {

0 commit comments

Comments
 (0)