Skip to content

Commit

Permalink
Merge pull request ipfs/go-merkledag#49 from RTradeLtd/get-pb-node
Browse files Browse the repository at this point in the history
Make getPBNode Public

This commit was moved from ipfs/go-merkledag@2c1a891
  • Loading branch information
Stebalien authored Oct 1, 2019
2 parents 50ed821 + 4a99c61 commit b6d5034
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ipld/merkledag/coding.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"sort"
"strings"

"github.com/ipfs/go-block-format"

blocks "github.com/ipfs/go-block-format"
pb "github.com/ipfs/go-merkledag/pb"

cid "github.com/ipfs/go-cid"
Expand Down Expand Up @@ -49,15 +48,18 @@ func (n *ProtoNode) unmarshal(encoded []byte) error {
// Marshal encodes a *Node instance into a new byte slice.
// The conversion uses an intermediate PBNode.
func (n *ProtoNode) Marshal() ([]byte, error) {
pbn := n.getPBNode()
pbn := n.GetPBNode()
data, err := pbn.Marshal()
if err != nil {
return data, fmt.Errorf("marshal failed. %v", err)
}
return data, nil
}

func (n *ProtoNode) getPBNode() *pb.PBNode {
// GetPBNode converts *ProtoNode into it's protocol buffer variant.
// If you plan on mutating the data of the original node, it is recommended
// that you call ProtoNode.Copy() before calling ProtoNode.GetPBNode()
func (n *ProtoNode) GetPBNode() *pb.PBNode {
pbn := &pb.PBNode{}
if len(n.links) > 0 {
pbn.Links = make([]*pb.PBLink, len(n.links))
Expand Down

0 comments on commit b6d5034

Please sign in to comment.