1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-23 21:47:52 +08:00

Rename Encoded() to EncodeProtobuf()

License: MIT
Signed-off-by: Mildred Ki'Lya <mildred-pub.git@mildred.fr>
This commit is contained in:
Mildred Ki'Lya
2016-02-25 07:35:28 +01:00
parent 1f5b76ac18
commit 7c11fe57cb
5 changed files with 13 additions and 13 deletions

View File

@ -68,9 +68,9 @@ func (n *Node) getPBNode() *pb.PBNode {
return pbn return pbn
} }
// Encoded returns the encoded raw data version of a Node instance. // EncodeProtobuf returns the encoded raw data version of a Node instance.
// It may use a cached encoded version, unless the force flag is given. // It may use a cached encoded version, unless the force flag is given.
func (n *Node) Encoded(force bool) ([]byte, error) { func (n *Node) EncodeProtobuf(force bool) ([]byte, error) {
sort.Stable(LinkSlice(n.Links)) // keep links sorted sort.Stable(LinkSlice(n.Links)) // keep links sorted
if n.encoded == nil || force { if n.encoded == nil || force {
var err error var err error

View File

@ -49,7 +49,7 @@ func (n *dagService) Add(nd *Node) (key.Key, error) {
return "", fmt.Errorf("dagService is nil") return "", fmt.Errorf("dagService is nil")
} }
d, err := nd.Encoded(false) d, err := nd.EncodeProtobuf(false)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -313,7 +313,7 @@ type Batch struct {
} }
func (t *Batch) Add(nd *Node) (key.Key, error) { func (t *Batch) Add(nd *Node) (key.Key, error) {
d, err := nd.Encoded(false) d, err := nd.EncodeProtobuf(false)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -64,7 +64,7 @@ func TestNode(t *testing.T) {
fmt.Println("-", l.Name, l.Size, l.Hash) fmt.Println("-", l.Name, l.Size, l.Hash)
} }
e, err := n.Encoded(false) e, err := n.EncodeProtobuf(false)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} else { } else {
@ -96,9 +96,9 @@ func TestNode(t *testing.T) {
} }
func SubtestNodeStat(t *testing.T, n *Node) { func SubtestNodeStat(t *testing.T, n *Node) {
enc, err := n.Encoded(true) enc, err := n.EncodeProtobuf(true)
if err != nil { if err != nil {
t.Error("n.Encoded(true) failed") t.Error("n.EncodeProtobuf(true) failed")
return return
} }

View File

@ -203,7 +203,7 @@ func (n *Node) UpdateNodeLink(name string, that *Node) (*Node, error) {
// Size returns the total size of the data addressed by node, // Size returns the total size of the data addressed by node,
// including the total sizes of references. // including the total sizes of references.
func (n *Node) Size() (uint64, error) { func (n *Node) Size() (uint64, error) {
b, err := n.Encoded(false) b, err := n.EncodeProtobuf(false)
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -217,7 +217,7 @@ func (n *Node) Size() (uint64, error) {
// Stat returns statistics on the node. // Stat returns statistics on the node.
func (n *Node) Stat() (*NodeStat, error) { func (n *Node) Stat() (*NodeStat, error) {
enc, err := n.Encoded(false) enc, err := n.EncodeProtobuf(false)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -244,8 +244,8 @@ func (n *Node) Stat() (*NodeStat, error) {
// Multihash hashes the encoded data of this node. // Multihash hashes the encoded data of this node.
func (n *Node) Multihash() (mh.Multihash, error) { func (n *Node) Multihash() (mh.Multihash, error) {
// Note: Encoded generates the hash and puts it in n.cached. // Note: EncodeProtobuf generates the hash and puts it in n.cached.
_, err := n.Encoded(false) _, err := n.EncodeProtobuf(false)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -258,7 +258,7 @@ func (dm *DagModifier) modifyDag(node *mdag.Node, offset uint64, data io.Reader)
node.Links[i].Hash = mh.Multihash(k) node.Links[i].Hash = mh.Multihash(k)
// Recache serialized node // Recache serialized node
_, err = node.Encoded(true) _, err = node.EncodeProtobuf(true)
if err != nil { if err != nil {
return "", false, err return "", false, err
} }
@ -489,7 +489,7 @@ func dagTruncate(ctx context.Context, nd *mdag.Node, size uint64, ds mdag.DAGSer
nd.Data = d nd.Data = d
// invalidate cache and recompute serialized data // invalidate cache and recompute serialized data
_, err = nd.Encoded(true) _, err = nd.EncodeProtobuf(true)
if err != nil { if err != nil {
return nil, err return nil, err
} }