Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make getPBNode Public #49

Merged
merged 2 commits into from
Oct 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions 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