func (n *ProtoNode) GetPBNode() *pb.PBNode {
	pbn := &pb.PBNode{}
	if len(n.links) > 0 {
		pbn.Links = make([]*pb.PBLink, len(n.links))
	}
	sort.Stable(LinkSlice(n.links))  
	for i, l := range n.links {
		pbn.Links[i] = &pb.PBLink{}
		pbn.Links[i].Name = &l.Name
		pbn.Links[i].Tsize = &l.Size
		if l.Cid.Defined() {
			pbn.Links[i].Hash = l.Cid.Bytes()
		}
	}
	if len(n.data) > 0 {
		pbn.Data = n.data
	}
	return pbn
}
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()
package merkledag
import (
	"fmt"
	"sort"
	"strings"
	blocks "github.com/ipfs/go-block-format"
	cid "github.com/ipfs/go-cid"
	format "github.com/ipfs/go-ipld-format"
	pb "github.com/ipfs/go-merkledag/pb"
	dagpb "github.com/ipld/go-codec-dagpb"
	ipld "github.com/ipld/go-ipld-prime"
	"github.com/ipld/go-ipld-prime/fluent/qp"
	cidlink "github.com/ipld/go-ipld-prime/linking/cid"
)
const _ = pb.DoNotUpgradeFileEverItWillChangeYourHashes
func unmarshal(encodedBytes []byte) (*ProtoNode, error) {
	nb := dagpb.Type.PBNode.NewBuilder()
	if err := dagpb.DecodeBytes(nb, encodedBytes); err != nil {
		return nil, err
	}
	nd := nb.Build()
	return fromImmutableNode(&immutableProtoNode{encodedBytes, nd.(dagpb.PBNode)}), nil
}
func fromImmutableNode(encoded *immutableProtoNode) *ProtoNode {
	n := new(ProtoNode)
	n.encoded = encoded
	if n.encoded.PBNode.Data.Exists() {
		n.data = n.encoded.PBNode.Data.Must().Bytes()
	}
	numLinks := n.encoded.PBNode.Links.Length()
	n.links = make([]*format.Link, numLinks)
	linkAllocs := make([]format.Link, numLinks)
	for i := int64(0); i < numLinks; i++ {
		next := n.encoded.PBNode.Links.Lookup(i)
		name := ""
		if next.FieldName().Exists() {
			name = next.FieldName().Must().String()
		}
		c := cid.Undef
		c = next.FieldHash().Link().(cidlink.Link).Cid
		size := uint64(0)
		if next.FieldTsize().Exists() {
			size = uint64(next.FieldTsize().Must().Int())
		}
		link := &linkAllocs[i]
		link.Name = name
		link.Size = size
		link.Cid = c
		n.links[i] = link
	}
	return n
}
func (n *ProtoNode) marshalImmutable() (*immutableProtoNode, error) {
	nd, err := qp.BuildMap(dagpb.Type.PBNode, 2, func(ma ipld.MapAssembler) {
		qp.MapEntry(ma, "Links", qp.List(int64(len(n.links)), func(la ipld.ListAssembler) {
			for _, link := range n.links {
				qp.ListEntry(la, qp.Map(3, func(ma ipld.MapAssembler) {
					if link.Cid.Defined() {
						qp.MapEntry(ma, "Hash", qp.Link(cidlink.Link{Cid: link.Cid}))
					}
					qp.MapEntry(ma, "Name", qp.String(link.Name))
					qp.MapEntry(ma, "Tsize", qp.Int(int64(link.Size)))
				}))
			}
		}))
		if n.data != nil {
			qp.MapEntry(ma, "Data", qp.Bytes(n.data))
		}
	})
	if err != nil {
		return nil, err
	}
	enc := make([]byte, 0, 1024)
	enc, err = dagpb.AppendEncode(enc, nd)
	if err != nil {
		return nil, err
	}
	return &immutableProtoNode{enc, nd.(dagpb.PBNode)}, nil
}
func (n *ProtoNode) Marshal() ([]byte, error) {
	enc, err := n.marshalImmutable()
	if err != nil {
		return nil, err
	}
	return enc.encoded, nil
}