Unverified Commit 2c1a891f authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #49 from RTradeLtd/get-pb-node

Make getPBNode Public
parents 3ecad706 c8d632c5
...@@ -5,8 +5,7 @@ import ( ...@@ -5,8 +5,7 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/ipfs/go-block-format" blocks "github.com/ipfs/go-block-format"
pb "github.com/ipfs/go-merkledag/pb" pb "github.com/ipfs/go-merkledag/pb"
cid "github.com/ipfs/go-cid" cid "github.com/ipfs/go-cid"
...@@ -49,7 +48,7 @@ func (n *ProtoNode) unmarshal(encoded []byte) error { ...@@ -49,7 +48,7 @@ func (n *ProtoNode) unmarshal(encoded []byte) error {
// Marshal encodes a *Node instance into a new byte slice. // Marshal encodes a *Node instance into a new byte slice.
// The conversion uses an intermediate PBNode. // The conversion uses an intermediate PBNode.
func (n *ProtoNode) Marshal() ([]byte, error) { func (n *ProtoNode) Marshal() ([]byte, error) {
pbn := n.getPBNode() pbn := n.GetPBNode()
data, err := pbn.Marshal() data, err := pbn.Marshal()
if err != nil { if err != nil {
return data, fmt.Errorf("marshal failed. %v", err) return data, fmt.Errorf("marshal failed. %v", err)
...@@ -57,7 +56,10 @@ func (n *ProtoNode) Marshal() ([]byte, error) { ...@@ -57,7 +56,10 @@ func (n *ProtoNode) Marshal() ([]byte, error) {
return data, nil 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{} pbn := &pb.PBNode{}
if len(n.links) > 0 { if len(n.links) > 0 {
pbn.Links = make([]*pb.PBLink, len(n.links)) pbn.Links = make([]*pb.PBLink, len(n.links))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment