From 1e82733d23a6d1acd7baf88ca420ae89cc235450 Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Thu, 4 Mar 2021 17:46:28 -0800 Subject: [PATCH 01/43] first commit This commit was moved from ipfs/go-unixfsnode@05d510928c79fb6c5b2c3be141cd58d94930fd2f --- unixfs/node/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 unixfs/node/README.md diff --git a/unixfs/node/README.md b/unixfs/node/README.md new file mode 100644 index 000000000..38f53eca6 --- /dev/null +++ b/unixfs/node/README.md @@ -0,0 +1 @@ +# go-unixfs-node From cd049e06f4afe47688afce90d17713a23f9694a1 Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Thu, 4 Mar 2021 20:40:05 -0800 Subject: [PATCH 02/43] feat(unixfsnode): initial implementation This commit was moved from ipfs/go-unixfsnode@f2af51ae85c1c96de2d72a78cfab6723af0d31c1 --- unixfs/node/README.md | 6 +- unixfs/node/link.go | 23 ++++ unixfs/node/node.go | 201 +++++++++++++++++++++++++++++++++++ unixfs/node/nodeprototype.go | 38 +++++++ unixfs/node/reification.go | 30 ++++++ 5 files changed, 297 insertions(+), 1 deletion(-) create mode 100644 unixfs/node/link.go create mode 100644 unixfs/node/node.go create mode 100644 unixfs/node/nodeprototype.go create mode 100644 unixfs/node/reification.go diff --git a/unixfs/node/README.md b/unixfs/node/README.md index 38f53eca6..675960209 100644 --- a/unixfs/node/README.md +++ b/unixfs/node/README.md @@ -1 +1,5 @@ -# go-unixfs-node +# go-unixfsnode + +This is an IPLD ADL that provides string based pathing for protobuf nodes. The top level node behaves like a map where LookupByString returns the Hash property on the Link in the protobufs list of Links whos Name property matches the key. This should enable selector traversals that work based of paths. + +Note that while it works internally with go-codec-dagpb, the Reify method (used to get a UnixFSNode from a DagPB node should actually work successfully with go-ipld-prime-proto nodes) \ No newline at end of file diff --git a/unixfs/node/link.go b/unixfs/node/link.go new file mode 100644 index 000000000..21eeaa277 --- /dev/null +++ b/unixfs/node/link.go @@ -0,0 +1,23 @@ +package unixfsnode + +import ( + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/schema" +) + +var _ ipld.Node = UnixFSLink(nil) +var _ schema.TypedNode = UnixFSLink(nil) +var _ schema.TypedLinkNode = UnixFSLink(nil) + +// UnixFSLink just adds a LinkTargetNodePrototype method to dagpb.Link so that you can cross +// link boundaries correctly in path traversals +type UnixFSLink = *_UnixFSLink + +type _UnixFSLink struct { + dagpb.Link +} + +func (n UnixFSLink) LinkTargetNodePrototype() ipld.NodePrototype { + return _UnixFSNode__Prototype{} +} diff --git a/unixfs/node/node.go b/unixfs/node/node.go new file mode 100644 index 000000000..df4cf90ac --- /dev/null +++ b/unixfs/node/node.go @@ -0,0 +1,201 @@ +package unixfsnode + +import ( + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/schema" +) + +var _ ipld.Node = UnixFSNode(nil) +var _ schema.TypedNode = UnixFSNode(nil) + +type UnixFSNode = *_UnixFSNode + +type _UnixFSNode struct { + _substrate dagpb.PBNode +} + +func (n UnixFSNode) Kind() ipld.Kind { + return n._substrate.Kind() +} + +// LookupByString looks for the key in the list of links with a matching name +func (n UnixFSNode) LookupByString(key string) (ipld.Node, error) { + links := n._substrate.FieldLinks() + link := lookup(links, key) + if link == nil { + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} + } + return link, nil +} + +func (n UnixFSNode) LookupByNode(key ipld.Node) (ipld.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} + +func (n UnixFSNode) LookupByIndex(idx int64) (ipld.Node, error) { + return n._substrate.LookupByIndex(idx) +} + +func (n UnixFSNode) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return n.LookupByString(seg.String()) +} + +func (n UnixFSNode) MapIterator() ipld.MapIterator { + return &UnixFSNode__MapItr{n._substrate.Links.Iterator()} +} + +// UnixFSNode map iterator iterates throught the links as if they were a map +// Note: for now it does return links with no name, where the key is just String("") +type UnixFSNode__MapItr struct { + _substrate *dagpb.PBLinks__Itr +} + +func (itr *UnixFSNode__MapItr) Next() (k ipld.Node, v ipld.Node, err error) { + _, next := itr._substrate.Next() + if next == nil { + return nil, nil, ipld.ErrIteratorOverread{} + } + if next.FieldName().Exists() { + return next.FieldName().Must(), &_UnixFSLink{next.FieldHash()}, nil + } + nb := dagpb.Type.String.NewBuilder() + err = nb.AssignString("") + if err != nil { + return nil, nil, err + } + s := nb.Build() + return s, next.FieldHash(), nil +} + +func (itr *UnixFSNode__MapItr) Done() bool { + return itr._substrate.Done() +} + +// ListIterator returns an iterator which yields key-value pairs +// traversing the node. +// If the node kind is anything other than a list, nil will be returned. +// +// The iterator will yield every entry in the list; that is, it +// can be expected that itr.Next will be called node.Length times +// before itr.Done becomes true. +func (n UnixFSNode) ListIterator() ipld.ListIterator { + return nil +} + +// Length returns the length of a list, or the number of entries in a map, +// or -1 if the node is not of list nor map kind. +func (n UnixFSNode) Length() int64 { + return n._substrate.FieldLinks().Length() +} + +func (n UnixFSNode) IsAbsent() bool { + return false +} + +func (n UnixFSNode) IsNull() bool { + return false +} + +func (n UnixFSNode) AsBool() (bool, error) { + return n._substrate.AsBool() +} + +func (n UnixFSNode) AsInt() (int64, error) { + return n._substrate.AsInt() +} + +func (n UnixFSNode) AsFloat() (float64, error) { + return n._substrate.AsFloat() +} + +func (n UnixFSNode) AsString() (string, error) { + return n._substrate.AsString() +} + +func (n UnixFSNode) AsBytes() ([]byte, error) { + return n._substrate.AsBytes() +} + +func (n UnixFSNode) AsLink() (ipld.Link, error) { + return n._substrate.AsLink() +} + +func (n UnixFSNode) Prototype() ipld.NodePrototype { + return _UnixFSNode__Prototype{} +} + +// satisfy schema.TypedNode +func (UnixFSNode) Type() schema.Type { + return nil /*TODO:typelit*/ +} + +func (n UnixFSNode) Representation() ipld.Node { + return n._substrate.Representation() +} + +// Native map accessors + +func (n UnixFSNode) Iterator() *UnixFSNode__Itr { + + return &UnixFSNode__Itr{n._substrate.Links.Iterator()} +} + +type UnixFSNode__Itr struct { + _substrate *dagpb.PBLinks__Itr +} + +func (itr *UnixFSNode__Itr) Next() (k dagpb.String, v UnixFSLink) { + _, next := itr._substrate.Next() + if next == nil { + return nil, nil + } + if next.FieldName().Exists() { + return next.FieldName().Must(), &_UnixFSLink{next.FieldHash()} + } + nb := dagpb.Type.String.NewBuilder() + err := nb.AssignString("") + if err != nil { + return nil, nil + } + s := nb.Build() + return s.(dagpb.String), &_UnixFSLink{next.FieldHash()} +} +func (itr *UnixFSNode__Itr) Done() bool { + return itr._substrate.Done() +} + +func (n UnixFSNode) Lookup(key dagpb.String) UnixFSLink { + return lookup(n._substrate.FieldLinks(), key.String()) +} + +// direct access to the links and data + +func (n UnixFSNode) FieldLinks() dagpb.PBLinks { + return n._substrate.FieldLinks() +} + +func (n UnixFSNode) FieldData() dagpb.MaybeBytes { + return n._substrate.FieldData() +} + +// we need to lookup by key in a list of dag pb links a fair amount, so just have +// a shortcut method +func lookup(links dagpb.PBLinks, key string) UnixFSLink { + li := links.Iterator() + for !li.Done() { + _, next := li.Next() + name := "" + if next.FieldName().Exists() { + name = next.FieldName().Must().String() + } + if key == name { + return &_UnixFSLink{next.FieldHash()} + } + } + return nil +} diff --git a/unixfs/node/nodeprototype.go b/unixfs/node/nodeprototype.go new file mode 100644 index 000000000..93847ec47 --- /dev/null +++ b/unixfs/node/nodeprototype.go @@ -0,0 +1,38 @@ +package unixfsnode + +import ( + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" +) + +// NodeBuilder for UnixFS Nodes -- note: this expects underlying data that +// has the same format as a normal dagpb node -- in fact, it uses the +// exact same builder but then wraps at the end + +var Type typeSlab + +type typeSlab struct { + UnixFSNode _UnixFSNode__Prototype +} + +type _UnixFSNode__Prototype struct{} + +func (_UnixFSNode__Prototype) NewBuilder() ipld.NodeBuilder { + var nb _UnixFSNode__Builder + nb.Reset() + return &nb +} + +type _UnixFSNode__Builder struct { + ipld.NodeBuilder +} + +func (nb *_UnixFSNode__Builder) Build() ipld.Node { + n := nb.NodeBuilder.Build().(dagpb.PBNode) + return &_UnixFSNode{_substrate: n} +} + +func (nb *_UnixFSNode__Builder) Reset() { + snb := dagpb.Type.PBNode.NewBuilder() + *nb = _UnixFSNode__Builder{snb} +} diff --git a/unixfs/node/reification.go b/unixfs/node/reification.go new file mode 100644 index 000000000..4115c76bc --- /dev/null +++ b/unixfs/node/reification.go @@ -0,0 +1,30 @@ +package unixfsnode + +import ( + "fmt" + + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" +) + +// Reify looks at an ipld Node and tries to interpret it as a UnixFSNode +// if successful, it returns the UnixFSNode +func Reify(maybePBNodeRoot ipld.Node) (ipld.Node, error) { + if pbNode, ok := maybePBNodeRoot.(dagpb.PBNode); ok { + return &_UnixFSNode{_substrate: pbNode}, nil + } + + // Shortcut didn't work. Process via the data model. + // The AssignNode method on the pb node already contains all the logic necessary for this, so we use that. + nb := dagpb.Type.PBNode.NewBuilder() + if err := nb.AssignNode(maybePBNodeRoot); err != nil { + return nil, fmt.Errorf("unixfsnode.Reify failed: data does not match expected shape for Protobuf Node: %w", err) + } + return &_UnixFSNode{nb.Build().(dagpb.PBNode)}, nil + +} + +// Substrate returns the underlying PBNode -- note: only the substrate will encode successfully to protobuf if writing +func (n UnixFSNode) Substrate() ipld.Node { + return n._substrate +} From eabd4756bdb72729301c600972085b19e470752b Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Wed, 31 Mar 2021 16:40:11 -0700 Subject: [PATCH 03/43] feat(data): add unixfs data node decoding add builders and utitlities for working with unixfs data protobufs This commit was moved from ipfs/go-unixfsnode@4574e4178ac71994d66d15f1004d28c7daf8b25c --- unixfs/node/data/builder/builder.go | 116 + unixfs/node/data/datatypes.go | 28 + unixfs/node/data/errors.go | 22 + unixfs/node/data/fixtures/directory.unixfs | 1 + unixfs/node/data/fixtures/directory/file.txt | 1 + unixfs/node/data/fixtures/file.txt | 1 + unixfs/node/data/fixtures/file.txt.unixfs | 2 + unixfs/node/data/fixtures/raw.unixfs | 2 + unixfs/node/data/fixtures/symlink.txt | 1 + unixfs/node/data/fixtures/symlink.txt.unixfs | 1 + unixfs/node/data/format_test.go | 376 ++ unixfs/node/data/gen/main.go | 87 + unixfs/node/data/ipldsch_minima.go | 50 + unixfs/node/data/ipldsch_satisfaction.go | 4609 ++++++++++++++++++ unixfs/node/data/ipldsch_types.go | 83 + unixfs/node/data/marshal.go | 84 + unixfs/node/data/permissions.go | 25 + unixfs/node/data/unmarshal.go | 304 ++ unixfs/node/data/wirenumbers.go | 17 + 19 files changed, 5810 insertions(+) create mode 100644 unixfs/node/data/builder/builder.go create mode 100644 unixfs/node/data/datatypes.go create mode 100644 unixfs/node/data/errors.go create mode 100644 unixfs/node/data/fixtures/directory.unixfs create mode 100644 unixfs/node/data/fixtures/directory/file.txt create mode 100644 unixfs/node/data/fixtures/file.txt create mode 100644 unixfs/node/data/fixtures/file.txt.unixfs create mode 100644 unixfs/node/data/fixtures/raw.unixfs create mode 100644 unixfs/node/data/fixtures/symlink.txt create mode 100644 unixfs/node/data/fixtures/symlink.txt.unixfs create mode 100644 unixfs/node/data/format_test.go create mode 100644 unixfs/node/data/gen/main.go create mode 100644 unixfs/node/data/ipldsch_minima.go create mode 100644 unixfs/node/data/ipldsch_satisfaction.go create mode 100644 unixfs/node/data/ipldsch_types.go create mode 100644 unixfs/node/data/marshal.go create mode 100644 unixfs/node/data/permissions.go create mode 100644 unixfs/node/data/unmarshal.go create mode 100644 unixfs/node/data/wirenumbers.go diff --git a/unixfs/node/data/builder/builder.go b/unixfs/node/data/builder/builder.go new file mode 100644 index 000000000..b52a1241c --- /dev/null +++ b/unixfs/node/data/builder/builder.go @@ -0,0 +1,116 @@ +package builder + +import ( + "errors" + "fmt" + "strconv" + "time" + + "github.com/ipfs/go-unixfsnode/data" + "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/fluent/qp" +) + +func BuildUnixFs(fn func(*Builder)) (data.UnixFSData, error) { + nd, err := qp.BuildMap(data.Type.UnixFSData, -1, func(ma ipld.MapAssembler) { + b := &Builder{MapAssembler: ma} + fn(b) + if !b.hasBlockSizes { + qp.MapEntry(ma, "BlockSizes", qp.List(0, func(ipld.ListAssembler) {})) + } + if !b.hasDataType { + qp.MapEntry(ma, "DataType", qp.Int(data.Data_File)) + } + }) + if err != nil { + return nil, err + } + return nd.(data.UnixFSData), nil +} + +type Builder struct { + ipld.MapAssembler + hasDataType bool + hasBlockSizes bool +} + +func DataType(b *Builder, dataType int64) { + _, ok := data.DataTypeNames[dataType] + if !ok { + panic(fmt.Errorf("Type: %d is not valid", dataType)) + } + qp.MapEntry(b.MapAssembler, "DataType", qp.Int(dataType)) + b.hasDataType = true +} + +func Data(b *Builder, data []byte) { + qp.MapEntry(b.MapAssembler, "Data", qp.Bytes(data)) + +} + +func FileSize(b *Builder, fileSize uint64) { + qp.MapEntry(b.MapAssembler, "FileSize", qp.Int(int64(fileSize))) +} + +func BlockSizes(b *Builder, blockSizes []uint64) { + qp.MapEntry(b.MapAssembler, "BlockSizes", qp.List(int64(len(blockSizes)), func(la ipld.ListAssembler) { + for _, bs := range blockSizes { + qp.ListEntry(la, qp.Int(int64(bs))) + } + })) + b.hasBlockSizes = true +} + +func HashFunc(b *Builder, hashFunc uint64) { + qp.MapEntry(b.MapAssembler, "HashFunc", qp.Int(int64(hashFunc))) +} + +func Fanout(b *Builder, fanout uint64) { + qp.MapEntry(b.MapAssembler, "Fanout", qp.Int(int64(fanout))) +} + +func Permissions(b *Builder, mode int) { + mode = mode & 0xFFF + qp.MapEntry(b.MapAssembler, "Mode", qp.Int(int64(mode))) +} + +func parseModeString(modeString string) (uint64, error) { + if len(modeString) > 0 && modeString[0] == '0' { + return strconv.ParseUint(modeString, 8, 32) + } + return strconv.ParseUint(modeString, 10, 32) +} + +func PermissionsString(b *Builder, modeString string) { + mode64, err := parseModeString(modeString) + if err != nil { + panic(err) + } + mode64 = mode64 & 0xFFF + qp.MapEntry(b.MapAssembler, "Mode", qp.Int(int64(mode64))) +} + +func Mtime(b *Builder, fn func(tb TimeBuilder)) { + qp.MapEntry(b.MapAssembler, "Mtime", qp.Map(-1, func(ma ipld.MapAssembler) { + fn(ma) + })) +} + +type TimeBuilder ipld.MapAssembler + +func Time(ma TimeBuilder, t time.Time) { + Seconds(ma, t.Unix()) + FractionalNanoseconds(ma, int32(t.Nanosecond())) +} + +func Seconds(ma TimeBuilder, seconds int64) { + qp.MapEntry(ma, "Seconds", qp.Int(seconds)) + +} + +func FractionalNanoseconds(ma TimeBuilder, nanoseconds int32) { + if nanoseconds < 0 || nanoseconds > 999999999 { + panic(errors.New("mtime-nsecs must be within the range [0,999999999]")) + } + qp.MapEntry(ma, "FractionalNanoseconds", qp.Int(int64(nanoseconds))) +} diff --git a/unixfs/node/data/datatypes.go b/unixfs/node/data/datatypes.go new file mode 100644 index 000000000..9acab920b --- /dev/null +++ b/unixfs/node/data/datatypes.go @@ -0,0 +1,28 @@ +package data + +const ( + Data_Raw int64 = 0 + Data_Directory int64 = 1 + Data_File int64 = 2 + Data_Metadata int64 = 3 + Data_Symlink int64 = 4 + Data_HAMTShard int64 = 5 +) + +var DataTypeNames = map[int64]string{ + Data_Raw: "Raw", + Data_Directory: "Directory", + Data_File: "File", + Data_Metadata: "Metadata", + Data_Symlink: "Symlink", + Data_HAMTShard: "HAMTShard", +} + +var DataTypeValues = map[string]int64{ + "Raw": Data_Raw, + "Directory": Data_Directory, + "File": Data_File, + "Metadata": Data_Metadata, + "Symlink": Data_Symlink, + "HAMTShard": Data_HAMTShard, +} diff --git a/unixfs/node/data/errors.go b/unixfs/node/data/errors.go new file mode 100644 index 000000000..4a61dc66f --- /dev/null +++ b/unixfs/node/data/errors.go @@ -0,0 +1,22 @@ +package data + +import ( + "fmt" +) + +type ErrWrongNodeType struct { + Expected int64 + Actual int64 +} + +func (e ErrWrongNodeType) Error() string { + expectedName, ok := DataTypeNames[e.Expected] + if !ok { + expectedName = "Unknown Type" + } + actualName, ok := DataTypeNames[e.Actual] + if !ok { + actualName = "Unknown Type" + } + return fmt.Sprintf("Incorrect Node Type: (UnixFSData) expected type: %s, actual type: %s", expectedName, actualName) +} diff --git a/unixfs/node/data/fixtures/directory.unixfs b/unixfs/node/data/fixtures/directory.unixfs new file mode 100644 index 000000000..e19a122a5 --- /dev/null +++ b/unixfs/node/data/fixtures/directory.unixfs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/unixfs/node/data/fixtures/directory/file.txt b/unixfs/node/data/fixtures/directory/file.txt new file mode 100644 index 000000000..551a8b668 --- /dev/null +++ b/unixfs/node/data/fixtures/directory/file.txt @@ -0,0 +1 @@ +Hello UnixFS diff --git a/unixfs/node/data/fixtures/file.txt b/unixfs/node/data/fixtures/file.txt new file mode 100644 index 000000000..551a8b668 --- /dev/null +++ b/unixfs/node/data/fixtures/file.txt @@ -0,0 +1 @@ +Hello UnixFS diff --git a/unixfs/node/data/fixtures/file.txt.unixfs b/unixfs/node/data/fixtures/file.txt.unixfs new file mode 100644 index 000000000..3ea1525b9 --- /dev/null +++ b/unixfs/node/data/fixtures/file.txt.unixfs @@ -0,0 +1,2 @@ + Hello UnixFS + \ No newline at end of file diff --git a/unixfs/node/data/fixtures/raw.unixfs b/unixfs/node/data/fixtures/raw.unixfs new file mode 100644 index 000000000..3ea1525b9 --- /dev/null +++ b/unixfs/node/data/fixtures/raw.unixfs @@ -0,0 +1,2 @@ + Hello UnixFS + \ No newline at end of file diff --git a/unixfs/node/data/fixtures/symlink.txt b/unixfs/node/data/fixtures/symlink.txt new file mode 100644 index 000000000..551a8b668 --- /dev/null +++ b/unixfs/node/data/fixtures/symlink.txt @@ -0,0 +1 @@ +Hello UnixFS diff --git a/unixfs/node/data/fixtures/symlink.txt.unixfs b/unixfs/node/data/fixtures/symlink.txt.unixfs new file mode 100644 index 000000000..87cc8aad9 --- /dev/null +++ b/unixfs/node/data/fixtures/symlink.txt.unixfs @@ -0,0 +1 @@ +file.txt \ No newline at end of file diff --git a/unixfs/node/data/format_test.go b/unixfs/node/data/format_test.go new file mode 100644 index 000000000..f9096aab4 --- /dev/null +++ b/unixfs/node/data/format_test.go @@ -0,0 +1,376 @@ +package data_test + +// adapted from https://github.com/ipfs/js-ipfs-unixfs/blob/master/packages/ipfs-unixfs/test/unixfs-format.spec.js + +import ( + "io/ioutil" + "os" + "path" + "runtime" + "strconv" + "testing" + "time" + + . "github.com/ipfs/go-unixfsnode/data" + "github.com/ipfs/go-unixfsnode/data/builder" + "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/fluent/qp" + "github.com/stretchr/testify/require" +) + +func loadFixture(name string) []byte { + _, filename, _, _ := runtime.Caller(0) + + f, err := os.Open(path.Join(path.Dir(filename), "fixtures", name)) + if err != nil { + panic(err) + } + data, err := ioutil.ReadAll(f) + if err != nil { + panic(err) + } + return data +} + +var raw = loadFixture("raw.unixfs") +var directory = loadFixture("directory.unixfs") +var file = loadFixture("file.txt.unixfs") +var symlink = loadFixture("symlink.txt.unixfs") + +func TestUnixfsFormat(t *testing.T) { + t.Run("defaults to file", func(t *testing.T) { + data, err := builder.BuildUnixFs(func(*builder.Builder) {}) + require.NoError(t, err) + require.Equal(t, Data_File, data.FieldDataType().Int()) + marshaled := EncodeUnixFSData(data) + unmarshaled, err := DecodeUnixFSData(marshaled) + require.NoError(t, err) + require.Equal(t, unmarshaled.FieldDataType(), data.FieldDataType()) + require.Equal(t, unmarshaled.FieldData(), data.FieldData()) + require.Equal(t, unmarshaled.FieldBlockSizes(), data.FieldBlockSizes()) + require.Equal(t, unmarshaled.FieldFileSize(), data.FieldFileSize()) + }) + + t.Run("raw", func(t *testing.T) { + data, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_Raw) + builder.Data(b, []byte("bananas")) + }) + require.NoError(t, err) + marshaled := EncodeUnixFSData(data) + unmarshaled, err := DecodeUnixFSData(marshaled) + require.NoError(t, err) + require.Equal(t, unmarshaled.FieldDataType(), data.FieldDataType()) + require.Equal(t, unmarshaled.FieldData(), data.FieldData()) + require.Equal(t, unmarshaled.FieldBlockSizes(), data.FieldBlockSizes()) + require.Equal(t, unmarshaled.FieldFileSize(), data.FieldFileSize()) + }) + + t.Run("directory", func(t *testing.T) { + data, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_Directory) + }) + require.NoError(t, err) + marshaled := EncodeUnixFSData(data) + unmarshaled, err := DecodeUnixFSData(marshaled) + require.NoError(t, err) + require.Equal(t, unmarshaled.FieldDataType(), data.FieldDataType()) + require.Equal(t, unmarshaled.FieldData(), data.FieldData()) + require.Equal(t, unmarshaled.FieldBlockSizes(), data.FieldBlockSizes()) + require.Equal(t, unmarshaled.FieldFileSize(), data.FieldFileSize()) + }) + + t.Run("HAMTShard", func(t *testing.T) { + data, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_HAMTShard) + }) + require.NoError(t, err) + marshaled := EncodeUnixFSData(data) + unmarshaled, err := DecodeUnixFSData(marshaled) + require.NoError(t, err) + require.Equal(t, unmarshaled.FieldDataType(), data.FieldDataType()) + require.Equal(t, unmarshaled.FieldData(), data.FieldData()) + require.Equal(t, unmarshaled.FieldBlockSizes(), data.FieldBlockSizes()) + require.Equal(t, unmarshaled.FieldFileSize(), data.FieldFileSize()) + }) + + t.Run("file", func(t *testing.T) { + data, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_File) + builder.Data(b, []byte("batata")) + }) + require.NoError(t, err) + marshaled := EncodeUnixFSData(data) + unmarshaled, err := DecodeUnixFSData(marshaled) + require.NoError(t, err) + require.Equal(t, unmarshaled.FieldDataType(), data.FieldDataType()) + require.Equal(t, unmarshaled.FieldData(), data.FieldData()) + require.Equal(t, unmarshaled.FieldBlockSizes(), data.FieldBlockSizes()) + require.Equal(t, unmarshaled.FieldFileSize(), data.FieldFileSize()) + }) + + t.Run("file add blocksize", func(t *testing.T) { + data, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_File) + builder.BlockSizes(b, []uint64{256}) + }) + require.NoError(t, err) + marshaled := EncodeUnixFSData(data) + unmarshaled, err := DecodeUnixFSData(marshaled) + require.NoError(t, err) + require.Equal(t, unmarshaled.FieldDataType(), data.FieldDataType()) + require.Equal(t, unmarshaled.FieldData(), data.FieldData()) + require.Equal(t, unmarshaled.FieldBlockSizes(), data.FieldBlockSizes()) + require.Equal(t, unmarshaled.FieldFileSize(), data.FieldFileSize()) + }) + + t.Run("mode", func(t *testing.T) { + mode, err := strconv.ParseInt("0555", 8, 32) + require.NoError(t, err) + data, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_File) + builder.Permissions(b, int(mode)) + }) + require.NoError(t, err) + unmarshaled, err := DecodeUnixFSData(EncodeUnixFSData(data)) + require.NoError(t, err) + require.True(t, unmarshaled.FieldMode().Exists()) + require.Equal(t, mode, unmarshaled.FieldMode().Must().Int()) + }) + + t.Run("default mode for files", func(t *testing.T) { + data, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_File) + }) + require.NoError(t, err) + unmarshaled, err := DecodeUnixFSData(EncodeUnixFSData(data)) + require.NoError(t, err) + + require.Equal(t, 0o0644, unmarshaled.Permissions()) + }) + + t.Run("default mode for directories", func(t *testing.T) { + data, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_Directory) + }) + require.NoError(t, err) + unmarshaled, err := DecodeUnixFSData(EncodeUnixFSData(data)) + require.NoError(t, err) + + require.Equal(t, 0o0755, unmarshaled.Permissions()) + }) + + t.Run("default mode for hamt shards", func(t *testing.T) { + data, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_HAMTShard) + }) + require.NoError(t, err) + unmarshaled, err := DecodeUnixFSData(EncodeUnixFSData(data)) + require.NoError(t, err) + + require.Equal(t, 0o0755, unmarshaled.Permissions()) + }) + + t.Run("mode as string", func(t *testing.T) { + mode, err := strconv.ParseInt("0555", 8, 32) + require.NoError(t, err) + data, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_File) + builder.PermissionsString(b, "0555") + }) + require.NoError(t, err) + unmarshaled, err := DecodeUnixFSData(EncodeUnixFSData(data)) + require.NoError(t, err) + require.True(t, unmarshaled.FieldMode().Exists()) + require.Equal(t, mode, unmarshaled.FieldMode().Must().Int()) + }) + + t.Run("mtime", func(t *testing.T) { + data, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_File) + builder.Mtime(b, func(tb builder.TimeBuilder) { + builder.Seconds(tb, 5) + }) + }) + require.NoError(t, err) + marshaled := EncodeUnixFSData(data) + unmarshaled, err := DecodeUnixFSData(marshaled) + require.NoError(t, err) + require.Equal(t, unmarshaled.FieldMtime(), data.FieldMtime()) + }) + + t.Run("mtime from time.Time", func(t *testing.T) { + now := time.Now() + seconds := now.Unix() + nanosecond := now.Nanosecond() + + data, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_File) + builder.Mtime(b, func(tb builder.TimeBuilder) { + builder.Time(tb, now) + }) + }) + require.NoError(t, err) + marshaled := EncodeUnixFSData(data) + unmarshaled, err := DecodeUnixFSData(marshaled) + require.NoError(t, err) + require.True(t, unmarshaled.FieldMtime().Exists()) + mtime := unmarshaled.FieldMtime().Must() + require.Equal(t, seconds, mtime.FieldSeconds().Int()) + require.True(t, mtime.FieldFractionalNanoseconds().Exists()) + require.Equal(t, int64(nanosecond), mtime.FieldFractionalNanoseconds().Must().Int()) + }) + + t.Run("omits default file mode from protobuf", func(t *testing.T) { + data, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_File) + builder.Permissions(b, 0o0644) + }) + require.NoError(t, err) + marshaled := EncodeUnixFSData(data) + unmarshaled, err := DecodeUnixFSData(marshaled) + require.NoError(t, err) + + require.False(t, unmarshaled.FieldMode().Exists()) + require.Equal(t, 0o644, unmarshaled.Permissions()) + + }) + + t.Run("omits default directory mode from protobuf", func(t *testing.T) { + data, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_Directory) + builder.Permissions(b, 0o0755) + }) + require.NoError(t, err) + marshaled := EncodeUnixFSData(data) + unmarshaled, err := DecodeUnixFSData(marshaled) + require.NoError(t, err) + + require.False(t, unmarshaled.FieldMode().Exists()) + require.Equal(t, 0o0755, unmarshaled.Permissions()) + }) + + t.Run("respects high bits in mode read from buffer", func(t *testing.T) { + mode := 0o0100644 // similar to output from fs.stat + nd, err := qp.BuildMap(Type.UnixFSData, -1, func(ma ipld.MapAssembler) { + qp.MapEntry(ma, "DataType", qp.Int(Data_File)) + qp.MapEntry(ma, "BlockSizes", qp.List(0, func(ipld.ListAssembler) {})) + qp.MapEntry(ma, "Mode", qp.Int(int64(mode))) + }) + require.NoError(t, err) + und, ok := nd.(UnixFSData) + require.True(t, ok) + + marshaled := EncodeUnixFSData(und) + unmarshaled, err := DecodeUnixFSData(marshaled) + require.NoError(t, err) + require.Equal(t, 0o0644, unmarshaled.Permissions()) + require.True(t, unmarshaled.FieldMode().Exists()) + require.Equal(t, int64(mode), unmarshaled.FieldMode().Must().Int()) + + }) + + t.Run("ignores high bits in mode passed to constructor", func(t *testing.T) { + mode := 0o0100644 // similar to output from fs.stat + entry, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_File) + builder.Permissions(b, mode) + }) + require.NoError(t, err) + require.True(t, entry.FieldMode().Exists()) + require.Equal(t, 0o644, entry.Permissions()) + // should have truncated mode to bits in the version of the spec this module supports + + marshaled := EncodeUnixFSData(entry) + unmarshaled, err := DecodeUnixFSData(marshaled) + require.NoError(t, err) + + require.False(t, unmarshaled.FieldMode().Exists()) + require.Equal(t, 0o644, unmarshaled.Permissions()) + }) + + // figuring out what is this metadata for https://github.com/ipfs/js-ipfs-data-importing/issues/3#issuecomment-182336526 + t.Run("metadata", func(t *testing.T) { + data, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_Metadata) + }) + require.NoError(t, err) + + marshaled := EncodeUnixFSData(data) + unmarshaled, err := DecodeUnixFSData(marshaled) + require.NoError(t, err) + + require.Equal(t, Data_Metadata, unmarshaled.FieldDataType().Int()) + }) + + t.Run("symlink", func(t *testing.T) { + data, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_Symlink) + }) + require.NoError(t, err) + marshaled := EncodeUnixFSData(data) + unmarshaled, err := DecodeUnixFSData(marshaled) + require.NoError(t, err) + require.Equal(t, unmarshaled.FieldDataType(), data.FieldDataType()) + require.Equal(t, unmarshaled.FieldData(), data.FieldData()) + require.Equal(t, unmarshaled.FieldBlockSizes(), data.FieldBlockSizes()) + require.Equal(t, unmarshaled.FieldFileSize(), data.FieldFileSize()) + }) + + t.Run("invalid type", func(t *testing.T) { + _, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, 9999) + }) + require.EqualError(t, err, "Type: 9999 is not valid") + }) +} + +func TestInterop(t *testing.T) { + t.Run("raw", func(t *testing.T) { + unmarshaled, err := DecodeUnixFSData(raw) + require.NoError(t, err) + + require.True(t, unmarshaled.FieldData().Exists()) + require.Equal(t, []byte("Hello UnixFS\n"), unmarshaled.FieldData().Must().Bytes()) + require.Equal(t, Data_File, unmarshaled.FieldDataType().Int()) + require.Equal(t, raw, EncodeUnixFSData(unmarshaled)) + }) + + t.Run("directory", func(t *testing.T) { + unmarshaled, err := DecodeUnixFSData(directory) + require.NoError(t, err) + + require.False(t, unmarshaled.FieldData().Exists()) + require.Equal(t, Data_Directory, unmarshaled.FieldDataType().Int()) + require.Equal(t, directory, EncodeUnixFSData(unmarshaled)) + }) + + t.Run("file", func(t *testing.T) { + unmarshaled, err := DecodeUnixFSData(file) + require.NoError(t, err) + + require.True(t, unmarshaled.FieldData().Exists()) + require.Equal(t, []byte("Hello UnixFS\n"), unmarshaled.FieldData().Must().Bytes()) + require.Equal(t, Data_File, unmarshaled.FieldDataType().Int()) + require.Equal(t, file, EncodeUnixFSData(unmarshaled)) + }) + + t.Run("symlink", func(t *testing.T) { + unmarshaled, err := DecodeUnixFSData(symlink) + require.NoError(t, err) + + require.Equal(t, []byte("file.txt"), unmarshaled.FieldData().Must().Bytes()) + require.Equal(t, Data_Symlink, unmarshaled.FieldDataType().Int()) + require.Equal(t, symlink, EncodeUnixFSData(unmarshaled)) + }) + + t.Run("empty", func(t *testing.T) { + data, err := builder.BuildUnixFs(func(b *builder.Builder) { + builder.DataType(b, Data_File) + }) + require.NoError(t, err) + marshaled := EncodeUnixFSData(data) + + require.Equal(t, []byte{0x08, 0x02}, marshaled) + }) +} diff --git a/unixfs/node/data/gen/main.go b/unixfs/node/data/gen/main.go new file mode 100644 index 000000000..96c6f303a --- /dev/null +++ b/unixfs/node/data/gen/main.go @@ -0,0 +1,87 @@ +package main + +import ( + "fmt" + "os" + + "github.com/ipld/go-ipld-prime/schema" + gengo "github.com/ipld/go-ipld-prime/schema/gen/go" +) + +func main() { + ts := schema.TypeSystem{} + ts.Init() + adjCfg := &gengo.AdjunctCfg{} + + pkgName := "data" + + ts.Accumulate(schema.SpawnString("String")) + ts.Accumulate(schema.SpawnInt("Int")) + ts.Accumulate(schema.SpawnBytes("Bytes")) + + ts.Accumulate(schema.SpawnList("BlockSizes", "Int", false)) + + /* + type UnixTime struct { + seconds Int + fractionalNanoseconds Int + } + */ + ts.Accumulate(schema.SpawnStruct("UnixTime", + []schema.StructField{ + schema.SpawnStructField("Seconds", "Int", false, false), + schema.SpawnStructField("FractionalNanoseconds", "Int", true, false), + }, + schema.SpawnStructRepresentationMap(nil), + )) + + /* + type UnixFSData struct { + dataType Int + data optional Bytes + filesize optional Int; + blocksizes [Int] + + hashType optional Int + fanout optional Int + mode optional Int + mtime optional UnixTime + } representation map + */ + + ts.Accumulate(schema.SpawnStruct("UnixFSData", + []schema.StructField{ + schema.SpawnStructField("DataType", "Int", false, false), + schema.SpawnStructField("Data", "Bytes", true, false), + schema.SpawnStructField("FileSize", "Int", true, false), + schema.SpawnStructField("BlockSizes", "BlockSizes", false, false), + schema.SpawnStructField("HashType", "Int", true, false), + schema.SpawnStructField("Fanout", "Int", true, false), + schema.SpawnStructField("Mode", "Int", true, false), + schema.SpawnStructField("Mtime", "UnixTime", true, false), + }, + schema.SpawnStructRepresentationMap(nil), + )) + + /* + type UnixFSMetadata struct { + mimeType optional String + } representation map + */ + + ts.Accumulate(schema.SpawnStruct("UnixFSMetadata", + []schema.StructField{ + schema.SpawnStructField("MimeType", "String", true, false), + }, + schema.SpawnStructRepresentationMap(nil), + )) + + if errs := ts.ValidateGraph(); errs != nil { + for _, err := range errs { + fmt.Printf("- %s\n", err) + } + os.Exit(1) + } + + gengo.Generate(".", pkgName, ts, adjCfg) +} diff --git a/unixfs/node/data/ipldsch_minima.go b/unixfs/node/data/ipldsch_minima.go new file mode 100644 index 000000000..64b5433c5 --- /dev/null +++ b/unixfs/node/data/ipldsch_minima.go @@ -0,0 +1,50 @@ +package data + +// Code generated by go-ipld-prime gengo. DO NOT EDIT. + +import ( + "fmt" + + "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/schema" +) + +const ( + midvalue = schema.Maybe(4) + allowNull = schema.Maybe(5) +) + +type maState uint8 + +const ( + maState_initial maState = iota + maState_midKey + maState_expectValue + maState_midValue + maState_finished +) + +type laState uint8 + +const ( + laState_initial laState = iota + laState_midValue + laState_finished +) +type _ErrorThunkAssembler struct { + e error +} + +func (ea _ErrorThunkAssembler) BeginMap(_ int64) (ipld.MapAssembler, error) { return nil, ea.e } +func (ea _ErrorThunkAssembler) BeginList(_ int64) (ipld.ListAssembler, error) { return nil, ea.e } +func (ea _ErrorThunkAssembler) AssignNull() error { return ea.e } +func (ea _ErrorThunkAssembler) AssignBool(bool) error { return ea.e } +func (ea _ErrorThunkAssembler) AssignInt(int64) error { return ea.e } +func (ea _ErrorThunkAssembler) AssignFloat(float64) error { return ea.e } +func (ea _ErrorThunkAssembler) AssignString(string) error { return ea.e } +func (ea _ErrorThunkAssembler) AssignBytes([]byte) error { return ea.e } +func (ea _ErrorThunkAssembler) AssignLink(ipld.Link) error { return ea.e } +func (ea _ErrorThunkAssembler) AssignNode(ipld.Node) error { return ea.e } +func (ea _ErrorThunkAssembler) Prototype() ipld.NodePrototype { + panic(fmt.Errorf("cannot get prototype from error-carrying assembler: already derailed with error: %w", ea.e)) +} diff --git a/unixfs/node/data/ipldsch_satisfaction.go b/unixfs/node/data/ipldsch_satisfaction.go new file mode 100644 index 000000000..2907b2445 --- /dev/null +++ b/unixfs/node/data/ipldsch_satisfaction.go @@ -0,0 +1,4609 @@ +package data + +// Code generated by go-ipld-prime gengo. DO NOT EDIT. + +import ( + ipld "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/node/mixins" + "github.com/ipld/go-ipld-prime/schema" +) + +func (n *_BlockSizes) Lookup(idx int64) Int { + if n.Length() <= idx { + return nil + } + v := &n.x[idx] + return v +} +func (n *_BlockSizes) LookupMaybe(idx int64) MaybeInt { + if n.Length() <= idx { + return nil + } + v := &n.x[idx] + return &_Int__Maybe{ + m: schema.Maybe_Value, + v: v, + } +} + +var _BlockSizes__valueAbsent = _Int__Maybe{m: schema.Maybe_Absent} + +func (n BlockSizes) Iterator() *BlockSizes__Itr { + return &BlockSizes__Itr{n, 0} +} + +type BlockSizes__Itr struct { + n BlockSizes + idx int +} + +func (itr *BlockSizes__Itr) Next() (idx int64, v Int) { + if itr.idx >= len(itr.n.x) { + return -1, nil + } + idx = int64(itr.idx) + v = &itr.n.x[itr.idx] + itr.idx++ + return +} +func (itr *BlockSizes__Itr) Done() bool { + return itr.idx >= len(itr.n.x) +} + +type _BlockSizes__Maybe struct { + m schema.Maybe + v BlockSizes +} +type MaybeBlockSizes = *_BlockSizes__Maybe + +func (m MaybeBlockSizes) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeBlockSizes) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeBlockSizes) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeBlockSizes) AsNode() ipld.Node { + switch m.m { + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") + } +} +func (m MaybeBlockSizes) Must() BlockSizes { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return m.v +} + +var _ ipld.Node = (BlockSizes)(&_BlockSizes{}) +var _ schema.TypedNode = (BlockSizes)(&_BlockSizes{}) + +func (BlockSizes) Kind() ipld.Kind { + return ipld.Kind_List +} +func (BlockSizes) LookupByString(string) (ipld.Node, error) { + return mixins.List{"data.BlockSizes"}.LookupByString("") +} +func (n BlockSizes) LookupByNode(k ipld.Node) (ipld.Node, error) { + idx, err := k.AsInt() + if err != nil { + return nil, err + } + return n.LookupByIndex(idx) +} +func (n BlockSizes) LookupByIndex(idx int64) (ipld.Node, error) { + if n.Length() <= idx { + return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfInt(idx)} + } + v := &n.x[idx] + return v, nil +} +func (n BlockSizes) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + i, err := seg.Index() + if err != nil { + return nil, ipld.ErrInvalidSegmentForList{TypeName: "data.BlockSizes", TroubleSegment: seg, Reason: err} + } + return n.LookupByIndex(i) +} +func (BlockSizes) MapIterator() ipld.MapIterator { + return nil +} +func (n BlockSizes) ListIterator() ipld.ListIterator { + return &_BlockSizes__ListItr{n, 0} +} + +type _BlockSizes__ListItr struct { + n BlockSizes + idx int +} + +func (itr *_BlockSizes__ListItr) Next() (idx int64, v ipld.Node, _ error) { + if itr.idx >= len(itr.n.x) { + return -1, nil, ipld.ErrIteratorOverread{} + } + idx = int64(itr.idx) + x := &itr.n.x[itr.idx] + v = x + itr.idx++ + return +} +func (itr *_BlockSizes__ListItr) Done() bool { + return itr.idx >= len(itr.n.x) +} + +func (n BlockSizes) Length() int64 { + return int64(len(n.x)) +} +func (BlockSizes) IsAbsent() bool { + return false +} +func (BlockSizes) IsNull() bool { + return false +} +func (BlockSizes) AsBool() (bool, error) { + return mixins.List{"data.BlockSizes"}.AsBool() +} +func (BlockSizes) AsInt() (int64, error) { + return mixins.List{"data.BlockSizes"}.AsInt() +} +func (BlockSizes) AsFloat() (float64, error) { + return mixins.List{"data.BlockSizes"}.AsFloat() +} +func (BlockSizes) AsString() (string, error) { + return mixins.List{"data.BlockSizes"}.AsString() +} +func (BlockSizes) AsBytes() ([]byte, error) { + return mixins.List{"data.BlockSizes"}.AsBytes() +} +func (BlockSizes) AsLink() (ipld.Link, error) { + return mixins.List{"data.BlockSizes"}.AsLink() +} +func (BlockSizes) Prototype() ipld.NodePrototype { + return _BlockSizes__Prototype{} +} + +type _BlockSizes__Prototype struct{} + +func (_BlockSizes__Prototype) NewBuilder() ipld.NodeBuilder { + var nb _BlockSizes__Builder + nb.Reset() + return &nb +} + +type _BlockSizes__Builder struct { + _BlockSizes__Assembler +} + +func (nb *_BlockSizes__Builder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_BlockSizes__Builder) Reset() { + var w _BlockSizes + var m schema.Maybe + *nb = _BlockSizes__Builder{_BlockSizes__Assembler{w: &w, m: &m}} +} + +type _BlockSizes__Assembler struct { + w *_BlockSizes + m *schema.Maybe + state laState + + cm schema.Maybe + va _Int__Assembler +} + +func (na *_BlockSizes__Assembler) reset() { + na.state = laState_initial + na.va.reset() +} +func (_BlockSizes__Assembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { + return mixins.ListAssembler{"data.BlockSizes"}.BeginMap(0) +} +func (na *_BlockSizes__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if sizeHint < 0 { + sizeHint = 0 + } + if na.w == nil { + na.w = &_BlockSizes{} + } + if sizeHint > 0 { + na.w.x = make([]_Int, 0, sizeHint) + } + return na, nil +} +func (na *_BlockSizes__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.ListAssembler{"data.BlockSizes"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_BlockSizes__Assembler) AssignBool(bool) error { + return mixins.ListAssembler{"data.BlockSizes"}.AssignBool(false) +} +func (_BlockSizes__Assembler) AssignInt(int64) error { + return mixins.ListAssembler{"data.BlockSizes"}.AssignInt(0) +} +func (_BlockSizes__Assembler) AssignFloat(float64) error { + return mixins.ListAssembler{"data.BlockSizes"}.AssignFloat(0) +} +func (_BlockSizes__Assembler) AssignString(string) error { + return mixins.ListAssembler{"data.BlockSizes"}.AssignString("") +} +func (_BlockSizes__Assembler) AssignBytes([]byte) error { + return mixins.ListAssembler{"data.BlockSizes"}.AssignBytes(nil) +} +func (_BlockSizes__Assembler) AssignLink(ipld.Link) error { + return mixins.ListAssembler{"data.BlockSizes"}.AssignLink(nil) +} +func (na *_BlockSizes__Assembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_BlockSizes); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != ipld.Kind_List { + return ipld.ErrWrongKind{TypeName: "data.BlockSizes", MethodName: "AssignNode", AppropriateKind: ipld.KindSet_JustList, ActualKind: v.Kind()} + } + itr := v.ListIterator() + for !itr.Done() { + _, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_BlockSizes__Assembler) Prototype() ipld.NodePrototype { + return _BlockSizes__Prototype{} +} +func (la *_BlockSizes__Assembler) valueFinishTidy() bool { + switch la.cm { + case schema.Maybe_Value: + la.va.w = nil + la.cm = schema.Maybe_Absent + la.state = laState_initial + la.va.reset() + return true + default: + return false + } +} +func (la *_BlockSizes__Assembler) AssembleValue() ipld.NodeAssembler { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + la.w.x = append(la.w.x, _Int{}) + la.state = laState_midValue + row := &la.w.x[len(la.w.x)-1] + la.va.w = row + la.va.m = &la.cm + return &la.va +} +func (la *_BlockSizes__Assembler) Finish() error { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + la.state = laState_finished + *la.m = schema.Maybe_Value + return nil +} +func (la *_BlockSizes__Assembler) ValuePrototype(_ int64) ipld.NodePrototype { + return _Int__Prototype{} +} +func (BlockSizes) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n BlockSizes) Representation() ipld.Node { + return (*_BlockSizes__Repr)(n) +} + +type _BlockSizes__Repr _BlockSizes + +var _ ipld.Node = &_BlockSizes__Repr{} + +func (_BlockSizes__Repr) Kind() ipld.Kind { + return ipld.Kind_List +} +func (_BlockSizes__Repr) LookupByString(string) (ipld.Node, error) { + return mixins.List{"data.BlockSizes.Repr"}.LookupByString("") +} +func (nr *_BlockSizes__Repr) LookupByNode(k ipld.Node) (ipld.Node, error) { + v, err := (BlockSizes)(nr).LookupByNode(k) + if err != nil || v == ipld.Null { + return v, err + } + return v.(Int).Representation(), nil +} +func (nr *_BlockSizes__Repr) LookupByIndex(idx int64) (ipld.Node, error) { + v, err := (BlockSizes)(nr).LookupByIndex(idx) + if err != nil || v == ipld.Null { + return v, err + } + return v.(Int).Representation(), nil +} +func (n _BlockSizes__Repr) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + i, err := seg.Index() + if err != nil { + return nil, ipld.ErrInvalidSegmentForList{TypeName: "data.BlockSizes.Repr", TroubleSegment: seg, Reason: err} + } + return n.LookupByIndex(i) +} +func (_BlockSizes__Repr) MapIterator() ipld.MapIterator { + return nil +} +func (nr *_BlockSizes__Repr) ListIterator() ipld.ListIterator { + return &_BlockSizes__ReprListItr{(BlockSizes)(nr), 0} +} + +type _BlockSizes__ReprListItr _BlockSizes__ListItr + +func (itr *_BlockSizes__ReprListItr) Next() (idx int64, v ipld.Node, err error) { + idx, v, err = (*_BlockSizes__ListItr)(itr).Next() + if err != nil || v == ipld.Null { + return + } + return idx, v.(Int).Representation(), nil +} +func (itr *_BlockSizes__ReprListItr) Done() bool { + return (*_BlockSizes__ListItr)(itr).Done() +} + +func (rn *_BlockSizes__Repr) Length() int64 { + return int64(len(rn.x)) +} +func (_BlockSizes__Repr) IsAbsent() bool { + return false +} +func (_BlockSizes__Repr) IsNull() bool { + return false +} +func (_BlockSizes__Repr) AsBool() (bool, error) { + return mixins.List{"data.BlockSizes.Repr"}.AsBool() +} +func (_BlockSizes__Repr) AsInt() (int64, error) { + return mixins.List{"data.BlockSizes.Repr"}.AsInt() +} +func (_BlockSizes__Repr) AsFloat() (float64, error) { + return mixins.List{"data.BlockSizes.Repr"}.AsFloat() +} +func (_BlockSizes__Repr) AsString() (string, error) { + return mixins.List{"data.BlockSizes.Repr"}.AsString() +} +func (_BlockSizes__Repr) AsBytes() ([]byte, error) { + return mixins.List{"data.BlockSizes.Repr"}.AsBytes() +} +func (_BlockSizes__Repr) AsLink() (ipld.Link, error) { + return mixins.List{"data.BlockSizes.Repr"}.AsLink() +} +func (_BlockSizes__Repr) Prototype() ipld.NodePrototype { + return _BlockSizes__ReprPrototype{} +} + +type _BlockSizes__ReprPrototype struct{} + +func (_BlockSizes__ReprPrototype) NewBuilder() ipld.NodeBuilder { + var nb _BlockSizes__ReprBuilder + nb.Reset() + return &nb +} + +type _BlockSizes__ReprBuilder struct { + _BlockSizes__ReprAssembler +} + +func (nb *_BlockSizes__ReprBuilder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_BlockSizes__ReprBuilder) Reset() { + var w _BlockSizes + var m schema.Maybe + *nb = _BlockSizes__ReprBuilder{_BlockSizes__ReprAssembler{w: &w, m: &m}} +} + +type _BlockSizes__ReprAssembler struct { + w *_BlockSizes + m *schema.Maybe + state laState + + cm schema.Maybe + va _Int__ReprAssembler +} + +func (na *_BlockSizes__ReprAssembler) reset() { + na.state = laState_initial + na.va.reset() +} +func (_BlockSizes__ReprAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { + return mixins.ListAssembler{"data.BlockSizes.Repr"}.BeginMap(0) +} +func (na *_BlockSizes__ReprAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if sizeHint < 0 { + sizeHint = 0 + } + if na.w == nil { + na.w = &_BlockSizes{} + } + if sizeHint > 0 { + na.w.x = make([]_Int, 0, sizeHint) + } + return na, nil +} +func (na *_BlockSizes__ReprAssembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.ListAssembler{"data.BlockSizes.Repr.Repr"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_BlockSizes__ReprAssembler) AssignBool(bool) error { + return mixins.ListAssembler{"data.BlockSizes.Repr"}.AssignBool(false) +} +func (_BlockSizes__ReprAssembler) AssignInt(int64) error { + return mixins.ListAssembler{"data.BlockSizes.Repr"}.AssignInt(0) +} +func (_BlockSizes__ReprAssembler) AssignFloat(float64) error { + return mixins.ListAssembler{"data.BlockSizes.Repr"}.AssignFloat(0) +} +func (_BlockSizes__ReprAssembler) AssignString(string) error { + return mixins.ListAssembler{"data.BlockSizes.Repr"}.AssignString("") +} +func (_BlockSizes__ReprAssembler) AssignBytes([]byte) error { + return mixins.ListAssembler{"data.BlockSizes.Repr"}.AssignBytes(nil) +} +func (_BlockSizes__ReprAssembler) AssignLink(ipld.Link) error { + return mixins.ListAssembler{"data.BlockSizes.Repr"}.AssignLink(nil) +} +func (na *_BlockSizes__ReprAssembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_BlockSizes); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != ipld.Kind_List { + return ipld.ErrWrongKind{TypeName: "data.BlockSizes.Repr", MethodName: "AssignNode", AppropriateKind: ipld.KindSet_JustList, ActualKind: v.Kind()} + } + itr := v.ListIterator() + for !itr.Done() { + _, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_BlockSizes__ReprAssembler) Prototype() ipld.NodePrototype { + return _BlockSizes__ReprPrototype{} +} +func (la *_BlockSizes__ReprAssembler) valueFinishTidy() bool { + switch la.cm { + case schema.Maybe_Value: + la.va.w = nil + la.cm = schema.Maybe_Absent + la.state = laState_initial + la.va.reset() + return true + default: + return false + } +} +func (la *_BlockSizes__ReprAssembler) AssembleValue() ipld.NodeAssembler { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + la.w.x = append(la.w.x, _Int{}) + la.state = laState_midValue + row := &la.w.x[len(la.w.x)-1] + la.va.w = row + la.va.m = &la.cm + return &la.va +} +func (la *_BlockSizes__ReprAssembler) Finish() error { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + la.state = laState_finished + *la.m = schema.Maybe_Value + return nil +} +func (la *_BlockSizes__ReprAssembler) ValuePrototype(_ int64) ipld.NodePrototype { + return _Int__ReprPrototype{} +} + +func (n Bytes) Bytes() []byte { + return n.x +} +func (_Bytes__Prototype) FromBytes(v []byte) (Bytes, error) { + n := _Bytes{v} + return &n, nil +} + +type _Bytes__Maybe struct { + m schema.Maybe + v Bytes +} +type MaybeBytes = *_Bytes__Maybe + +func (m MaybeBytes) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeBytes) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeBytes) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeBytes) AsNode() ipld.Node { + switch m.m { + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") + } +} +func (m MaybeBytes) Must() Bytes { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return m.v +} + +var _ ipld.Node = (Bytes)(&_Bytes{}) +var _ schema.TypedNode = (Bytes)(&_Bytes{}) + +func (Bytes) Kind() ipld.Kind { + return ipld.Kind_Bytes +} +func (Bytes) LookupByString(string) (ipld.Node, error) { + return mixins.Bytes{"data.Bytes"}.LookupByString("") +} +func (Bytes) LookupByNode(ipld.Node) (ipld.Node, error) { + return mixins.Bytes{"data.Bytes"}.LookupByNode(nil) +} +func (Bytes) LookupByIndex(idx int64) (ipld.Node, error) { + return mixins.Bytes{"data.Bytes"}.LookupByIndex(0) +} +func (Bytes) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return mixins.Bytes{"data.Bytes"}.LookupBySegment(seg) +} +func (Bytes) MapIterator() ipld.MapIterator { + return nil +} +func (Bytes) ListIterator() ipld.ListIterator { + return nil +} +func (Bytes) Length() int64 { + return -1 +} +func (Bytes) IsAbsent() bool { + return false +} +func (Bytes) IsNull() bool { + return false +} +func (Bytes) AsBool() (bool, error) { + return mixins.Bytes{"data.Bytes"}.AsBool() +} +func (Bytes) AsInt() (int64, error) { + return mixins.Bytes{"data.Bytes"}.AsInt() +} +func (Bytes) AsFloat() (float64, error) { + return mixins.Bytes{"data.Bytes"}.AsFloat() +} +func (Bytes) AsString() (string, error) { + return mixins.Bytes{"data.Bytes"}.AsString() +} +func (n Bytes) AsBytes() ([]byte, error) { + return n.x, nil +} +func (Bytes) AsLink() (ipld.Link, error) { + return mixins.Bytes{"data.Bytes"}.AsLink() +} +func (Bytes) Prototype() ipld.NodePrototype { + return _Bytes__Prototype{} +} + +type _Bytes__Prototype struct{} + +func (_Bytes__Prototype) NewBuilder() ipld.NodeBuilder { + var nb _Bytes__Builder + nb.Reset() + return &nb +} + +type _Bytes__Builder struct { + _Bytes__Assembler +} + +func (nb *_Bytes__Builder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_Bytes__Builder) Reset() { + var w _Bytes + var m schema.Maybe + *nb = _Bytes__Builder{_Bytes__Assembler{w: &w, m: &m}} +} + +type _Bytes__Assembler struct { + w *_Bytes + m *schema.Maybe +} + +func (na *_Bytes__Assembler) reset() {} +func (_Bytes__Assembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { + return mixins.BytesAssembler{"data.Bytes"}.BeginMap(0) +} +func (_Bytes__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { + return mixins.BytesAssembler{"data.Bytes"}.BeginList(0) +} +func (na *_Bytes__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.BytesAssembler{"data.Bytes"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + panic("unreachable") +} +func (_Bytes__Assembler) AssignBool(bool) error { + return mixins.BytesAssembler{"data.Bytes"}.AssignBool(false) +} +func (_Bytes__Assembler) AssignInt(int64) error { + return mixins.BytesAssembler{"data.Bytes"}.AssignInt(0) +} +func (_Bytes__Assembler) AssignFloat(float64) error { + return mixins.BytesAssembler{"data.Bytes"}.AssignFloat(0) +} +func (_Bytes__Assembler) AssignString(string) error { + return mixins.BytesAssembler{"data.Bytes"}.AssignString("") +} +func (na *_Bytes__Assembler) AssignBytes(v []byte) error { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + if na.w == nil { + na.w = &_Bytes{} + } + na.w.x = v + *na.m = schema.Maybe_Value + return nil +} +func (_Bytes__Assembler) AssignLink(ipld.Link) error { + return mixins.BytesAssembler{"data.Bytes"}.AssignLink(nil) +} +func (na *_Bytes__Assembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_Bytes); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v2, err := v.AsBytes(); err != nil { + return err + } else { + return na.AssignBytes(v2) + } +} +func (_Bytes__Assembler) Prototype() ipld.NodePrototype { + return _Bytes__Prototype{} +} +func (Bytes) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n Bytes) Representation() ipld.Node { + return (*_Bytes__Repr)(n) +} + +type _Bytes__Repr = _Bytes + +var _ ipld.Node = &_Bytes__Repr{} + +type _Bytes__ReprPrototype = _Bytes__Prototype +type _Bytes__ReprAssembler = _Bytes__Assembler + +func (n Int) Int() int64 { + return n.x +} +func (_Int__Prototype) FromInt(v int64) (Int, error) { + n := _Int{v} + return &n, nil +} + +type _Int__Maybe struct { + m schema.Maybe + v Int +} +type MaybeInt = *_Int__Maybe + +func (m MaybeInt) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeInt) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeInt) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeInt) AsNode() ipld.Node { + switch m.m { + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") + } +} +func (m MaybeInt) Must() Int { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return m.v +} + +var _ ipld.Node = (Int)(&_Int{}) +var _ schema.TypedNode = (Int)(&_Int{}) + +func (Int) Kind() ipld.Kind { + return ipld.Kind_Int +} +func (Int) LookupByString(string) (ipld.Node, error) { + return mixins.Int{"data.Int"}.LookupByString("") +} +func (Int) LookupByNode(ipld.Node) (ipld.Node, error) { + return mixins.Int{"data.Int"}.LookupByNode(nil) +} +func (Int) LookupByIndex(idx int64) (ipld.Node, error) { + return mixins.Int{"data.Int"}.LookupByIndex(0) +} +func (Int) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return mixins.Int{"data.Int"}.LookupBySegment(seg) +} +func (Int) MapIterator() ipld.MapIterator { + return nil +} +func (Int) ListIterator() ipld.ListIterator { + return nil +} +func (Int) Length() int64 { + return -1 +} +func (Int) IsAbsent() bool { + return false +} +func (Int) IsNull() bool { + return false +} +func (Int) AsBool() (bool, error) { + return mixins.Int{"data.Int"}.AsBool() +} +func (n Int) AsInt() (int64, error) { + return n.x, nil +} +func (Int) AsFloat() (float64, error) { + return mixins.Int{"data.Int"}.AsFloat() +} +func (Int) AsString() (string, error) { + return mixins.Int{"data.Int"}.AsString() +} +func (Int) AsBytes() ([]byte, error) { + return mixins.Int{"data.Int"}.AsBytes() +} +func (Int) AsLink() (ipld.Link, error) { + return mixins.Int{"data.Int"}.AsLink() +} +func (Int) Prototype() ipld.NodePrototype { + return _Int__Prototype{} +} + +type _Int__Prototype struct{} + +func (_Int__Prototype) NewBuilder() ipld.NodeBuilder { + var nb _Int__Builder + nb.Reset() + return &nb +} + +type _Int__Builder struct { + _Int__Assembler +} + +func (nb *_Int__Builder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_Int__Builder) Reset() { + var w _Int + var m schema.Maybe + *nb = _Int__Builder{_Int__Assembler{w: &w, m: &m}} +} + +type _Int__Assembler struct { + w *_Int + m *schema.Maybe +} + +func (na *_Int__Assembler) reset() {} +func (_Int__Assembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { + return mixins.IntAssembler{"data.Int"}.BeginMap(0) +} +func (_Int__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { + return mixins.IntAssembler{"data.Int"}.BeginList(0) +} +func (na *_Int__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.IntAssembler{"data.Int"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + panic("unreachable") +} +func (_Int__Assembler) AssignBool(bool) error { + return mixins.IntAssembler{"data.Int"}.AssignBool(false) +} +func (na *_Int__Assembler) AssignInt(v int64) error { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + if na.w == nil { + na.w = &_Int{} + } + na.w.x = v + *na.m = schema.Maybe_Value + return nil +} +func (_Int__Assembler) AssignFloat(float64) error { + return mixins.IntAssembler{"data.Int"}.AssignFloat(0) +} +func (_Int__Assembler) AssignString(string) error { + return mixins.IntAssembler{"data.Int"}.AssignString("") +} +func (_Int__Assembler) AssignBytes([]byte) error { + return mixins.IntAssembler{"data.Int"}.AssignBytes(nil) +} +func (_Int__Assembler) AssignLink(ipld.Link) error { + return mixins.IntAssembler{"data.Int"}.AssignLink(nil) +} +func (na *_Int__Assembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_Int); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v2, err := v.AsInt(); err != nil { + return err + } else { + return na.AssignInt(v2) + } +} +func (_Int__Assembler) Prototype() ipld.NodePrototype { + return _Int__Prototype{} +} +func (Int) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n Int) Representation() ipld.Node { + return (*_Int__Repr)(n) +} + +type _Int__Repr = _Int + +var _ ipld.Node = &_Int__Repr{} + +type _Int__ReprPrototype = _Int__Prototype +type _Int__ReprAssembler = _Int__Assembler + +func (n String) String() string { + return n.x +} +func (_String__Prototype) fromString(w *_String, v string) error { + *w = _String{v} + return nil +} +func (_String__Prototype) FromString(v string) (String, error) { + n := _String{v} + return &n, nil +} + +type _String__Maybe struct { + m schema.Maybe + v String +} +type MaybeString = *_String__Maybe + +func (m MaybeString) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeString) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeString) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeString) AsNode() ipld.Node { + switch m.m { + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") + } +} +func (m MaybeString) Must() String { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return m.v +} + +var _ ipld.Node = (String)(&_String{}) +var _ schema.TypedNode = (String)(&_String{}) + +func (String) Kind() ipld.Kind { + return ipld.Kind_String +} +func (String) LookupByString(string) (ipld.Node, error) { + return mixins.String{"data.String"}.LookupByString("") +} +func (String) LookupByNode(ipld.Node) (ipld.Node, error) { + return mixins.String{"data.String"}.LookupByNode(nil) +} +func (String) LookupByIndex(idx int64) (ipld.Node, error) { + return mixins.String{"data.String"}.LookupByIndex(0) +} +func (String) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return mixins.String{"data.String"}.LookupBySegment(seg) +} +func (String) MapIterator() ipld.MapIterator { + return nil +} +func (String) ListIterator() ipld.ListIterator { + return nil +} +func (String) Length() int64 { + return -1 +} +func (String) IsAbsent() bool { + return false +} +func (String) IsNull() bool { + return false +} +func (String) AsBool() (bool, error) { + return mixins.String{"data.String"}.AsBool() +} +func (String) AsInt() (int64, error) { + return mixins.String{"data.String"}.AsInt() +} +func (String) AsFloat() (float64, error) { + return mixins.String{"data.String"}.AsFloat() +} +func (n String) AsString() (string, error) { + return n.x, nil +} +func (String) AsBytes() ([]byte, error) { + return mixins.String{"data.String"}.AsBytes() +} +func (String) AsLink() (ipld.Link, error) { + return mixins.String{"data.String"}.AsLink() +} +func (String) Prototype() ipld.NodePrototype { + return _String__Prototype{} +} + +type _String__Prototype struct{} + +func (_String__Prototype) NewBuilder() ipld.NodeBuilder { + var nb _String__Builder + nb.Reset() + return &nb +} + +type _String__Builder struct { + _String__Assembler +} + +func (nb *_String__Builder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_String__Builder) Reset() { + var w _String + var m schema.Maybe + *nb = _String__Builder{_String__Assembler{w: &w, m: &m}} +} + +type _String__Assembler struct { + w *_String + m *schema.Maybe +} + +func (na *_String__Assembler) reset() {} +func (_String__Assembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { + return mixins.StringAssembler{"data.String"}.BeginMap(0) +} +func (_String__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { + return mixins.StringAssembler{"data.String"}.BeginList(0) +} +func (na *_String__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.StringAssembler{"data.String"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + panic("unreachable") +} +func (_String__Assembler) AssignBool(bool) error { + return mixins.StringAssembler{"data.String"}.AssignBool(false) +} +func (_String__Assembler) AssignInt(int64) error { + return mixins.StringAssembler{"data.String"}.AssignInt(0) +} +func (_String__Assembler) AssignFloat(float64) error { + return mixins.StringAssembler{"data.String"}.AssignFloat(0) +} +func (na *_String__Assembler) AssignString(v string) error { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + if na.w == nil { + na.w = &_String{} + } + na.w.x = v + *na.m = schema.Maybe_Value + return nil +} +func (_String__Assembler) AssignBytes([]byte) error { + return mixins.StringAssembler{"data.String"}.AssignBytes(nil) +} +func (_String__Assembler) AssignLink(ipld.Link) error { + return mixins.StringAssembler{"data.String"}.AssignLink(nil) +} +func (na *_String__Assembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_String); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v2, err := v.AsString(); err != nil { + return err + } else { + return na.AssignString(v2) + } +} +func (_String__Assembler) Prototype() ipld.NodePrototype { + return _String__Prototype{} +} +func (String) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n String) Representation() ipld.Node { + return (*_String__Repr)(n) +} + +type _String__Repr = _String + +var _ ipld.Node = &_String__Repr{} + +type _String__ReprPrototype = _String__Prototype +type _String__ReprAssembler = _String__Assembler + +func (n _UnixFSData) FieldDataType() Int { + return &n.DataType +} +func (n _UnixFSData) FieldData() MaybeBytes { + return &n.Data +} +func (n _UnixFSData) FieldFileSize() MaybeInt { + return &n.FileSize +} +func (n _UnixFSData) FieldBlockSizes() BlockSizes { + return &n.BlockSizes +} +func (n _UnixFSData) FieldHashType() MaybeInt { + return &n.HashType +} +func (n _UnixFSData) FieldFanout() MaybeInt { + return &n.Fanout +} +func (n _UnixFSData) FieldMode() MaybeInt { + return &n.Mode +} +func (n _UnixFSData) FieldMtime() MaybeUnixTime { + return &n.Mtime +} + +type _UnixFSData__Maybe struct { + m schema.Maybe + v UnixFSData +} +type MaybeUnixFSData = *_UnixFSData__Maybe + +func (m MaybeUnixFSData) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeUnixFSData) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeUnixFSData) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeUnixFSData) AsNode() ipld.Node { + switch m.m { + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") + } +} +func (m MaybeUnixFSData) Must() UnixFSData { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return m.v +} + +var ( + fieldName__UnixFSData_DataType = _String{"DataType"} + fieldName__UnixFSData_Data = _String{"Data"} + fieldName__UnixFSData_FileSize = _String{"FileSize"} + fieldName__UnixFSData_BlockSizes = _String{"BlockSizes"} + fieldName__UnixFSData_HashType = _String{"HashType"} + fieldName__UnixFSData_Fanout = _String{"Fanout"} + fieldName__UnixFSData_Mode = _String{"Mode"} + fieldName__UnixFSData_Mtime = _String{"Mtime"} +) +var _ ipld.Node = (UnixFSData)(&_UnixFSData{}) +var _ schema.TypedNode = (UnixFSData)(&_UnixFSData{}) + +func (UnixFSData) Kind() ipld.Kind { + return ipld.Kind_Map +} +func (n UnixFSData) LookupByString(key string) (ipld.Node, error) { + switch key { + case "DataType": + return &n.DataType, nil + case "Data": + if n.Data.m == schema.Maybe_Absent { + return ipld.Absent, nil + } + return n.Data.v, nil + case "FileSize": + if n.FileSize.m == schema.Maybe_Absent { + return ipld.Absent, nil + } + return n.FileSize.v, nil + case "BlockSizes": + return &n.BlockSizes, nil + case "HashType": + if n.HashType.m == schema.Maybe_Absent { + return ipld.Absent, nil + } + return n.HashType.v, nil + case "Fanout": + if n.Fanout.m == schema.Maybe_Absent { + return ipld.Absent, nil + } + return n.Fanout.v, nil + case "Mode": + if n.Mode.m == schema.Maybe_Absent { + return ipld.Absent, nil + } + return n.Mode.v, nil + case "Mtime": + if n.Mtime.m == schema.Maybe_Absent { + return ipld.Absent, nil + } + return n.Mtime.v, nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} + } +} +func (n UnixFSData) LookupByNode(key ipld.Node) (ipld.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} +func (UnixFSData) LookupByIndex(idx int64) (ipld.Node, error) { + return mixins.Map{"data.UnixFSData"}.LookupByIndex(0) +} +func (n UnixFSData) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return n.LookupByString(seg.String()) +} +func (n UnixFSData) MapIterator() ipld.MapIterator { + return &_UnixFSData__MapItr{n, 0} +} + +type _UnixFSData__MapItr struct { + n UnixFSData + idx int +} + +func (itr *_UnixFSData__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) { + if itr.idx >= 8 { + return nil, nil, ipld.ErrIteratorOverread{} + } + switch itr.idx { + case 0: + k = &fieldName__UnixFSData_DataType + v = &itr.n.DataType + case 1: + k = &fieldName__UnixFSData_Data + if itr.n.Data.m == schema.Maybe_Absent { + v = ipld.Absent + break + } + v = itr.n.Data.v + case 2: + k = &fieldName__UnixFSData_FileSize + if itr.n.FileSize.m == schema.Maybe_Absent { + v = ipld.Absent + break + } + v = itr.n.FileSize.v + case 3: + k = &fieldName__UnixFSData_BlockSizes + v = &itr.n.BlockSizes + case 4: + k = &fieldName__UnixFSData_HashType + if itr.n.HashType.m == schema.Maybe_Absent { + v = ipld.Absent + break + } + v = itr.n.HashType.v + case 5: + k = &fieldName__UnixFSData_Fanout + if itr.n.Fanout.m == schema.Maybe_Absent { + v = ipld.Absent + break + } + v = itr.n.Fanout.v + case 6: + k = &fieldName__UnixFSData_Mode + if itr.n.Mode.m == schema.Maybe_Absent { + v = ipld.Absent + break + } + v = itr.n.Mode.v + case 7: + k = &fieldName__UnixFSData_Mtime + if itr.n.Mtime.m == schema.Maybe_Absent { + v = ipld.Absent + break + } + v = itr.n.Mtime.v + default: + panic("unreachable") + } + itr.idx++ + return +} +func (itr *_UnixFSData__MapItr) Done() bool { + return itr.idx >= 8 +} + +func (UnixFSData) ListIterator() ipld.ListIterator { + return nil +} +func (UnixFSData) Length() int64 { + return 8 +} +func (UnixFSData) IsAbsent() bool { + return false +} +func (UnixFSData) IsNull() bool { + return false +} +func (UnixFSData) AsBool() (bool, error) { + return mixins.Map{"data.UnixFSData"}.AsBool() +} +func (UnixFSData) AsInt() (int64, error) { + return mixins.Map{"data.UnixFSData"}.AsInt() +} +func (UnixFSData) AsFloat() (float64, error) { + return mixins.Map{"data.UnixFSData"}.AsFloat() +} +func (UnixFSData) AsString() (string, error) { + return mixins.Map{"data.UnixFSData"}.AsString() +} +func (UnixFSData) AsBytes() ([]byte, error) { + return mixins.Map{"data.UnixFSData"}.AsBytes() +} +func (UnixFSData) AsLink() (ipld.Link, error) { + return mixins.Map{"data.UnixFSData"}.AsLink() +} +func (UnixFSData) Prototype() ipld.NodePrototype { + return _UnixFSData__Prototype{} +} + +type _UnixFSData__Prototype struct{} + +func (_UnixFSData__Prototype) NewBuilder() ipld.NodeBuilder { + var nb _UnixFSData__Builder + nb.Reset() + return &nb +} + +type _UnixFSData__Builder struct { + _UnixFSData__Assembler +} + +func (nb *_UnixFSData__Builder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_UnixFSData__Builder) Reset() { + var w _UnixFSData + var m schema.Maybe + *nb = _UnixFSData__Builder{_UnixFSData__Assembler{w: &w, m: &m}} +} + +type _UnixFSData__Assembler struct { + w *_UnixFSData + m *schema.Maybe + state maState + s int + f int + + cm schema.Maybe + ca_DataType _Int__Assembler + ca_Data _Bytes__Assembler + ca_FileSize _Int__Assembler + ca_BlockSizes _BlockSizes__Assembler + ca_HashType _Int__Assembler + ca_Fanout _Int__Assembler + ca_Mode _Int__Assembler + ca_Mtime _UnixTime__Assembler +} + +func (na *_UnixFSData__Assembler) reset() { + na.state = maState_initial + na.s = 0 + na.ca_DataType.reset() + na.ca_Data.reset() + na.ca_FileSize.reset() + na.ca_BlockSizes.reset() + na.ca_HashType.reset() + na.ca_Fanout.reset() + na.ca_Mode.reset() + na.ca_Mtime.reset() +} + +var ( + fieldBit__UnixFSData_DataType = 1 << 0 + fieldBit__UnixFSData_Data = 1 << 1 + fieldBit__UnixFSData_FileSize = 1 << 2 + fieldBit__UnixFSData_BlockSizes = 1 << 3 + fieldBit__UnixFSData_HashType = 1 << 4 + fieldBit__UnixFSData_Fanout = 1 << 5 + fieldBit__UnixFSData_Mode = 1 << 6 + fieldBit__UnixFSData_Mtime = 1 << 7 + fieldBits__UnixFSData_sufficient = 0 + 1<<0 + 1<<3 +) + +func (na *_UnixFSData__Assembler) BeginMap(int64) (ipld.MapAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if na.w == nil { + na.w = &_UnixFSData{} + } + return na, nil +} +func (_UnixFSData__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { + return mixins.MapAssembler{"data.UnixFSData"}.BeginList(0) +} +func (na *_UnixFSData__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.MapAssembler{"data.UnixFSData"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_UnixFSData__Assembler) AssignBool(bool) error { + return mixins.MapAssembler{"data.UnixFSData"}.AssignBool(false) +} +func (_UnixFSData__Assembler) AssignInt(int64) error { + return mixins.MapAssembler{"data.UnixFSData"}.AssignInt(0) +} +func (_UnixFSData__Assembler) AssignFloat(float64) error { + return mixins.MapAssembler{"data.UnixFSData"}.AssignFloat(0) +} +func (_UnixFSData__Assembler) AssignString(string) error { + return mixins.MapAssembler{"data.UnixFSData"}.AssignString("") +} +func (_UnixFSData__Assembler) AssignBytes([]byte) error { + return mixins.MapAssembler{"data.UnixFSData"}.AssignBytes(nil) +} +func (_UnixFSData__Assembler) AssignLink(ipld.Link) error { + return mixins.MapAssembler{"data.UnixFSData"}.AssignLink(nil) +} +func (na *_UnixFSData__Assembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_UnixFSData); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != ipld.Kind_Map { + return ipld.ErrWrongKind{TypeName: "data.UnixFSData", MethodName: "AssignNode", AppropriateKind: ipld.KindSet_JustMap, ActualKind: v.Kind()} + } + itr := v.MapIterator() + for !itr.Done() { + k, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_UnixFSData__Assembler) Prototype() ipld.NodePrototype { + return _UnixFSData__Prototype{} +} +func (ma *_UnixFSData__Assembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.cm { + case schema.Maybe_Value: + ma.ca_DataType.w = nil + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + return true + default: + return false + } + case 1: + switch ma.w.Data.m { + case schema.Maybe_Value: + ma.w.Data.v = ma.ca_Data.w + ma.state = maState_initial + return true + default: + return false + } + case 2: + switch ma.w.FileSize.m { + case schema.Maybe_Value: + ma.w.FileSize.v = ma.ca_FileSize.w + ma.state = maState_initial + return true + default: + return false + } + case 3: + switch ma.cm { + case schema.Maybe_Value: + ma.ca_BlockSizes.w = nil + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + return true + default: + return false + } + case 4: + switch ma.w.HashType.m { + case schema.Maybe_Value: + ma.w.HashType.v = ma.ca_HashType.w + ma.state = maState_initial + return true + default: + return false + } + case 5: + switch ma.w.Fanout.m { + case schema.Maybe_Value: + ma.w.Fanout.v = ma.ca_Fanout.w + ma.state = maState_initial + return true + default: + return false + } + case 6: + switch ma.w.Mode.m { + case schema.Maybe_Value: + ma.w.Mode.v = ma.ca_Mode.w + ma.state = maState_initial + return true + default: + return false + } + case 7: + switch ma.w.Mtime.m { + case schema.Maybe_Value: + ma.w.Mtime.v = ma.ca_Mtime.w + ma.state = maState_initial + return true + default: + return false + } + default: + panic("unreachable") + } +} +func (ma *_UnixFSData__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, error) { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") + } + switch k { + case "DataType": + if ma.s&fieldBit__UnixFSData_DataType != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_DataType} + } + ma.s += fieldBit__UnixFSData_DataType + ma.state = maState_midValue + ma.f = 0 + ma.ca_DataType.w = &ma.w.DataType + ma.ca_DataType.m = &ma.cm + return &ma.ca_DataType, nil + case "Data": + if ma.s&fieldBit__UnixFSData_Data != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Data} + } + ma.s += fieldBit__UnixFSData_Data + ma.state = maState_midValue + ma.f = 1 + ma.ca_Data.w = ma.w.Data.v + ma.ca_Data.m = &ma.w.Data.m + return &ma.ca_Data, nil + case "FileSize": + if ma.s&fieldBit__UnixFSData_FileSize != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_FileSize} + } + ma.s += fieldBit__UnixFSData_FileSize + ma.state = maState_midValue + ma.f = 2 + ma.ca_FileSize.w = ma.w.FileSize.v + ma.ca_FileSize.m = &ma.w.FileSize.m + return &ma.ca_FileSize, nil + case "BlockSizes": + if ma.s&fieldBit__UnixFSData_BlockSizes != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_BlockSizes} + } + ma.s += fieldBit__UnixFSData_BlockSizes + ma.state = maState_midValue + ma.f = 3 + ma.ca_BlockSizes.w = &ma.w.BlockSizes + ma.ca_BlockSizes.m = &ma.cm + return &ma.ca_BlockSizes, nil + case "HashType": + if ma.s&fieldBit__UnixFSData_HashType != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_HashType} + } + ma.s += fieldBit__UnixFSData_HashType + ma.state = maState_midValue + ma.f = 4 + ma.ca_HashType.w = ma.w.HashType.v + ma.ca_HashType.m = &ma.w.HashType.m + return &ma.ca_HashType, nil + case "Fanout": + if ma.s&fieldBit__UnixFSData_Fanout != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Fanout} + } + ma.s += fieldBit__UnixFSData_Fanout + ma.state = maState_midValue + ma.f = 5 + ma.ca_Fanout.w = ma.w.Fanout.v + ma.ca_Fanout.m = &ma.w.Fanout.m + return &ma.ca_Fanout, nil + case "Mode": + if ma.s&fieldBit__UnixFSData_Mode != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mode} + } + ma.s += fieldBit__UnixFSData_Mode + ma.state = maState_midValue + ma.f = 6 + ma.ca_Mode.w = ma.w.Mode.v + ma.ca_Mode.m = &ma.w.Mode.m + return &ma.ca_Mode, nil + case "Mtime": + if ma.s&fieldBit__UnixFSData_Mtime != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mtime} + } + ma.s += fieldBit__UnixFSData_Mtime + ma.state = maState_midValue + ma.f = 7 + ma.ca_Mtime.w = ma.w.Mtime.v + ma.ca_Mtime.m = &ma.w.Mtime.m + return &ma.ca_Mtime, nil + } + return nil, ipld.ErrInvalidKey{TypeName: "data.UnixFSData", Key: &_String{k}} +} +func (ma *_UnixFSData__Assembler) AssembleKey() ipld.NodeAssembler { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.state = maState_midKey + return (*_UnixFSData__KeyAssembler)(ma) +} +func (ma *_UnixFSData__Assembler) AssembleValue() ipld.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + ma.state = maState_midValue + switch ma.f { + case 0: + ma.ca_DataType.w = &ma.w.DataType + ma.ca_DataType.m = &ma.cm + return &ma.ca_DataType + case 1: + ma.ca_Data.w = ma.w.Data.v + ma.ca_Data.m = &ma.w.Data.m + return &ma.ca_Data + case 2: + ma.ca_FileSize.w = ma.w.FileSize.v + ma.ca_FileSize.m = &ma.w.FileSize.m + return &ma.ca_FileSize + case 3: + ma.ca_BlockSizes.w = &ma.w.BlockSizes + ma.ca_BlockSizes.m = &ma.cm + return &ma.ca_BlockSizes + case 4: + ma.ca_HashType.w = ma.w.HashType.v + ma.ca_HashType.m = &ma.w.HashType.m + return &ma.ca_HashType + case 5: + ma.ca_Fanout.w = ma.w.Fanout.v + ma.ca_Fanout.m = &ma.w.Fanout.m + return &ma.ca_Fanout + case 6: + ma.ca_Mode.w = ma.w.Mode.v + ma.ca_Mode.m = &ma.w.Mode.m + return &ma.ca_Mode + case 7: + ma.ca_Mtime.w = ma.w.Mtime.v + ma.ca_Mtime.m = &ma.w.Mtime.m + return &ma.ca_Mtime + default: + panic("unreachable") + } +} +func (ma *_UnixFSData__Assembler) Finish() error { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + if ma.s&fieldBits__UnixFSData_sufficient != fieldBits__UnixFSData_sufficient { + err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} + if ma.s&fieldBit__UnixFSData_DataType == 0 { + err.Missing = append(err.Missing, "DataType") + } + if ma.s&fieldBit__UnixFSData_BlockSizes == 0 { + err.Missing = append(err.Missing, "BlockSizes") + } + return err + } + ma.state = maState_finished + *ma.m = schema.Maybe_Value + return nil +} +func (ma *_UnixFSData__Assembler) KeyPrototype() ipld.NodePrototype { + return _String__Prototype{} +} +func (ma *_UnixFSData__Assembler) ValuePrototype(k string) ipld.NodePrototype { + panic("todo structbuilder mapassembler valueprototype") +} + +type _UnixFSData__KeyAssembler _UnixFSData__Assembler + +func (_UnixFSData__KeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { + return mixins.StringAssembler{"data.UnixFSData.KeyAssembler"}.BeginMap(0) +} +func (_UnixFSData__KeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { + return mixins.StringAssembler{"data.UnixFSData.KeyAssembler"}.BeginList(0) +} +func (na *_UnixFSData__KeyAssembler) AssignNull() error { + return mixins.StringAssembler{"data.UnixFSData.KeyAssembler"}.AssignNull() +} +func (_UnixFSData__KeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{"data.UnixFSData.KeyAssembler"}.AssignBool(false) +} +func (_UnixFSData__KeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{"data.UnixFSData.KeyAssembler"}.AssignInt(0) +} +func (_UnixFSData__KeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{"data.UnixFSData.KeyAssembler"}.AssignFloat(0) +} +func (ka *_UnixFSData__KeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") + } + switch k { + case "DataType": + if ka.s&fieldBit__UnixFSData_DataType != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_DataType} + } + ka.s += fieldBit__UnixFSData_DataType + ka.state = maState_expectValue + ka.f = 0 + case "Data": + if ka.s&fieldBit__UnixFSData_Data != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Data} + } + ka.s += fieldBit__UnixFSData_Data + ka.state = maState_expectValue + ka.f = 1 + case "FileSize": + if ka.s&fieldBit__UnixFSData_FileSize != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_FileSize} + } + ka.s += fieldBit__UnixFSData_FileSize + ka.state = maState_expectValue + ka.f = 2 + case "BlockSizes": + if ka.s&fieldBit__UnixFSData_BlockSizes != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_BlockSizes} + } + ka.s += fieldBit__UnixFSData_BlockSizes + ka.state = maState_expectValue + ka.f = 3 + case "HashType": + if ka.s&fieldBit__UnixFSData_HashType != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_HashType} + } + ka.s += fieldBit__UnixFSData_HashType + ka.state = maState_expectValue + ka.f = 4 + case "Fanout": + if ka.s&fieldBit__UnixFSData_Fanout != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Fanout} + } + ka.s += fieldBit__UnixFSData_Fanout + ka.state = maState_expectValue + ka.f = 5 + case "Mode": + if ka.s&fieldBit__UnixFSData_Mode != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mode} + } + ka.s += fieldBit__UnixFSData_Mode + ka.state = maState_expectValue + ka.f = 6 + case "Mtime": + if ka.s&fieldBit__UnixFSData_Mtime != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mtime} + } + ka.s += fieldBit__UnixFSData_Mtime + ka.state = maState_expectValue + ka.f = 7 + default: + return ipld.ErrInvalidKey{TypeName: "data.UnixFSData", Key: &_String{k}} + } + return nil +} +func (_UnixFSData__KeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{"data.UnixFSData.KeyAssembler"}.AssignBytes(nil) +} +func (_UnixFSData__KeyAssembler) AssignLink(ipld.Link) error { + return mixins.StringAssembler{"data.UnixFSData.KeyAssembler"}.AssignLink(nil) +} +func (ka *_UnixFSData__KeyAssembler) AssignNode(v ipld.Node) error { + if v2, err := v.AsString(); err != nil { + return err + } else { + return ka.AssignString(v2) + } +} +func (_UnixFSData__KeyAssembler) Prototype() ipld.NodePrototype { + return _String__Prototype{} +} +func (UnixFSData) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n UnixFSData) Representation() ipld.Node { + return (*_UnixFSData__Repr)(n) +} + +type _UnixFSData__Repr _UnixFSData + +var ( + fieldName__UnixFSData_DataType_serial = _String{"DataType"} + fieldName__UnixFSData_Data_serial = _String{"Data"} + fieldName__UnixFSData_FileSize_serial = _String{"FileSize"} + fieldName__UnixFSData_BlockSizes_serial = _String{"BlockSizes"} + fieldName__UnixFSData_HashType_serial = _String{"HashType"} + fieldName__UnixFSData_Fanout_serial = _String{"Fanout"} + fieldName__UnixFSData_Mode_serial = _String{"Mode"} + fieldName__UnixFSData_Mtime_serial = _String{"Mtime"} +) +var _ ipld.Node = &_UnixFSData__Repr{} + +func (_UnixFSData__Repr) Kind() ipld.Kind { + return ipld.Kind_Map +} +func (n *_UnixFSData__Repr) LookupByString(key string) (ipld.Node, error) { + switch key { + case "DataType": + return n.DataType.Representation(), nil + case "Data": + if n.Data.m == schema.Maybe_Absent { + return ipld.Absent, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)} + } + return n.Data.v.Representation(), nil + case "FileSize": + if n.FileSize.m == schema.Maybe_Absent { + return ipld.Absent, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)} + } + return n.FileSize.v.Representation(), nil + case "BlockSizes": + return n.BlockSizes.Representation(), nil + case "HashType": + if n.HashType.m == schema.Maybe_Absent { + return ipld.Absent, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)} + } + return n.HashType.v.Representation(), nil + case "Fanout": + if n.Fanout.m == schema.Maybe_Absent { + return ipld.Absent, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)} + } + return n.Fanout.v.Representation(), nil + case "Mode": + if n.Mode.m == schema.Maybe_Absent { + return ipld.Absent, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)} + } + return n.Mode.v.Representation(), nil + case "Mtime": + if n.Mtime.m == schema.Maybe_Absent { + return ipld.Absent, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)} + } + return n.Mtime.v.Representation(), nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} + } +} +func (n *_UnixFSData__Repr) LookupByNode(key ipld.Node) (ipld.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} +func (_UnixFSData__Repr) LookupByIndex(idx int64) (ipld.Node, error) { + return mixins.Map{"data.UnixFSData.Repr"}.LookupByIndex(0) +} +func (n _UnixFSData__Repr) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return n.LookupByString(seg.String()) +} +func (n *_UnixFSData__Repr) MapIterator() ipld.MapIterator { + end := 8 + if n.Mtime.m == schema.Maybe_Absent { + end = 7 + } else { + goto done + } + if n.Mode.m == schema.Maybe_Absent { + end = 6 + } else { + goto done + } + if n.Fanout.m == schema.Maybe_Absent { + end = 5 + } else { + goto done + } + if n.HashType.m == schema.Maybe_Absent { + end = 4 + } else { + goto done + } +done: + return &_UnixFSData__ReprMapItr{n, 0, end} +} + +type _UnixFSData__ReprMapItr struct { + n *_UnixFSData__Repr + idx int + end int +} + +func (itr *_UnixFSData__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) { +advance: + if itr.idx >= 8 { + return nil, nil, ipld.ErrIteratorOverread{} + } + switch itr.idx { + case 0: + k = &fieldName__UnixFSData_DataType_serial + v = itr.n.DataType.Representation() + case 1: + k = &fieldName__UnixFSData_Data_serial + if itr.n.Data.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.Data.v.Representation() + case 2: + k = &fieldName__UnixFSData_FileSize_serial + if itr.n.FileSize.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.FileSize.v.Representation() + case 3: + k = &fieldName__UnixFSData_BlockSizes_serial + v = itr.n.BlockSizes.Representation() + case 4: + k = &fieldName__UnixFSData_HashType_serial + if itr.n.HashType.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.HashType.v.Representation() + case 5: + k = &fieldName__UnixFSData_Fanout_serial + if itr.n.Fanout.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.Fanout.v.Representation() + case 6: + k = &fieldName__UnixFSData_Mode_serial + if itr.n.Mode.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.Mode.v.Representation() + case 7: + k = &fieldName__UnixFSData_Mtime_serial + if itr.n.Mtime.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.Mtime.v.Representation() + default: + panic("unreachable") + } + itr.idx++ + return +} +func (itr *_UnixFSData__ReprMapItr) Done() bool { + return itr.idx >= itr.end +} +func (_UnixFSData__Repr) ListIterator() ipld.ListIterator { + return nil +} +func (rn *_UnixFSData__Repr) Length() int64 { + l := 8 + if rn.Data.m == schema.Maybe_Absent { + l-- + } + if rn.FileSize.m == schema.Maybe_Absent { + l-- + } + if rn.HashType.m == schema.Maybe_Absent { + l-- + } + if rn.Fanout.m == schema.Maybe_Absent { + l-- + } + if rn.Mode.m == schema.Maybe_Absent { + l-- + } + if rn.Mtime.m == schema.Maybe_Absent { + l-- + } + return int64(l) +} +func (_UnixFSData__Repr) IsAbsent() bool { + return false +} +func (_UnixFSData__Repr) IsNull() bool { + return false +} +func (_UnixFSData__Repr) AsBool() (bool, error) { + return mixins.Map{"data.UnixFSData.Repr"}.AsBool() +} +func (_UnixFSData__Repr) AsInt() (int64, error) { + return mixins.Map{"data.UnixFSData.Repr"}.AsInt() +} +func (_UnixFSData__Repr) AsFloat() (float64, error) { + return mixins.Map{"data.UnixFSData.Repr"}.AsFloat() +} +func (_UnixFSData__Repr) AsString() (string, error) { + return mixins.Map{"data.UnixFSData.Repr"}.AsString() +} +func (_UnixFSData__Repr) AsBytes() ([]byte, error) { + return mixins.Map{"data.UnixFSData.Repr"}.AsBytes() +} +func (_UnixFSData__Repr) AsLink() (ipld.Link, error) { + return mixins.Map{"data.UnixFSData.Repr"}.AsLink() +} +func (_UnixFSData__Repr) Prototype() ipld.NodePrototype { + return _UnixFSData__ReprPrototype{} +} + +type _UnixFSData__ReprPrototype struct{} + +func (_UnixFSData__ReprPrototype) NewBuilder() ipld.NodeBuilder { + var nb _UnixFSData__ReprBuilder + nb.Reset() + return &nb +} + +type _UnixFSData__ReprBuilder struct { + _UnixFSData__ReprAssembler +} + +func (nb *_UnixFSData__ReprBuilder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_UnixFSData__ReprBuilder) Reset() { + var w _UnixFSData + var m schema.Maybe + *nb = _UnixFSData__ReprBuilder{_UnixFSData__ReprAssembler{w: &w, m: &m}} +} + +type _UnixFSData__ReprAssembler struct { + w *_UnixFSData + m *schema.Maybe + state maState + s int + f int + + cm schema.Maybe + ca_DataType _Int__ReprAssembler + ca_Data _Bytes__ReprAssembler + ca_FileSize _Int__ReprAssembler + ca_BlockSizes _BlockSizes__ReprAssembler + ca_HashType _Int__ReprAssembler + ca_Fanout _Int__ReprAssembler + ca_Mode _Int__ReprAssembler + ca_Mtime _UnixTime__ReprAssembler +} + +func (na *_UnixFSData__ReprAssembler) reset() { + na.state = maState_initial + na.s = 0 + na.ca_DataType.reset() + na.ca_Data.reset() + na.ca_FileSize.reset() + na.ca_BlockSizes.reset() + na.ca_HashType.reset() + na.ca_Fanout.reset() + na.ca_Mode.reset() + na.ca_Mtime.reset() +} +func (na *_UnixFSData__ReprAssembler) BeginMap(int64) (ipld.MapAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if na.w == nil { + na.w = &_UnixFSData{} + } + return na, nil +} +func (_UnixFSData__ReprAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { + return mixins.MapAssembler{"data.UnixFSData.Repr"}.BeginList(0) +} +func (na *_UnixFSData__ReprAssembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.MapAssembler{"data.UnixFSData.Repr.Repr"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_UnixFSData__ReprAssembler) AssignBool(bool) error { + return mixins.MapAssembler{"data.UnixFSData.Repr"}.AssignBool(false) +} +func (_UnixFSData__ReprAssembler) AssignInt(int64) error { + return mixins.MapAssembler{"data.UnixFSData.Repr"}.AssignInt(0) +} +func (_UnixFSData__ReprAssembler) AssignFloat(float64) error { + return mixins.MapAssembler{"data.UnixFSData.Repr"}.AssignFloat(0) +} +func (_UnixFSData__ReprAssembler) AssignString(string) error { + return mixins.MapAssembler{"data.UnixFSData.Repr"}.AssignString("") +} +func (_UnixFSData__ReprAssembler) AssignBytes([]byte) error { + return mixins.MapAssembler{"data.UnixFSData.Repr"}.AssignBytes(nil) +} +func (_UnixFSData__ReprAssembler) AssignLink(ipld.Link) error { + return mixins.MapAssembler{"data.UnixFSData.Repr"}.AssignLink(nil) +} +func (na *_UnixFSData__ReprAssembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_UnixFSData); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != ipld.Kind_Map { + return ipld.ErrWrongKind{TypeName: "data.UnixFSData.Repr", MethodName: "AssignNode", AppropriateKind: ipld.KindSet_JustMap, ActualKind: v.Kind()} + } + itr := v.MapIterator() + for !itr.Done() { + k, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_UnixFSData__ReprAssembler) Prototype() ipld.NodePrototype { + return _UnixFSData__ReprPrototype{} +} +func (ma *_UnixFSData__ReprAssembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.cm { + case schema.Maybe_Value: + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + return true + default: + return false + } + case 1: + switch ma.w.Data.m { + case schema.Maybe_Value: + ma.w.Data.v = ma.ca_Data.w + ma.state = maState_initial + return true + default: + return false + } + case 2: + switch ma.w.FileSize.m { + case schema.Maybe_Value: + ma.w.FileSize.v = ma.ca_FileSize.w + ma.state = maState_initial + return true + default: + return false + } + case 3: + switch ma.cm { + case schema.Maybe_Value: + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + return true + default: + return false + } + case 4: + switch ma.w.HashType.m { + case schema.Maybe_Value: + ma.w.HashType.v = ma.ca_HashType.w + ma.state = maState_initial + return true + default: + return false + } + case 5: + switch ma.w.Fanout.m { + case schema.Maybe_Value: + ma.w.Fanout.v = ma.ca_Fanout.w + ma.state = maState_initial + return true + default: + return false + } + case 6: + switch ma.w.Mode.m { + case schema.Maybe_Value: + ma.w.Mode.v = ma.ca_Mode.w + ma.state = maState_initial + return true + default: + return false + } + case 7: + switch ma.w.Mtime.m { + case schema.Maybe_Value: + ma.w.Mtime.v = ma.ca_Mtime.w + ma.state = maState_initial + return true + default: + return false + } + default: + panic("unreachable") + } +} +func (ma *_UnixFSData__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssembler, error) { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") + } + switch k { + case "DataType": + if ma.s&fieldBit__UnixFSData_DataType != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_DataType_serial} + } + ma.s += fieldBit__UnixFSData_DataType + ma.state = maState_midValue + ma.f = 0 + ma.ca_DataType.w = &ma.w.DataType + ma.ca_DataType.m = &ma.cm + return &ma.ca_DataType, nil + case "Data": + if ma.s&fieldBit__UnixFSData_Data != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Data_serial} + } + ma.s += fieldBit__UnixFSData_Data + ma.state = maState_midValue + ma.f = 1 + ma.ca_Data.w = ma.w.Data.v + ma.ca_Data.m = &ma.w.Data.m + + return &ma.ca_Data, nil + case "FileSize": + if ma.s&fieldBit__UnixFSData_FileSize != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_FileSize_serial} + } + ma.s += fieldBit__UnixFSData_FileSize + ma.state = maState_midValue + ma.f = 2 + ma.ca_FileSize.w = ma.w.FileSize.v + ma.ca_FileSize.m = &ma.w.FileSize.m + + return &ma.ca_FileSize, nil + case "BlockSizes": + if ma.s&fieldBit__UnixFSData_BlockSizes != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_BlockSizes_serial} + } + ma.s += fieldBit__UnixFSData_BlockSizes + ma.state = maState_midValue + ma.f = 3 + ma.ca_BlockSizes.w = &ma.w.BlockSizes + ma.ca_BlockSizes.m = &ma.cm + return &ma.ca_BlockSizes, nil + case "HashType": + if ma.s&fieldBit__UnixFSData_HashType != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_HashType_serial} + } + ma.s += fieldBit__UnixFSData_HashType + ma.state = maState_midValue + ma.f = 4 + ma.ca_HashType.w = ma.w.HashType.v + ma.ca_HashType.m = &ma.w.HashType.m + + return &ma.ca_HashType, nil + case "Fanout": + if ma.s&fieldBit__UnixFSData_Fanout != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Fanout_serial} + } + ma.s += fieldBit__UnixFSData_Fanout + ma.state = maState_midValue + ma.f = 5 + ma.ca_Fanout.w = ma.w.Fanout.v + ma.ca_Fanout.m = &ma.w.Fanout.m + + return &ma.ca_Fanout, nil + case "Mode": + if ma.s&fieldBit__UnixFSData_Mode != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mode_serial} + } + ma.s += fieldBit__UnixFSData_Mode + ma.state = maState_midValue + ma.f = 6 + ma.ca_Mode.w = ma.w.Mode.v + ma.ca_Mode.m = &ma.w.Mode.m + + return &ma.ca_Mode, nil + case "Mtime": + if ma.s&fieldBit__UnixFSData_Mtime != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mtime_serial} + } + ma.s += fieldBit__UnixFSData_Mtime + ma.state = maState_midValue + ma.f = 7 + ma.ca_Mtime.w = ma.w.Mtime.v + ma.ca_Mtime.m = &ma.w.Mtime.m + + return &ma.ca_Mtime, nil + default: + } + return nil, ipld.ErrInvalidKey{TypeName: "data.UnixFSData.Repr", Key: &_String{k}} +} +func (ma *_UnixFSData__ReprAssembler) AssembleKey() ipld.NodeAssembler { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.state = maState_midKey + return (*_UnixFSData__ReprKeyAssembler)(ma) +} +func (ma *_UnixFSData__ReprAssembler) AssembleValue() ipld.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + ma.state = maState_midValue + switch ma.f { + case 0: + ma.ca_DataType.w = &ma.w.DataType + ma.ca_DataType.m = &ma.cm + return &ma.ca_DataType + case 1: + ma.ca_Data.w = ma.w.Data.v + ma.ca_Data.m = &ma.w.Data.m + + return &ma.ca_Data + case 2: + ma.ca_FileSize.w = ma.w.FileSize.v + ma.ca_FileSize.m = &ma.w.FileSize.m + + return &ma.ca_FileSize + case 3: + ma.ca_BlockSizes.w = &ma.w.BlockSizes + ma.ca_BlockSizes.m = &ma.cm + return &ma.ca_BlockSizes + case 4: + ma.ca_HashType.w = ma.w.HashType.v + ma.ca_HashType.m = &ma.w.HashType.m + + return &ma.ca_HashType + case 5: + ma.ca_Fanout.w = ma.w.Fanout.v + ma.ca_Fanout.m = &ma.w.Fanout.m + + return &ma.ca_Fanout + case 6: + ma.ca_Mode.w = ma.w.Mode.v + ma.ca_Mode.m = &ma.w.Mode.m + + return &ma.ca_Mode + case 7: + ma.ca_Mtime.w = ma.w.Mtime.v + ma.ca_Mtime.m = &ma.w.Mtime.m + + return &ma.ca_Mtime + default: + panic("unreachable") + } +} +func (ma *_UnixFSData__ReprAssembler) Finish() error { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + if ma.s&fieldBits__UnixFSData_sufficient != fieldBits__UnixFSData_sufficient { + err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} + if ma.s&fieldBit__UnixFSData_DataType == 0 { + err.Missing = append(err.Missing, "DataType") + } + if ma.s&fieldBit__UnixFSData_BlockSizes == 0 { + err.Missing = append(err.Missing, "BlockSizes") + } + return err + } + ma.state = maState_finished + *ma.m = schema.Maybe_Value + return nil +} +func (ma *_UnixFSData__ReprAssembler) KeyPrototype() ipld.NodePrototype { + return _String__Prototype{} +} +func (ma *_UnixFSData__ReprAssembler) ValuePrototype(k string) ipld.NodePrototype { + panic("todo structbuilder mapassembler repr valueprototype") +} + +type _UnixFSData__ReprKeyAssembler _UnixFSData__ReprAssembler + +func (_UnixFSData__ReprKeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { + return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.BeginMap(0) +} +func (_UnixFSData__ReprKeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { + return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.BeginList(0) +} +func (na *_UnixFSData__ReprKeyAssembler) AssignNull() error { + return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.AssignNull() +} +func (_UnixFSData__ReprKeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.AssignBool(false) +} +func (_UnixFSData__ReprKeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.AssignInt(0) +} +func (_UnixFSData__ReprKeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.AssignFloat(0) +} +func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") + } + switch k { + case "DataType": + if ka.s&fieldBit__UnixFSData_DataType != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_DataType_serial} + } + ka.s += fieldBit__UnixFSData_DataType + ka.state = maState_expectValue + ka.f = 0 + return nil + case "Data": + if ka.s&fieldBit__UnixFSData_Data != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Data_serial} + } + ka.s += fieldBit__UnixFSData_Data + ka.state = maState_expectValue + ka.f = 1 + return nil + case "FileSize": + if ka.s&fieldBit__UnixFSData_FileSize != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_FileSize_serial} + } + ka.s += fieldBit__UnixFSData_FileSize + ka.state = maState_expectValue + ka.f = 2 + return nil + case "BlockSizes": + if ka.s&fieldBit__UnixFSData_BlockSizes != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_BlockSizes_serial} + } + ka.s += fieldBit__UnixFSData_BlockSizes + ka.state = maState_expectValue + ka.f = 3 + return nil + case "HashType": + if ka.s&fieldBit__UnixFSData_HashType != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_HashType_serial} + } + ka.s += fieldBit__UnixFSData_HashType + ka.state = maState_expectValue + ka.f = 4 + return nil + case "Fanout": + if ka.s&fieldBit__UnixFSData_Fanout != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Fanout_serial} + } + ka.s += fieldBit__UnixFSData_Fanout + ka.state = maState_expectValue + ka.f = 5 + return nil + case "Mode": + if ka.s&fieldBit__UnixFSData_Mode != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mode_serial} + } + ka.s += fieldBit__UnixFSData_Mode + ka.state = maState_expectValue + ka.f = 6 + return nil + case "Mtime": + if ka.s&fieldBit__UnixFSData_Mtime != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mtime_serial} + } + ka.s += fieldBit__UnixFSData_Mtime + ka.state = maState_expectValue + ka.f = 7 + return nil + } + return ipld.ErrInvalidKey{TypeName: "data.UnixFSData.Repr", Key: &_String{k}} +} +func (_UnixFSData__ReprKeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.AssignBytes(nil) +} +func (_UnixFSData__ReprKeyAssembler) AssignLink(ipld.Link) error { + return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.AssignLink(nil) +} +func (ka *_UnixFSData__ReprKeyAssembler) AssignNode(v ipld.Node) error { + if v2, err := v.AsString(); err != nil { + return err + } else { + return ka.AssignString(v2) + } +} +func (_UnixFSData__ReprKeyAssembler) Prototype() ipld.NodePrototype { + return _String__Prototype{} +} + +func (n _UnixFSMetadata) FieldMimeType() MaybeString { + return &n.MimeType +} + +type _UnixFSMetadata__Maybe struct { + m schema.Maybe + v UnixFSMetadata +} +type MaybeUnixFSMetadata = *_UnixFSMetadata__Maybe + +func (m MaybeUnixFSMetadata) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeUnixFSMetadata) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeUnixFSMetadata) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeUnixFSMetadata) AsNode() ipld.Node { + switch m.m { + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") + } +} +func (m MaybeUnixFSMetadata) Must() UnixFSMetadata { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return m.v +} + +var ( + fieldName__UnixFSMetadata_MimeType = _String{"MimeType"} +) +var _ ipld.Node = (UnixFSMetadata)(&_UnixFSMetadata{}) +var _ schema.TypedNode = (UnixFSMetadata)(&_UnixFSMetadata{}) + +func (UnixFSMetadata) Kind() ipld.Kind { + return ipld.Kind_Map +} +func (n UnixFSMetadata) LookupByString(key string) (ipld.Node, error) { + switch key { + case "MimeType": + if n.MimeType.m == schema.Maybe_Absent { + return ipld.Absent, nil + } + return n.MimeType.v, nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} + } +} +func (n UnixFSMetadata) LookupByNode(key ipld.Node) (ipld.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} +func (UnixFSMetadata) LookupByIndex(idx int64) (ipld.Node, error) { + return mixins.Map{"data.UnixFSMetadata"}.LookupByIndex(0) +} +func (n UnixFSMetadata) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return n.LookupByString(seg.String()) +} +func (n UnixFSMetadata) MapIterator() ipld.MapIterator { + return &_UnixFSMetadata__MapItr{n, 0} +} + +type _UnixFSMetadata__MapItr struct { + n UnixFSMetadata + idx int +} + +func (itr *_UnixFSMetadata__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) { + if itr.idx >= 1 { + return nil, nil, ipld.ErrIteratorOverread{} + } + switch itr.idx { + case 0: + k = &fieldName__UnixFSMetadata_MimeType + if itr.n.MimeType.m == schema.Maybe_Absent { + v = ipld.Absent + break + } + v = itr.n.MimeType.v + default: + panic("unreachable") + } + itr.idx++ + return +} +func (itr *_UnixFSMetadata__MapItr) Done() bool { + return itr.idx >= 1 +} + +func (UnixFSMetadata) ListIterator() ipld.ListIterator { + return nil +} +func (UnixFSMetadata) Length() int64 { + return 1 +} +func (UnixFSMetadata) IsAbsent() bool { + return false +} +func (UnixFSMetadata) IsNull() bool { + return false +} +func (UnixFSMetadata) AsBool() (bool, error) { + return mixins.Map{"data.UnixFSMetadata"}.AsBool() +} +func (UnixFSMetadata) AsInt() (int64, error) { + return mixins.Map{"data.UnixFSMetadata"}.AsInt() +} +func (UnixFSMetadata) AsFloat() (float64, error) { + return mixins.Map{"data.UnixFSMetadata"}.AsFloat() +} +func (UnixFSMetadata) AsString() (string, error) { + return mixins.Map{"data.UnixFSMetadata"}.AsString() +} +func (UnixFSMetadata) AsBytes() ([]byte, error) { + return mixins.Map{"data.UnixFSMetadata"}.AsBytes() +} +func (UnixFSMetadata) AsLink() (ipld.Link, error) { + return mixins.Map{"data.UnixFSMetadata"}.AsLink() +} +func (UnixFSMetadata) Prototype() ipld.NodePrototype { + return _UnixFSMetadata__Prototype{} +} + +type _UnixFSMetadata__Prototype struct{} + +func (_UnixFSMetadata__Prototype) NewBuilder() ipld.NodeBuilder { + var nb _UnixFSMetadata__Builder + nb.Reset() + return &nb +} + +type _UnixFSMetadata__Builder struct { + _UnixFSMetadata__Assembler +} + +func (nb *_UnixFSMetadata__Builder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_UnixFSMetadata__Builder) Reset() { + var w _UnixFSMetadata + var m schema.Maybe + *nb = _UnixFSMetadata__Builder{_UnixFSMetadata__Assembler{w: &w, m: &m}} +} + +type _UnixFSMetadata__Assembler struct { + w *_UnixFSMetadata + m *schema.Maybe + state maState + s int + f int + + cm schema.Maybe + ca_MimeType _String__Assembler +} + +func (na *_UnixFSMetadata__Assembler) reset() { + na.state = maState_initial + na.s = 0 + na.ca_MimeType.reset() +} + +var ( + fieldBit__UnixFSMetadata_MimeType = 1 << 0 + fieldBits__UnixFSMetadata_sufficient = 0 +) + +func (na *_UnixFSMetadata__Assembler) BeginMap(int64) (ipld.MapAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if na.w == nil { + na.w = &_UnixFSMetadata{} + } + return na, nil +} +func (_UnixFSMetadata__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { + return mixins.MapAssembler{"data.UnixFSMetadata"}.BeginList(0) +} +func (na *_UnixFSMetadata__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.MapAssembler{"data.UnixFSMetadata"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_UnixFSMetadata__Assembler) AssignBool(bool) error { + return mixins.MapAssembler{"data.UnixFSMetadata"}.AssignBool(false) +} +func (_UnixFSMetadata__Assembler) AssignInt(int64) error { + return mixins.MapAssembler{"data.UnixFSMetadata"}.AssignInt(0) +} +func (_UnixFSMetadata__Assembler) AssignFloat(float64) error { + return mixins.MapAssembler{"data.UnixFSMetadata"}.AssignFloat(0) +} +func (_UnixFSMetadata__Assembler) AssignString(string) error { + return mixins.MapAssembler{"data.UnixFSMetadata"}.AssignString("") +} +func (_UnixFSMetadata__Assembler) AssignBytes([]byte) error { + return mixins.MapAssembler{"data.UnixFSMetadata"}.AssignBytes(nil) +} +func (_UnixFSMetadata__Assembler) AssignLink(ipld.Link) error { + return mixins.MapAssembler{"data.UnixFSMetadata"}.AssignLink(nil) +} +func (na *_UnixFSMetadata__Assembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_UnixFSMetadata); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != ipld.Kind_Map { + return ipld.ErrWrongKind{TypeName: "data.UnixFSMetadata", MethodName: "AssignNode", AppropriateKind: ipld.KindSet_JustMap, ActualKind: v.Kind()} + } + itr := v.MapIterator() + for !itr.Done() { + k, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_UnixFSMetadata__Assembler) Prototype() ipld.NodePrototype { + return _UnixFSMetadata__Prototype{} +} +func (ma *_UnixFSMetadata__Assembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.w.MimeType.m { + case schema.Maybe_Value: + ma.w.MimeType.v = ma.ca_MimeType.w + ma.state = maState_initial + return true + default: + return false + } + default: + panic("unreachable") + } +} +func (ma *_UnixFSMetadata__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, error) { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") + } + switch k { + case "MimeType": + if ma.s&fieldBit__UnixFSMetadata_MimeType != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSMetadata_MimeType} + } + ma.s += fieldBit__UnixFSMetadata_MimeType + ma.state = maState_midValue + ma.f = 0 + ma.ca_MimeType.w = ma.w.MimeType.v + ma.ca_MimeType.m = &ma.w.MimeType.m + return &ma.ca_MimeType, nil + } + return nil, ipld.ErrInvalidKey{TypeName: "data.UnixFSMetadata", Key: &_String{k}} +} +func (ma *_UnixFSMetadata__Assembler) AssembleKey() ipld.NodeAssembler { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.state = maState_midKey + return (*_UnixFSMetadata__KeyAssembler)(ma) +} +func (ma *_UnixFSMetadata__Assembler) AssembleValue() ipld.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + ma.state = maState_midValue + switch ma.f { + case 0: + ma.ca_MimeType.w = ma.w.MimeType.v + ma.ca_MimeType.m = &ma.w.MimeType.m + return &ma.ca_MimeType + default: + panic("unreachable") + } +} +func (ma *_UnixFSMetadata__Assembler) Finish() error { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + if ma.s&fieldBits__UnixFSMetadata_sufficient != fieldBits__UnixFSMetadata_sufficient { + err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} + return err + } + ma.state = maState_finished + *ma.m = schema.Maybe_Value + return nil +} +func (ma *_UnixFSMetadata__Assembler) KeyPrototype() ipld.NodePrototype { + return _String__Prototype{} +} +func (ma *_UnixFSMetadata__Assembler) ValuePrototype(k string) ipld.NodePrototype { + panic("todo structbuilder mapassembler valueprototype") +} + +type _UnixFSMetadata__KeyAssembler _UnixFSMetadata__Assembler + +func (_UnixFSMetadata__KeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { + return mixins.StringAssembler{"data.UnixFSMetadata.KeyAssembler"}.BeginMap(0) +} +func (_UnixFSMetadata__KeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { + return mixins.StringAssembler{"data.UnixFSMetadata.KeyAssembler"}.BeginList(0) +} +func (na *_UnixFSMetadata__KeyAssembler) AssignNull() error { + return mixins.StringAssembler{"data.UnixFSMetadata.KeyAssembler"}.AssignNull() +} +func (_UnixFSMetadata__KeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{"data.UnixFSMetadata.KeyAssembler"}.AssignBool(false) +} +func (_UnixFSMetadata__KeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{"data.UnixFSMetadata.KeyAssembler"}.AssignInt(0) +} +func (_UnixFSMetadata__KeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{"data.UnixFSMetadata.KeyAssembler"}.AssignFloat(0) +} +func (ka *_UnixFSMetadata__KeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") + } + switch k { + case "MimeType": + if ka.s&fieldBit__UnixFSMetadata_MimeType != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSMetadata_MimeType} + } + ka.s += fieldBit__UnixFSMetadata_MimeType + ka.state = maState_expectValue + ka.f = 0 + default: + return ipld.ErrInvalidKey{TypeName: "data.UnixFSMetadata", Key: &_String{k}} + } + return nil +} +func (_UnixFSMetadata__KeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{"data.UnixFSMetadata.KeyAssembler"}.AssignBytes(nil) +} +func (_UnixFSMetadata__KeyAssembler) AssignLink(ipld.Link) error { + return mixins.StringAssembler{"data.UnixFSMetadata.KeyAssembler"}.AssignLink(nil) +} +func (ka *_UnixFSMetadata__KeyAssembler) AssignNode(v ipld.Node) error { + if v2, err := v.AsString(); err != nil { + return err + } else { + return ka.AssignString(v2) + } +} +func (_UnixFSMetadata__KeyAssembler) Prototype() ipld.NodePrototype { + return _String__Prototype{} +} +func (UnixFSMetadata) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n UnixFSMetadata) Representation() ipld.Node { + return (*_UnixFSMetadata__Repr)(n) +} + +type _UnixFSMetadata__Repr _UnixFSMetadata + +var ( + fieldName__UnixFSMetadata_MimeType_serial = _String{"MimeType"} +) +var _ ipld.Node = &_UnixFSMetadata__Repr{} + +func (_UnixFSMetadata__Repr) Kind() ipld.Kind { + return ipld.Kind_Map +} +func (n *_UnixFSMetadata__Repr) LookupByString(key string) (ipld.Node, error) { + switch key { + case "MimeType": + if n.MimeType.m == schema.Maybe_Absent { + return ipld.Absent, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)} + } + return n.MimeType.v.Representation(), nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} + } +} +func (n *_UnixFSMetadata__Repr) LookupByNode(key ipld.Node) (ipld.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} +func (_UnixFSMetadata__Repr) LookupByIndex(idx int64) (ipld.Node, error) { + return mixins.Map{"data.UnixFSMetadata.Repr"}.LookupByIndex(0) +} +func (n _UnixFSMetadata__Repr) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return n.LookupByString(seg.String()) +} +func (n *_UnixFSMetadata__Repr) MapIterator() ipld.MapIterator { + end := 1 + if n.MimeType.m == schema.Maybe_Absent { + end = 0 + } else { + goto done + } +done: + return &_UnixFSMetadata__ReprMapItr{n, 0, end} +} + +type _UnixFSMetadata__ReprMapItr struct { + n *_UnixFSMetadata__Repr + idx int + end int +} + +func (itr *_UnixFSMetadata__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) { +advance: + if itr.idx >= 1 { + return nil, nil, ipld.ErrIteratorOverread{} + } + switch itr.idx { + case 0: + k = &fieldName__UnixFSMetadata_MimeType_serial + if itr.n.MimeType.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.MimeType.v.Representation() + default: + panic("unreachable") + } + itr.idx++ + return +} +func (itr *_UnixFSMetadata__ReprMapItr) Done() bool { + return itr.idx >= itr.end +} +func (_UnixFSMetadata__Repr) ListIterator() ipld.ListIterator { + return nil +} +func (rn *_UnixFSMetadata__Repr) Length() int64 { + l := 1 + if rn.MimeType.m == schema.Maybe_Absent { + l-- + } + return int64(l) +} +func (_UnixFSMetadata__Repr) IsAbsent() bool { + return false +} +func (_UnixFSMetadata__Repr) IsNull() bool { + return false +} +func (_UnixFSMetadata__Repr) AsBool() (bool, error) { + return mixins.Map{"data.UnixFSMetadata.Repr"}.AsBool() +} +func (_UnixFSMetadata__Repr) AsInt() (int64, error) { + return mixins.Map{"data.UnixFSMetadata.Repr"}.AsInt() +} +func (_UnixFSMetadata__Repr) AsFloat() (float64, error) { + return mixins.Map{"data.UnixFSMetadata.Repr"}.AsFloat() +} +func (_UnixFSMetadata__Repr) AsString() (string, error) { + return mixins.Map{"data.UnixFSMetadata.Repr"}.AsString() +} +func (_UnixFSMetadata__Repr) AsBytes() ([]byte, error) { + return mixins.Map{"data.UnixFSMetadata.Repr"}.AsBytes() +} +func (_UnixFSMetadata__Repr) AsLink() (ipld.Link, error) { + return mixins.Map{"data.UnixFSMetadata.Repr"}.AsLink() +} +func (_UnixFSMetadata__Repr) Prototype() ipld.NodePrototype { + return _UnixFSMetadata__ReprPrototype{} +} + +type _UnixFSMetadata__ReprPrototype struct{} + +func (_UnixFSMetadata__ReprPrototype) NewBuilder() ipld.NodeBuilder { + var nb _UnixFSMetadata__ReprBuilder + nb.Reset() + return &nb +} + +type _UnixFSMetadata__ReprBuilder struct { + _UnixFSMetadata__ReprAssembler +} + +func (nb *_UnixFSMetadata__ReprBuilder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_UnixFSMetadata__ReprBuilder) Reset() { + var w _UnixFSMetadata + var m schema.Maybe + *nb = _UnixFSMetadata__ReprBuilder{_UnixFSMetadata__ReprAssembler{w: &w, m: &m}} +} + +type _UnixFSMetadata__ReprAssembler struct { + w *_UnixFSMetadata + m *schema.Maybe + state maState + s int + f int + + cm schema.Maybe + ca_MimeType _String__ReprAssembler +} + +func (na *_UnixFSMetadata__ReprAssembler) reset() { + na.state = maState_initial + na.s = 0 + na.ca_MimeType.reset() +} +func (na *_UnixFSMetadata__ReprAssembler) BeginMap(int64) (ipld.MapAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if na.w == nil { + na.w = &_UnixFSMetadata{} + } + return na, nil +} +func (_UnixFSMetadata__ReprAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { + return mixins.MapAssembler{"data.UnixFSMetadata.Repr"}.BeginList(0) +} +func (na *_UnixFSMetadata__ReprAssembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.MapAssembler{"data.UnixFSMetadata.Repr.Repr"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_UnixFSMetadata__ReprAssembler) AssignBool(bool) error { + return mixins.MapAssembler{"data.UnixFSMetadata.Repr"}.AssignBool(false) +} +func (_UnixFSMetadata__ReprAssembler) AssignInt(int64) error { + return mixins.MapAssembler{"data.UnixFSMetadata.Repr"}.AssignInt(0) +} +func (_UnixFSMetadata__ReprAssembler) AssignFloat(float64) error { + return mixins.MapAssembler{"data.UnixFSMetadata.Repr"}.AssignFloat(0) +} +func (_UnixFSMetadata__ReprAssembler) AssignString(string) error { + return mixins.MapAssembler{"data.UnixFSMetadata.Repr"}.AssignString("") +} +func (_UnixFSMetadata__ReprAssembler) AssignBytes([]byte) error { + return mixins.MapAssembler{"data.UnixFSMetadata.Repr"}.AssignBytes(nil) +} +func (_UnixFSMetadata__ReprAssembler) AssignLink(ipld.Link) error { + return mixins.MapAssembler{"data.UnixFSMetadata.Repr"}.AssignLink(nil) +} +func (na *_UnixFSMetadata__ReprAssembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_UnixFSMetadata); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != ipld.Kind_Map { + return ipld.ErrWrongKind{TypeName: "data.UnixFSMetadata.Repr", MethodName: "AssignNode", AppropriateKind: ipld.KindSet_JustMap, ActualKind: v.Kind()} + } + itr := v.MapIterator() + for !itr.Done() { + k, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_UnixFSMetadata__ReprAssembler) Prototype() ipld.NodePrototype { + return _UnixFSMetadata__ReprPrototype{} +} +func (ma *_UnixFSMetadata__ReprAssembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.w.MimeType.m { + case schema.Maybe_Value: + ma.w.MimeType.v = ma.ca_MimeType.w + ma.state = maState_initial + return true + default: + return false + } + default: + panic("unreachable") + } +} +func (ma *_UnixFSMetadata__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssembler, error) { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") + } + switch k { + case "MimeType": + if ma.s&fieldBit__UnixFSMetadata_MimeType != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSMetadata_MimeType_serial} + } + ma.s += fieldBit__UnixFSMetadata_MimeType + ma.state = maState_midValue + ma.f = 0 + ma.ca_MimeType.w = ma.w.MimeType.v + ma.ca_MimeType.m = &ma.w.MimeType.m + + return &ma.ca_MimeType, nil + default: + } + return nil, ipld.ErrInvalidKey{TypeName: "data.UnixFSMetadata.Repr", Key: &_String{k}} +} +func (ma *_UnixFSMetadata__ReprAssembler) AssembleKey() ipld.NodeAssembler { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.state = maState_midKey + return (*_UnixFSMetadata__ReprKeyAssembler)(ma) +} +func (ma *_UnixFSMetadata__ReprAssembler) AssembleValue() ipld.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + ma.state = maState_midValue + switch ma.f { + case 0: + ma.ca_MimeType.w = ma.w.MimeType.v + ma.ca_MimeType.m = &ma.w.MimeType.m + + return &ma.ca_MimeType + default: + panic("unreachable") + } +} +func (ma *_UnixFSMetadata__ReprAssembler) Finish() error { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + if ma.s&fieldBits__UnixFSMetadata_sufficient != fieldBits__UnixFSMetadata_sufficient { + err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} + return err + } + ma.state = maState_finished + *ma.m = schema.Maybe_Value + return nil +} +func (ma *_UnixFSMetadata__ReprAssembler) KeyPrototype() ipld.NodePrototype { + return _String__Prototype{} +} +func (ma *_UnixFSMetadata__ReprAssembler) ValuePrototype(k string) ipld.NodePrototype { + panic("todo structbuilder mapassembler repr valueprototype") +} + +type _UnixFSMetadata__ReprKeyAssembler _UnixFSMetadata__ReprAssembler + +func (_UnixFSMetadata__ReprKeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { + return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.BeginMap(0) +} +func (_UnixFSMetadata__ReprKeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { + return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.BeginList(0) +} +func (na *_UnixFSMetadata__ReprKeyAssembler) AssignNull() error { + return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.AssignNull() +} +func (_UnixFSMetadata__ReprKeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.AssignBool(false) +} +func (_UnixFSMetadata__ReprKeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.AssignInt(0) +} +func (_UnixFSMetadata__ReprKeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.AssignFloat(0) +} +func (ka *_UnixFSMetadata__ReprKeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") + } + switch k { + case "MimeType": + if ka.s&fieldBit__UnixFSMetadata_MimeType != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSMetadata_MimeType_serial} + } + ka.s += fieldBit__UnixFSMetadata_MimeType + ka.state = maState_expectValue + ka.f = 0 + return nil + } + return ipld.ErrInvalidKey{TypeName: "data.UnixFSMetadata.Repr", Key: &_String{k}} +} +func (_UnixFSMetadata__ReprKeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.AssignBytes(nil) +} +func (_UnixFSMetadata__ReprKeyAssembler) AssignLink(ipld.Link) error { + return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.AssignLink(nil) +} +func (ka *_UnixFSMetadata__ReprKeyAssembler) AssignNode(v ipld.Node) error { + if v2, err := v.AsString(); err != nil { + return err + } else { + return ka.AssignString(v2) + } +} +func (_UnixFSMetadata__ReprKeyAssembler) Prototype() ipld.NodePrototype { + return _String__Prototype{} +} + +func (n _UnixTime) FieldSeconds() Int { + return &n.Seconds +} +func (n _UnixTime) FieldFractionalNanoseconds() MaybeInt { + return &n.FractionalNanoseconds +} + +type _UnixTime__Maybe struct { + m schema.Maybe + v UnixTime +} +type MaybeUnixTime = *_UnixTime__Maybe + +func (m MaybeUnixTime) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeUnixTime) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeUnixTime) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeUnixTime) AsNode() ipld.Node { + switch m.m { + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") + } +} +func (m MaybeUnixTime) Must() UnixTime { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return m.v +} + +var ( + fieldName__UnixTime_Seconds = _String{"Seconds"} + fieldName__UnixTime_FractionalNanoseconds = _String{"FractionalNanoseconds"} +) +var _ ipld.Node = (UnixTime)(&_UnixTime{}) +var _ schema.TypedNode = (UnixTime)(&_UnixTime{}) + +func (UnixTime) Kind() ipld.Kind { + return ipld.Kind_Map +} +func (n UnixTime) LookupByString(key string) (ipld.Node, error) { + switch key { + case "Seconds": + return &n.Seconds, nil + case "FractionalNanoseconds": + if n.FractionalNanoseconds.m == schema.Maybe_Absent { + return ipld.Absent, nil + } + return n.FractionalNanoseconds.v, nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} + } +} +func (n UnixTime) LookupByNode(key ipld.Node) (ipld.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} +func (UnixTime) LookupByIndex(idx int64) (ipld.Node, error) { + return mixins.Map{"data.UnixTime"}.LookupByIndex(0) +} +func (n UnixTime) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return n.LookupByString(seg.String()) +} +func (n UnixTime) MapIterator() ipld.MapIterator { + return &_UnixTime__MapItr{n, 0} +} + +type _UnixTime__MapItr struct { + n UnixTime + idx int +} + +func (itr *_UnixTime__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) { + if itr.idx >= 2 { + return nil, nil, ipld.ErrIteratorOverread{} + } + switch itr.idx { + case 0: + k = &fieldName__UnixTime_Seconds + v = &itr.n.Seconds + case 1: + k = &fieldName__UnixTime_FractionalNanoseconds + if itr.n.FractionalNanoseconds.m == schema.Maybe_Absent { + v = ipld.Absent + break + } + v = itr.n.FractionalNanoseconds.v + default: + panic("unreachable") + } + itr.idx++ + return +} +func (itr *_UnixTime__MapItr) Done() bool { + return itr.idx >= 2 +} + +func (UnixTime) ListIterator() ipld.ListIterator { + return nil +} +func (UnixTime) Length() int64 { + return 2 +} +func (UnixTime) IsAbsent() bool { + return false +} +func (UnixTime) IsNull() bool { + return false +} +func (UnixTime) AsBool() (bool, error) { + return mixins.Map{"data.UnixTime"}.AsBool() +} +func (UnixTime) AsInt() (int64, error) { + return mixins.Map{"data.UnixTime"}.AsInt() +} +func (UnixTime) AsFloat() (float64, error) { + return mixins.Map{"data.UnixTime"}.AsFloat() +} +func (UnixTime) AsString() (string, error) { + return mixins.Map{"data.UnixTime"}.AsString() +} +func (UnixTime) AsBytes() ([]byte, error) { + return mixins.Map{"data.UnixTime"}.AsBytes() +} +func (UnixTime) AsLink() (ipld.Link, error) { + return mixins.Map{"data.UnixTime"}.AsLink() +} +func (UnixTime) Prototype() ipld.NodePrototype { + return _UnixTime__Prototype{} +} + +type _UnixTime__Prototype struct{} + +func (_UnixTime__Prototype) NewBuilder() ipld.NodeBuilder { + var nb _UnixTime__Builder + nb.Reset() + return &nb +} + +type _UnixTime__Builder struct { + _UnixTime__Assembler +} + +func (nb *_UnixTime__Builder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_UnixTime__Builder) Reset() { + var w _UnixTime + var m schema.Maybe + *nb = _UnixTime__Builder{_UnixTime__Assembler{w: &w, m: &m}} +} + +type _UnixTime__Assembler struct { + w *_UnixTime + m *schema.Maybe + state maState + s int + f int + + cm schema.Maybe + ca_Seconds _Int__Assembler + ca_FractionalNanoseconds _Int__Assembler +} + +func (na *_UnixTime__Assembler) reset() { + na.state = maState_initial + na.s = 0 + na.ca_Seconds.reset() + na.ca_FractionalNanoseconds.reset() +} + +var ( + fieldBit__UnixTime_Seconds = 1 << 0 + fieldBit__UnixTime_FractionalNanoseconds = 1 << 1 + fieldBits__UnixTime_sufficient = 0 + 1<<0 +) + +func (na *_UnixTime__Assembler) BeginMap(int64) (ipld.MapAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if na.w == nil { + na.w = &_UnixTime{} + } + return na, nil +} +func (_UnixTime__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { + return mixins.MapAssembler{"data.UnixTime"}.BeginList(0) +} +func (na *_UnixTime__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.MapAssembler{"data.UnixTime"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_UnixTime__Assembler) AssignBool(bool) error { + return mixins.MapAssembler{"data.UnixTime"}.AssignBool(false) +} +func (_UnixTime__Assembler) AssignInt(int64) error { + return mixins.MapAssembler{"data.UnixTime"}.AssignInt(0) +} +func (_UnixTime__Assembler) AssignFloat(float64) error { + return mixins.MapAssembler{"data.UnixTime"}.AssignFloat(0) +} +func (_UnixTime__Assembler) AssignString(string) error { + return mixins.MapAssembler{"data.UnixTime"}.AssignString("") +} +func (_UnixTime__Assembler) AssignBytes([]byte) error { + return mixins.MapAssembler{"data.UnixTime"}.AssignBytes(nil) +} +func (_UnixTime__Assembler) AssignLink(ipld.Link) error { + return mixins.MapAssembler{"data.UnixTime"}.AssignLink(nil) +} +func (na *_UnixTime__Assembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_UnixTime); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != ipld.Kind_Map { + return ipld.ErrWrongKind{TypeName: "data.UnixTime", MethodName: "AssignNode", AppropriateKind: ipld.KindSet_JustMap, ActualKind: v.Kind()} + } + itr := v.MapIterator() + for !itr.Done() { + k, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_UnixTime__Assembler) Prototype() ipld.NodePrototype { + return _UnixTime__Prototype{} +} +func (ma *_UnixTime__Assembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.cm { + case schema.Maybe_Value: + ma.ca_Seconds.w = nil + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + return true + default: + return false + } + case 1: + switch ma.w.FractionalNanoseconds.m { + case schema.Maybe_Value: + ma.w.FractionalNanoseconds.v = ma.ca_FractionalNanoseconds.w + ma.state = maState_initial + return true + default: + return false + } + default: + panic("unreachable") + } +} +func (ma *_UnixTime__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, error) { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") + } + switch k { + case "Seconds": + if ma.s&fieldBit__UnixTime_Seconds != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_Seconds} + } + ma.s += fieldBit__UnixTime_Seconds + ma.state = maState_midValue + ma.f = 0 + ma.ca_Seconds.w = &ma.w.Seconds + ma.ca_Seconds.m = &ma.cm + return &ma.ca_Seconds, nil + case "FractionalNanoseconds": + if ma.s&fieldBit__UnixTime_FractionalNanoseconds != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_FractionalNanoseconds} + } + ma.s += fieldBit__UnixTime_FractionalNanoseconds + ma.state = maState_midValue + ma.f = 1 + ma.ca_FractionalNanoseconds.w = ma.w.FractionalNanoseconds.v + ma.ca_FractionalNanoseconds.m = &ma.w.FractionalNanoseconds.m + return &ma.ca_FractionalNanoseconds, nil + } + return nil, ipld.ErrInvalidKey{TypeName: "data.UnixTime", Key: &_String{k}} +} +func (ma *_UnixTime__Assembler) AssembleKey() ipld.NodeAssembler { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.state = maState_midKey + return (*_UnixTime__KeyAssembler)(ma) +} +func (ma *_UnixTime__Assembler) AssembleValue() ipld.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + ma.state = maState_midValue + switch ma.f { + case 0: + ma.ca_Seconds.w = &ma.w.Seconds + ma.ca_Seconds.m = &ma.cm + return &ma.ca_Seconds + case 1: + ma.ca_FractionalNanoseconds.w = ma.w.FractionalNanoseconds.v + ma.ca_FractionalNanoseconds.m = &ma.w.FractionalNanoseconds.m + return &ma.ca_FractionalNanoseconds + default: + panic("unreachable") + } +} +func (ma *_UnixTime__Assembler) Finish() error { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + if ma.s&fieldBits__UnixTime_sufficient != fieldBits__UnixTime_sufficient { + err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} + if ma.s&fieldBit__UnixTime_Seconds == 0 { + err.Missing = append(err.Missing, "Seconds") + } + return err + } + ma.state = maState_finished + *ma.m = schema.Maybe_Value + return nil +} +func (ma *_UnixTime__Assembler) KeyPrototype() ipld.NodePrototype { + return _String__Prototype{} +} +func (ma *_UnixTime__Assembler) ValuePrototype(k string) ipld.NodePrototype { + panic("todo structbuilder mapassembler valueprototype") +} + +type _UnixTime__KeyAssembler _UnixTime__Assembler + +func (_UnixTime__KeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { + return mixins.StringAssembler{"data.UnixTime.KeyAssembler"}.BeginMap(0) +} +func (_UnixTime__KeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { + return mixins.StringAssembler{"data.UnixTime.KeyAssembler"}.BeginList(0) +} +func (na *_UnixTime__KeyAssembler) AssignNull() error { + return mixins.StringAssembler{"data.UnixTime.KeyAssembler"}.AssignNull() +} +func (_UnixTime__KeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{"data.UnixTime.KeyAssembler"}.AssignBool(false) +} +func (_UnixTime__KeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{"data.UnixTime.KeyAssembler"}.AssignInt(0) +} +func (_UnixTime__KeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{"data.UnixTime.KeyAssembler"}.AssignFloat(0) +} +func (ka *_UnixTime__KeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") + } + switch k { + case "Seconds": + if ka.s&fieldBit__UnixTime_Seconds != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_Seconds} + } + ka.s += fieldBit__UnixTime_Seconds + ka.state = maState_expectValue + ka.f = 0 + case "FractionalNanoseconds": + if ka.s&fieldBit__UnixTime_FractionalNanoseconds != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_FractionalNanoseconds} + } + ka.s += fieldBit__UnixTime_FractionalNanoseconds + ka.state = maState_expectValue + ka.f = 1 + default: + return ipld.ErrInvalidKey{TypeName: "data.UnixTime", Key: &_String{k}} + } + return nil +} +func (_UnixTime__KeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{"data.UnixTime.KeyAssembler"}.AssignBytes(nil) +} +func (_UnixTime__KeyAssembler) AssignLink(ipld.Link) error { + return mixins.StringAssembler{"data.UnixTime.KeyAssembler"}.AssignLink(nil) +} +func (ka *_UnixTime__KeyAssembler) AssignNode(v ipld.Node) error { + if v2, err := v.AsString(); err != nil { + return err + } else { + return ka.AssignString(v2) + } +} +func (_UnixTime__KeyAssembler) Prototype() ipld.NodePrototype { + return _String__Prototype{} +} +func (UnixTime) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n UnixTime) Representation() ipld.Node { + return (*_UnixTime__Repr)(n) +} + +type _UnixTime__Repr _UnixTime + +var ( + fieldName__UnixTime_Seconds_serial = _String{"Seconds"} + fieldName__UnixTime_FractionalNanoseconds_serial = _String{"FractionalNanoseconds"} +) +var _ ipld.Node = &_UnixTime__Repr{} + +func (_UnixTime__Repr) Kind() ipld.Kind { + return ipld.Kind_Map +} +func (n *_UnixTime__Repr) LookupByString(key string) (ipld.Node, error) { + switch key { + case "Seconds": + return n.Seconds.Representation(), nil + case "FractionalNanoseconds": + if n.FractionalNanoseconds.m == schema.Maybe_Absent { + return ipld.Absent, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)} + } + return n.FractionalNanoseconds.v.Representation(), nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} + } +} +func (n *_UnixTime__Repr) LookupByNode(key ipld.Node) (ipld.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} +func (_UnixTime__Repr) LookupByIndex(idx int64) (ipld.Node, error) { + return mixins.Map{"data.UnixTime.Repr"}.LookupByIndex(0) +} +func (n _UnixTime__Repr) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return n.LookupByString(seg.String()) +} +func (n *_UnixTime__Repr) MapIterator() ipld.MapIterator { + end := 2 + if n.FractionalNanoseconds.m == schema.Maybe_Absent { + end = 1 + } else { + goto done + } +done: + return &_UnixTime__ReprMapItr{n, 0, end} +} + +type _UnixTime__ReprMapItr struct { + n *_UnixTime__Repr + idx int + end int +} + +func (itr *_UnixTime__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) { +advance: + if itr.idx >= 2 { + return nil, nil, ipld.ErrIteratorOverread{} + } + switch itr.idx { + case 0: + k = &fieldName__UnixTime_Seconds_serial + v = itr.n.Seconds.Representation() + case 1: + k = &fieldName__UnixTime_FractionalNanoseconds_serial + if itr.n.FractionalNanoseconds.m == schema.Maybe_Absent { + itr.idx++ + goto advance + } + v = itr.n.FractionalNanoseconds.v.Representation() + default: + panic("unreachable") + } + itr.idx++ + return +} +func (itr *_UnixTime__ReprMapItr) Done() bool { + return itr.idx >= itr.end +} +func (_UnixTime__Repr) ListIterator() ipld.ListIterator { + return nil +} +func (rn *_UnixTime__Repr) Length() int64 { + l := 2 + if rn.FractionalNanoseconds.m == schema.Maybe_Absent { + l-- + } + return int64(l) +} +func (_UnixTime__Repr) IsAbsent() bool { + return false +} +func (_UnixTime__Repr) IsNull() bool { + return false +} +func (_UnixTime__Repr) AsBool() (bool, error) { + return mixins.Map{"data.UnixTime.Repr"}.AsBool() +} +func (_UnixTime__Repr) AsInt() (int64, error) { + return mixins.Map{"data.UnixTime.Repr"}.AsInt() +} +func (_UnixTime__Repr) AsFloat() (float64, error) { + return mixins.Map{"data.UnixTime.Repr"}.AsFloat() +} +func (_UnixTime__Repr) AsString() (string, error) { + return mixins.Map{"data.UnixTime.Repr"}.AsString() +} +func (_UnixTime__Repr) AsBytes() ([]byte, error) { + return mixins.Map{"data.UnixTime.Repr"}.AsBytes() +} +func (_UnixTime__Repr) AsLink() (ipld.Link, error) { + return mixins.Map{"data.UnixTime.Repr"}.AsLink() +} +func (_UnixTime__Repr) Prototype() ipld.NodePrototype { + return _UnixTime__ReprPrototype{} +} + +type _UnixTime__ReprPrototype struct{} + +func (_UnixTime__ReprPrototype) NewBuilder() ipld.NodeBuilder { + var nb _UnixTime__ReprBuilder + nb.Reset() + return &nb +} + +type _UnixTime__ReprBuilder struct { + _UnixTime__ReprAssembler +} + +func (nb *_UnixTime__ReprBuilder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_UnixTime__ReprBuilder) Reset() { + var w _UnixTime + var m schema.Maybe + *nb = _UnixTime__ReprBuilder{_UnixTime__ReprAssembler{w: &w, m: &m}} +} + +type _UnixTime__ReprAssembler struct { + w *_UnixTime + m *schema.Maybe + state maState + s int + f int + + cm schema.Maybe + ca_Seconds _Int__ReprAssembler + ca_FractionalNanoseconds _Int__ReprAssembler +} + +func (na *_UnixTime__ReprAssembler) reset() { + na.state = maState_initial + na.s = 0 + na.ca_Seconds.reset() + na.ca_FractionalNanoseconds.reset() +} +func (na *_UnixTime__ReprAssembler) BeginMap(int64) (ipld.MapAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if na.w == nil { + na.w = &_UnixTime{} + } + return na, nil +} +func (_UnixTime__ReprAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { + return mixins.MapAssembler{"data.UnixTime.Repr"}.BeginList(0) +} +func (na *_UnixTime__ReprAssembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.MapAssembler{"data.UnixTime.Repr.Repr"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_UnixTime__ReprAssembler) AssignBool(bool) error { + return mixins.MapAssembler{"data.UnixTime.Repr"}.AssignBool(false) +} +func (_UnixTime__ReprAssembler) AssignInt(int64) error { + return mixins.MapAssembler{"data.UnixTime.Repr"}.AssignInt(0) +} +func (_UnixTime__ReprAssembler) AssignFloat(float64) error { + return mixins.MapAssembler{"data.UnixTime.Repr"}.AssignFloat(0) +} +func (_UnixTime__ReprAssembler) AssignString(string) error { + return mixins.MapAssembler{"data.UnixTime.Repr"}.AssignString("") +} +func (_UnixTime__ReprAssembler) AssignBytes([]byte) error { + return mixins.MapAssembler{"data.UnixTime.Repr"}.AssignBytes(nil) +} +func (_UnixTime__ReprAssembler) AssignLink(ipld.Link) error { + return mixins.MapAssembler{"data.UnixTime.Repr"}.AssignLink(nil) +} +func (na *_UnixTime__ReprAssembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_UnixTime); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.Kind() != ipld.Kind_Map { + return ipld.ErrWrongKind{TypeName: "data.UnixTime.Repr", MethodName: "AssignNode", AppropriateKind: ipld.KindSet_JustMap, ActualKind: v.Kind()} + } + itr := v.MapIterator() + for !itr.Done() { + k, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_UnixTime__ReprAssembler) Prototype() ipld.NodePrototype { + return _UnixTime__ReprPrototype{} +} +func (ma *_UnixTime__ReprAssembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.cm { + case schema.Maybe_Value: + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + return true + default: + return false + } + case 1: + switch ma.w.FractionalNanoseconds.m { + case schema.Maybe_Value: + ma.w.FractionalNanoseconds.v = ma.ca_FractionalNanoseconds.w + ma.state = maState_initial + return true + default: + return false + } + default: + panic("unreachable") + } +} +func (ma *_UnixTime__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssembler, error) { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") + } + switch k { + case "Seconds": + if ma.s&fieldBit__UnixTime_Seconds != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_Seconds_serial} + } + ma.s += fieldBit__UnixTime_Seconds + ma.state = maState_midValue + ma.f = 0 + ma.ca_Seconds.w = &ma.w.Seconds + ma.ca_Seconds.m = &ma.cm + return &ma.ca_Seconds, nil + case "FractionalNanoseconds": + if ma.s&fieldBit__UnixTime_FractionalNanoseconds != 0 { + return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_FractionalNanoseconds_serial} + } + ma.s += fieldBit__UnixTime_FractionalNanoseconds + ma.state = maState_midValue + ma.f = 1 + ma.ca_FractionalNanoseconds.w = ma.w.FractionalNanoseconds.v + ma.ca_FractionalNanoseconds.m = &ma.w.FractionalNanoseconds.m + + return &ma.ca_FractionalNanoseconds, nil + default: + } + return nil, ipld.ErrInvalidKey{TypeName: "data.UnixTime.Repr", Key: &_String{k}} +} +func (ma *_UnixTime__ReprAssembler) AssembleKey() ipld.NodeAssembler { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.state = maState_midKey + return (*_UnixTime__ReprKeyAssembler)(ma) +} +func (ma *_UnixTime__ReprAssembler) AssembleValue() ipld.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + ma.state = maState_midValue + switch ma.f { + case 0: + ma.ca_Seconds.w = &ma.w.Seconds + ma.ca_Seconds.m = &ma.cm + return &ma.ca_Seconds + case 1: + ma.ca_FractionalNanoseconds.w = ma.w.FractionalNanoseconds.v + ma.ca_FractionalNanoseconds.m = &ma.w.FractionalNanoseconds.m + + return &ma.ca_FractionalNanoseconds + default: + panic("unreachable") + } +} +func (ma *_UnixTime__ReprAssembler) Finish() error { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + if ma.s&fieldBits__UnixTime_sufficient != fieldBits__UnixTime_sufficient { + err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} + if ma.s&fieldBit__UnixTime_Seconds == 0 { + err.Missing = append(err.Missing, "Seconds") + } + return err + } + ma.state = maState_finished + *ma.m = schema.Maybe_Value + return nil +} +func (ma *_UnixTime__ReprAssembler) KeyPrototype() ipld.NodePrototype { + return _String__Prototype{} +} +func (ma *_UnixTime__ReprAssembler) ValuePrototype(k string) ipld.NodePrototype { + panic("todo structbuilder mapassembler repr valueprototype") +} + +type _UnixTime__ReprKeyAssembler _UnixTime__ReprAssembler + +func (_UnixTime__ReprKeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { + return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.BeginMap(0) +} +func (_UnixTime__ReprKeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { + return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.BeginList(0) +} +func (na *_UnixTime__ReprKeyAssembler) AssignNull() error { + return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.AssignNull() +} +func (_UnixTime__ReprKeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.AssignBool(false) +} +func (_UnixTime__ReprKeyAssembler) AssignInt(int64) error { + return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.AssignInt(0) +} +func (_UnixTime__ReprKeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.AssignFloat(0) +} +func (ka *_UnixTime__ReprKeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") + } + switch k { + case "Seconds": + if ka.s&fieldBit__UnixTime_Seconds != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_Seconds_serial} + } + ka.s += fieldBit__UnixTime_Seconds + ka.state = maState_expectValue + ka.f = 0 + return nil + case "FractionalNanoseconds": + if ka.s&fieldBit__UnixTime_FractionalNanoseconds != 0 { + return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_FractionalNanoseconds_serial} + } + ka.s += fieldBit__UnixTime_FractionalNanoseconds + ka.state = maState_expectValue + ka.f = 1 + return nil + } + return ipld.ErrInvalidKey{TypeName: "data.UnixTime.Repr", Key: &_String{k}} +} +func (_UnixTime__ReprKeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.AssignBytes(nil) +} +func (_UnixTime__ReprKeyAssembler) AssignLink(ipld.Link) error { + return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.AssignLink(nil) +} +func (ka *_UnixTime__ReprKeyAssembler) AssignNode(v ipld.Node) error { + if v2, err := v.AsString(); err != nil { + return err + } else { + return ka.AssignString(v2) + } +} +func (_UnixTime__ReprKeyAssembler) Prototype() ipld.NodePrototype { + return _String__Prototype{} +} diff --git a/unixfs/node/data/ipldsch_types.go b/unixfs/node/data/ipldsch_types.go new file mode 100644 index 000000000..5fc6ae08a --- /dev/null +++ b/unixfs/node/data/ipldsch_types.go @@ -0,0 +1,83 @@ +package data + +// Code generated by go-ipld-prime gengo. DO NOT EDIT. + +import ( + ipld "github.com/ipld/go-ipld-prime" +) +var _ ipld.Node = nil // suppress errors when this dependency is not referenced +// Type is a struct embeding a NodePrototype/Type for every Node implementation in this package. +// One of its major uses is to start the construction of a value. +// You can use it like this: +// +// data.Type.YourTypeName.NewBuilder().BeginMap() //... +// +// and: +// +// data.Type.OtherTypeName.NewBuilder().AssignString("x") // ... +// +var Type typeSlab + +type typeSlab struct { + BlockSizes _BlockSizes__Prototype + BlockSizes__Repr _BlockSizes__ReprPrototype + Bytes _Bytes__Prototype + Bytes__Repr _Bytes__ReprPrototype + Int _Int__Prototype + Int__Repr _Int__ReprPrototype + String _String__Prototype + String__Repr _String__ReprPrototype + UnixFSData _UnixFSData__Prototype + UnixFSData__Repr _UnixFSData__ReprPrototype + UnixFSMetadata _UnixFSMetadata__Prototype + UnixFSMetadata__Repr _UnixFSMetadata__ReprPrototype + UnixTime _UnixTime__Prototype + UnixTime__Repr _UnixTime__ReprPrototype +} + +// --- type definitions follow --- + +// BlockSizes matches the IPLD Schema type "BlockSizes". It has list kind. +type BlockSizes = *_BlockSizes +type _BlockSizes struct { + x []_Int +} + +// Bytes matches the IPLD Schema type "Bytes". It has bytes kind. +type Bytes = *_Bytes +type _Bytes struct{ x []byte } + +// Int matches the IPLD Schema type "Int". It has int kind. +type Int = *_Int +type _Int struct{ x int64 } + +// String matches the IPLD Schema type "String". It has string kind. +type String = *_String +type _String struct{ x string } + +// UnixFSData matches the IPLD Schema type "UnixFSData". It has Struct type-kind, and may be interrogated like map kind. +type UnixFSData = *_UnixFSData +type _UnixFSData struct { + DataType _Int + Data _Bytes__Maybe + FileSize _Int__Maybe + BlockSizes _BlockSizes + HashType _Int__Maybe + Fanout _Int__Maybe + Mode _Int__Maybe + Mtime _UnixTime__Maybe +} + +// UnixFSMetadata matches the IPLD Schema type "UnixFSMetadata". It has Struct type-kind, and may be interrogated like map kind. +type UnixFSMetadata = *_UnixFSMetadata +type _UnixFSMetadata struct { + MimeType _String__Maybe +} + +// UnixTime matches the IPLD Schema type "UnixTime". It has Struct type-kind, and may be interrogated like map kind. +type UnixTime = *_UnixTime +type _UnixTime struct { + Seconds _Int + FractionalNanoseconds _Int__Maybe +} + diff --git a/unixfs/node/data/marshal.go b/unixfs/node/data/marshal.go new file mode 100644 index 000000000..7bef639ed --- /dev/null +++ b/unixfs/node/data/marshal.go @@ -0,0 +1,84 @@ +package data + +import "google.golang.org/protobuf/encoding/protowire" + +// EncodeUnixFSData serializes a UnixFSData node to bytes +func EncodeUnixFSData(node UnixFSData) []byte { + // 1KiB can be allocated on the stack, and covers most small nodes + // without having to grow the buffer and cause allocations. + enc := make([]byte, 0, 1024) + + return AppendEncodeUnixFSData(enc, node) +} + +func AppendEncodeUnixFSData(enc []byte, node UnixFSData) []byte { + enc = protowire.AppendTag(enc, Data_DataTypeWireNum, protowire.VarintType) + enc = protowire.AppendVarint(enc, uint64(node.FieldDataType().Int())) + if node.FieldData().Exists() { + enc = protowire.AppendTag(enc, Data_DataWireNum, protowire.BytesType) + enc = protowire.AppendBytes(enc, node.FieldData().Must().Bytes()) + } + if node.FieldFileSize().Exists() { + enc = protowire.AppendTag(enc, Data_FileSizeWireNum, protowire.VarintType) + enc = protowire.AppendVarint(enc, uint64(node.FieldFileSize().Must().Int())) + } + itr := node.FieldBlockSizes().Iterator() + for !itr.Done() { + _, nd := itr.Next() + enc = protowire.AppendTag(enc, Data_BlockSizesWireNum, protowire.VarintType) + enc = protowire.AppendVarint(enc, uint64(nd.Int())) + } + if node.FieldHashType().Exists() { + enc = protowire.AppendTag(enc, Data_HashTypeWireNum, protowire.VarintType) + enc = protowire.AppendVarint(enc, uint64(node.FieldHashType().Must().Int())) + } + if node.FieldFanout().Exists() { + enc = protowire.AppendTag(enc, Data_FanoutWireNum, protowire.VarintType) + enc = protowire.AppendVarint(enc, uint64(node.FieldFanout().Must().Int())) + } + if node.FieldMode().Exists() && node.FieldMode().Must().Int() != int64(DefaultPermissions(node)) { + enc = protowire.AppendTag(enc, Data_ModeWireNum, protowire.VarintType) + enc = protowire.AppendVarint(enc, uint64(node.FieldMode().Must().Int())) + } + if node.FieldMtime().Exists() { + mtime := node.FieldMtime().Must() + size := 0 + size += protowire.SizeTag(1) + size += protowire.SizeVarint(uint64(mtime.FieldSeconds().Int())) + if mtime.FieldFractionalNanoseconds().Exists() { + size += protowire.SizeTag(2) + size += protowire.SizeFixed32() + } + enc = protowire.AppendTag(enc, Data_MTimeWireNum, protowire.BytesType) + enc = protowire.AppendVarint(enc, uint64(size)) + enc = AppendEncodeUnixTime(enc, mtime) + } + return enc +} + +func AppendEncodeUnixTime(enc []byte, node UnixTime) []byte { + enc = protowire.AppendTag(enc, UnixTime_SecondsWireNum, protowire.VarintType) + enc = protowire.AppendVarint(enc, uint64(node.FieldSeconds().Int())) + if node.FieldFractionalNanoseconds().Exists() { + enc = protowire.AppendTag(enc, UnixTime_FractionalNanosecondsWireNum, protowire.Fixed32Type) + enc = protowire.AppendFixed32(enc, uint32(node.FieldFractionalNanoseconds().Must().Int())) + } + return enc +} + +// EncodeUnixFSMetadata serializes a UnixFSMetadata node to bytes +func EncodeUnixFSMetadata(node UnixFSMetadata) []byte { + // 1KiB can be allocated on the stack, and covers most small nodes + // without having to grow the buffer and cause allocations. + enc := make([]byte, 0, 1024) + + return AppendEncodeUnixFSMetadata(enc, node) +} + +func AppendEncodeUnixFSMetadata(enc []byte, node UnixFSMetadata) []byte { + if node.FieldMimeType().Exists() { + enc = protowire.AppendTag(enc, Metadata_MimeTypeWireNum, protowire.BytesType) + enc = protowire.AppendBytes(enc, []byte(node.FieldMimeType().Must().String())) + } + return enc +} diff --git a/unixfs/node/data/permissions.go b/unixfs/node/data/permissions.go new file mode 100644 index 000000000..d0b4dff7a --- /dev/null +++ b/unixfs/node/data/permissions.go @@ -0,0 +1,25 @@ +package data + +const FilePermissionsDefault = 0o0644 +const DirectorPerimissionsDefault = 0o0755 +const HAMTShardPerimissionsDefault = 0o0755 + +func (u UnixFSData) Permissions() int { + if u.FieldMode().Exists() { + return int(u.FieldMode().Must().Int() & 0xFFF) + } + return DefaultPermissions(u) +} + +func DefaultPermissions(u UnixFSData) int { + if u.FieldDataType().Int() == Data_File { + return FilePermissionsDefault + } + if u.FieldDataType().Int() == Data_Directory { + return DirectorPerimissionsDefault + } + if u.FieldDataType().Int() == Data_HAMTShard { + return HAMTShardPerimissionsDefault + } + return 0 +} diff --git a/unixfs/node/data/unmarshal.go b/unixfs/node/data/unmarshal.go new file mode 100644 index 000000000..7fbd76c64 --- /dev/null +++ b/unixfs/node/data/unmarshal.go @@ -0,0 +1,304 @@ +package data + +import ( + "errors" + "fmt" + "math" + + "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/fluent/qp" + "google.golang.org/protobuf/encoding/protowire" +) + +func DecodeUnixFSData(src []byte) (UnixFSData, error) { + nd, err := qp.BuildMap(Type.UnixFSData, -1, func(ma ipld.MapAssembler) { + err := consumeUnixFSData(src, ma) + if err != nil { + panic(err) + } + }) + if err != nil { + return nil, err + } + return nd.(UnixFSData), nil +} + +func consumeUnixFSData(remaining []byte, ma ipld.MapAssembler) error { + var bsa ipld.NodeBuilder + var la ipld.ListAssembler + var packedBlockSizes bool + for { + if len(remaining) == 0 { + break + } + + fieldNum, wireType, n := protowire.ConsumeTag(remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + switch fieldNum { + case Data_DataTypeWireNum: + if wireType != protowire.VarintType { + return fmt.Errorf("protobuf: (UnixFSData) invalid wireType, field: DataType, expected %d, got %d", protowire.VarintType, wireType) + } + dataType, n := protowire.ConsumeVarint(remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + qp.MapEntry(ma, "DataType", qp.Int(int64(dataType))) + case Data_DataWireNum: + if wireType != protowire.BytesType { + return fmt.Errorf("protobuf: (UnixFSData) invalid wireType, field: Data, expected %d, got %d", protowire.VarintType, wireType) + } + data, n := protowire.ConsumeBytes(remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + qp.MapEntry(ma, "Data", qp.Bytes(data)) + case Data_FileSizeWireNum: + if wireType != protowire.VarintType { + return fmt.Errorf("protobuf: (UnixFSData) invalid wireType, field: FileSize, expected %d, got %d", protowire.VarintType, wireType) + } + fileSize, n := protowire.ConsumeVarint(remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + qp.MapEntry(ma, "FileSize", qp.Int(int64(fileSize))) + case Data_BlockSizesWireNum: + switch wireType { + case protowire.VarintType: + if packedBlockSizes { + return errors.New("cannot build blocksizes twice") + } + if la == nil { + bsa = Type.BlockSizes.NewBuilder() + var err error + la, err = bsa.BeginList(1) + if err != nil { + return err + } + } + blockSize, n := protowire.ConsumeVarint(remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + qp.ListEntry(la, qp.Int(int64(blockSize))) + case protowire.BytesType: + if la != nil { + return errors.New("cannot build blocksizes twice") + } + blockSizesBytes, n := protowire.ConsumeBytes(remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + // count the number of varints in the array by looking at most + // significant bit not set + var blockSizeCount int64 + for _, integer := range blockSizesBytes { + if integer < 128 { + blockSizeCount++ + } + } + qp.MapEntry(ma, "BlockSizes", qp.List(blockSizeCount, func(la ipld.ListAssembler) { + err := consumeBlockSizes(blockSizesBytes, blockSizeCount, la) + if err != nil { + panic(err) + } + })) + default: + return fmt.Errorf("protobuf: (UnixFSData) invalid wireType, field: BlockSizes, got %d", wireType) + } + case Data_HashTypeWireNum: + if wireType != protowire.VarintType { + return fmt.Errorf("protobuf: (UnixFSData) invalid wireType, field: HashType, expected %d, got %d", protowire.VarintType, wireType) + } + hashType, n := protowire.ConsumeVarint(remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + qp.MapEntry(ma, "HashType", qp.Int(int64(hashType))) + case Data_FanoutWireNum: + if wireType != protowire.VarintType { + return fmt.Errorf("protobuf: (UnixFSData) invalid wireType, field: Fanout, expected %d, got %d", protowire.VarintType, wireType) + } + fanout, n := protowire.ConsumeVarint(remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + qp.MapEntry(ma, "Fanout", qp.Int(int64(fanout))) + case Data_ModeWireNum: + if wireType != protowire.VarintType { + return fmt.Errorf("protobuf: (UnixFSData) invalid wireType, field: Mode, expected %d, got %d", protowire.VarintType, wireType) + } + mode, n := protowire.ConsumeVarint(remaining) + if n < 0 { + return protowire.ParseError(n) + } + if mode > math.MaxUint32 { + return errors.New("mode should be a 32 bit value") + } + remaining = remaining[n:] + qp.MapEntry(ma, "Mode", qp.Int(int64(mode))) + case Data_MTimeWireNum: + if wireType != protowire.BytesType { + return fmt.Errorf("protobuf: (UnixFSData) invalid wireType, field: Mtime, expected %d, got %d", protowire.BytesType, wireType) + } + mTimeBytes, n := protowire.ConsumeBytes(remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + qp.MapEntry(ma, "Mtime", qp.Map(-1, func(ma ipld.MapAssembler) { + err := consumeUnixTime(mTimeBytes, ma) + if err != nil { + panic(err) + } + })) + default: + n := protowire.ConsumeFieldValue(fieldNum, wireType, remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + } + } + if !packedBlockSizes { + if la == nil { + qp.MapEntry(ma, "BlockSizes", qp.List(0, func(ipld.ListAssembler) {})) + } else { + err := la.Finish() + if err != nil { + return err + } + nd := bsa.Build() + qp.MapEntry(ma, "BlockSizes", qp.Node(nd)) + } + } + return nil +} + +func consumeBlockSizes(remaining []byte, count int64, la ipld.ListAssembler) error { + for i := 0; i < int(count); i++ { + blockSize, n := protowire.ConsumeVarint(remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + qp.ListEntry(la, qp.Int(int64(blockSize))) + } + if len(remaining) > 0 { + return errors.New("did not consume all block sizes") + } + return nil +} + +func consumeUnixTime(remaining []byte, ma ipld.MapAssembler) error { + for { + if len(remaining) == 0 { + break + } + + fieldNum, wireType, n := protowire.ConsumeTag(remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + + switch fieldNum { + case UnixTime_SecondsWireNum: + if wireType != protowire.VarintType { + return fmt.Errorf("protobuf: (UnixTime) invalid wireType, field: Seconds, expected %d, got %d", protowire.VarintType, wireType) + } + seconds, n := protowire.ConsumeVarint(remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + qp.MapEntry(ma, "Seconds", qp.Int(int64(seconds))) + case UnixTime_FractionalNanosecondsWireNum: + if wireType != protowire.Fixed32Type { + return fmt.Errorf("protobuf: (UnixTime) invalid wireType, field: FractionalNanoseconds, expected %d, got %d", protowire.Fixed32Type, wireType) + } + fractionalNanoseconds, n := protowire.ConsumeFixed32(remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + qp.MapEntry(ma, "FractionalNanoseconds", qp.Int(int64(fractionalNanoseconds))) + default: + n := protowire.ConsumeFieldValue(fieldNum, wireType, remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + } + } + return nil +} +func DecodeUnixTime(src []byte) (UnixTime, error) { + nd, err := qp.BuildMap(Type.UnixTime, -1, func(ma ipld.MapAssembler) { + err := consumeUnixTime(src, ma) + if err != nil { + panic(err) + } + }) + if err != nil { + return nil, err + } + return nd.(UnixTime), err +} + +func DecodeUnixFSMetadata(src []byte) (UnixFSMetadata, error) { + nd, err := qp.BuildMap(Type.UnixFSMetadata, -1, func(ma ipld.MapAssembler) { + err := consumeUnixFSMetadata(src, ma) + if err != nil { + panic(err) + } + }) + if err != nil { + return nil, err + } + return nd.(UnixFSMetadata), nil +} + +func consumeUnixFSMetadata(remaining []byte, ma ipld.MapAssembler) error { + for { + if len(remaining) == 0 { + break + } + + fieldNum, wireType, n := protowire.ConsumeTag(remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + + switch fieldNum { + case Metadata_MimeTypeWireNum: + if wireType != protowire.BytesType { + return fmt.Errorf("protobuf: (UnixFSMetadata) invalid wireType, field: MimeType, expected %d, got %d", protowire.VarintType, wireType) + } + mimeTypeBytes, n := protowire.ConsumeBytes(remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + qp.MapEntry(ma, "MimeType", qp.String(string(mimeTypeBytes))) + default: + n := protowire.ConsumeFieldValue(fieldNum, wireType, remaining) + if n < 0 { + return protowire.ParseError(n) + } + remaining = remaining[n:] + } + } + return nil +} diff --git a/unixfs/node/data/wirenumbers.go b/unixfs/node/data/wirenumbers.go new file mode 100644 index 000000000..43c8aab76 --- /dev/null +++ b/unixfs/node/data/wirenumbers.go @@ -0,0 +1,17 @@ +package data + +import "google.golang.org/protobuf/encoding/protowire" + +const ( + Data_DataTypeWireNum protowire.Number = 1 + Data_DataWireNum protowire.Number = 2 + Data_FileSizeWireNum protowire.Number = 3 + Data_BlockSizesWireNum protowire.Number = 4 + Data_HashTypeWireNum protowire.Number = 5 + Data_FanoutWireNum protowire.Number = 6 + Data_ModeWireNum protowire.Number = 7 + Data_MTimeWireNum protowire.Number = 8 + UnixTime_SecondsWireNum protowire.Number = 1 + UnixTime_FractionalNanosecondsWireNum protowire.Number = 2 + Metadata_MimeTypeWireNum protowire.Number = 1 +) From 8c661040c822310a2696994705a4d8ed026adbb5 Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Wed, 31 Mar 2021 20:58:46 -0700 Subject: [PATCH 04/43] feat(hamt): add hamt implementation Add HAMT Implementation + Shared iterator to use with basic directory This commit was moved from ipfs/go-unixfsnode@cdb32f2f05b153907416af08c589255d61df4f1b --- unixfs/node/hamt/shardeddir.go | 357 ++++++++++++++++++++++++++++ unixfs/node/hamt/shardeddir_test.go | 203 ++++++++++++++++ unixfs/node/hamt/util.go | 129 ++++++++++ unixfs/node/hamt/util_test.go | 66 +++++ unixfs/node/iter/iter.go | 83 +++++++ 5 files changed, 838 insertions(+) create mode 100644 unixfs/node/hamt/shardeddir.go create mode 100644 unixfs/node/hamt/shardeddir_test.go create mode 100644 unixfs/node/hamt/util.go create mode 100644 unixfs/node/hamt/util_test.go create mode 100644 unixfs/node/iter/iter.go diff --git a/unixfs/node/hamt/shardeddir.go b/unixfs/node/hamt/shardeddir.go new file mode 100644 index 000000000..89e6ebe05 --- /dev/null +++ b/unixfs/node/hamt/shardeddir.go @@ -0,0 +1,357 @@ +package hamt + +import ( + "context" + "fmt" + + "github.com/Stebalien/go-bitfield" + "github.com/ipfs/go-unixfsnode/data" + "github.com/ipfs/go-unixfsnode/iter" + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/schema" +) + +const ( + // HashMurmur3 is the multiformats identifier for Murmur3 + HashMurmur3 uint64 = 0x22 +) + +var _ ipld.Node = UnixFSHAMTShard(nil) +var _ schema.TypedNode = UnixFSHAMTShard(nil) + +type UnixFSHAMTShard = *_UnixFSHAMTShard + +type _UnixFSHAMTShard struct { + ctx context.Context + _substrate dagpb.PBNode + data data.UnixFSData + lsys *ipld.LinkSystem + bitfield bitfield.Bitfield + shardCache map[ipld.Link]*_UnixFSHAMTShard + cachedLength int64 +} + +func NewUnixFSHAMTShard(ctx context.Context, substrate dagpb.PBNode, data data.UnixFSData, lsys *ipld.LinkSystem) (ipld.Node, error) { + if err := ValidateHAMTData(data); err != nil { + return nil, err + } + shardCache := make(map[ipld.Link]*_UnixFSHAMTShard, substrate.FieldLinks().Length()) + bf := BitField(data) + return &_UnixFSHAMTShard{ + ctx: ctx, + _substrate: substrate, + data: data, + lsys: lsys, + shardCache: shardCache, + bitfield: bf, + cachedLength: -1, + }, nil +} + +func (n UnixFSHAMTShard) Kind() ipld.Kind { + return n._substrate.Kind() +} + +// LookupByString looks for the key in the list of links with a matching name +func (n UnixFSHAMTShard) LookupByString(key string) (ipld.Node, error) { + hv := &hashBits{b: hash([]byte(key))} + pbLink, err := n.lookup(key, hv) + if err != nil { + return nil, err + } + return pbLink.FieldHash(), nil +} + +func (n UnixFSHAMTShard) lookup(key string, hv *hashBits) (dagpb.PBLink, error) { + log2 := Log2Size(n.data) + maxPadLength := MaxPadLength(n.data) + childIndex, err := hv.Next(log2) + if err != nil { + return nil, err + } + + if n.hasChild(childIndex) { + pbLink, err := n.getChildLink(childIndex) + if err != nil { + return nil, err + } + isValue, err := IsValueLink(pbLink, maxPadLength) + if err != nil { + return nil, err + } + if isValue { + if MatchKey(pbLink, key, maxPadLength) { + return pbLink, nil + } + } else { + childNd, err := n.loadChild(pbLink) + if err != nil { + return nil, err + } + return childNd.lookup(key, hv) + } + } + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} +} + +func AttemptHAMTShardFromNode(ctx context.Context, nd ipld.Node, lsys *ipld.LinkSystem) (UnixFSHAMTShard, error) { + pbnd, ok := nd.(dagpb.PBNode) + if !ok { + return nil, fmt.Errorf("hamt.AttemptHAMTShardFromNode: child node was not a protobuf node") + } + if !pbnd.FieldData().Exists() { + return nil, fmt.Errorf("hamt.AttemptHAMTShardFromNode: child node was not a UnixFS node") + } + data, err := data.DecodeUnixFSData(pbnd.FieldData().Must().Bytes()) + if err != nil { + return nil, err + } + und, err := NewUnixFSHAMTShard(ctx, pbnd, data, lsys) + if err != nil { + return nil, err + } + return und.(UnixFSHAMTShard), nil +} + +func (n UnixFSHAMTShard) loadChild(pbLink dagpb.PBLink) (UnixFSHAMTShard, error) { + cached, ok := n.shardCache[pbLink.FieldHash().Link()] + if ok { + return cached, nil + } + nd, err := n.lsys.Load(ipld.LinkContext{Ctx: n.ctx}, pbLink.FieldHash().Link(), dagpb.Type.PBNode) + if err != nil { + return nil, err + } + und, err := AttemptHAMTShardFromNode(n.ctx, nd, n.lsys) + if err != nil { + return nil, err + } + n.shardCache[pbLink.FieldHash().Link()] = und + return und, nil +} + +func (n UnixFSHAMTShard) LookupByNode(key ipld.Node) (ipld.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} + +func (n UnixFSHAMTShard) LookupByIndex(idx int64) (ipld.Node, error) { + return n._substrate.LookupByIndex(idx) +} + +func (n UnixFSHAMTShard) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return n.LookupByString(seg.String()) +} + +func (n UnixFSHAMTShard) MapIterator() ipld.MapIterator { + maxpadLen := MaxPadLength(n.data) + listItr := &_UnixFSShardedDir__ListItr{ + _substrate: n.FieldLinks().Iterator(), + maxpadlen: maxpadLen, + nd: n, + } + st := stringTransformer{maxpadLen: maxpadLen} + return iter.NewUnixFSDirMapIterator(listItr, st.transformNameNode) +} + +type _UnixFSShardedDir__ListItr struct { + _substrate *dagpb.PBLinks__Itr + childIter *_UnixFSShardedDir__ListItr + nd UnixFSHAMTShard + maxpadlen int + total int64 +} + +func (itr *_UnixFSShardedDir__ListItr) Next() (int64, dagpb.PBLink) { + next := itr.next() + if next == nil { + return -1, next + } + total := itr.total + itr.total++ + return total, next +} + +func (itr *_UnixFSShardedDir__ListItr) next() dagpb.PBLink { + + if itr.childIter == nil { + if itr._substrate.Done() { + return nil + } + _, next := itr._substrate.Next() + isValue, err := IsValueLink(next, itr.maxpadlen) + if err != nil { + return nil + } + if isValue { + return next + } + child, err := itr.nd.loadChild(next) + if err != nil { + return nil + } + itr.childIter = &_UnixFSShardedDir__ListItr{ + _substrate: child._substrate.FieldLinks().Iterator(), + nd: child, + maxpadlen: MaxPadLength(child.data), + } + + } + _, next := itr.childIter.Next() + if itr.childIter.Done() { + itr.childIter = nil + } + return next +} + +func (itr *_UnixFSShardedDir__ListItr) Done() bool { + return itr.childIter == nil && itr._substrate.Done() +} + +// ListIterator returns an iterator which yields key-value pairs +// traversing the node. +// If the node kind is anything other than a list, nil will be returned. +// +// The iterator will yield every entry in the list; that is, it +// can be expected that itr.Next will be called node.Length times +// before itr.Done becomes true. +func (n UnixFSHAMTShard) ListIterator() ipld.ListIterator { + return nil +} + +// Length returns the length of a list, or the number of entries in a map, +// or -1 if the node is not of list nor map kind. +func (n UnixFSHAMTShard) Length() int64 { + if n.cachedLength != -1 { + return n.cachedLength + } + maxpadLen := MaxPadLength(n.data) + total := int64(0) + itr := n.FieldLinks().Iterator() + for !itr.Done() { + _, pbLink := itr.Next() + isValue, err := IsValueLink(pbLink, maxpadLen) + if err != nil { + continue + } + if isValue { + total++ + } else { + child, err := n.loadChild(pbLink) + if err != nil { + continue + } + total += child.Length() + } + } + n.cachedLength = total + return total +} + +func (n UnixFSHAMTShard) IsAbsent() bool { + return false +} + +func (n UnixFSHAMTShard) IsNull() bool { + return false +} + +func (n UnixFSHAMTShard) AsBool() (bool, error) { + return n._substrate.AsBool() +} + +func (n UnixFSHAMTShard) AsInt() (int64, error) { + return n._substrate.AsInt() +} + +func (n UnixFSHAMTShard) AsFloat() (float64, error) { + return n._substrate.AsFloat() +} + +func (n UnixFSHAMTShard) AsString() (string, error) { + return n._substrate.AsString() +} + +func (n UnixFSHAMTShard) AsBytes() ([]byte, error) { + return n._substrate.AsBytes() +} + +func (n UnixFSHAMTShard) AsLink() (ipld.Link, error) { + return n._substrate.AsLink() +} + +func (n UnixFSHAMTShard) Prototype() ipld.NodePrototype { + // TODO: should this return something? + // probobly not until we write the write interfaces + return nil +} + +// satisfy schema.TypedNode +func (UnixFSHAMTShard) Type() schema.Type { + return nil /*TODO:typelit*/ +} + +func (n UnixFSHAMTShard) Representation() ipld.Node { + return n._substrate.Representation() +} + +// Native map accessors + +func (n UnixFSHAMTShard) Iterator() *iter.UnixFSDir__Itr { + maxpadLen := MaxPadLength(n.data) + listItr := &_UnixFSShardedDir__ListItr{ + _substrate: n.FieldLinks().Iterator(), + maxpadlen: maxpadLen, + nd: n, + } + st := stringTransformer{maxpadLen: maxpadLen} + return iter.NewUnixFSDirIterator(listItr, st.transformNameNode) +} + +func (n UnixFSHAMTShard) Lookup(key dagpb.String) dagpb.PBLink { + hv := &hashBits{b: hash([]byte(key.String()))} + pbLink, err := n.lookup(key.String(), hv) + if err != nil { + return nil + } + return pbLink +} + +// direct access to the links and data + +func (n UnixFSHAMTShard) FieldLinks() dagpb.PBLinks { + return n._substrate.FieldLinks() +} + +func (n UnixFSHAMTShard) FieldData() dagpb.MaybeBytes { + return n._substrate.FieldData() +} + +func (n UnixFSHAMTShard) getChildLink(childIndex int) (dagpb.PBLink, error) { + linkIndex := n.bitfield.OnesBefore(childIndex) + if linkIndex >= int(n.FieldLinks().Length()) || linkIndex < 0 { + return nil, fmt.Errorf("invalid index passed to operate children (likely corrupt bitfield)") + } + return n.FieldLinks().Lookup(int64(linkIndex)), nil +} + +func (n UnixFSHAMTShard) hasChild(childIndex int) bool { + return n.bitfield.Bit(childIndex) +} + +type stringTransformer struct { + maxpadLen int +} + +func (s stringTransformer) transformNameNode(nd dagpb.String) dagpb.String { + nb := dagpb.Type.String.NewBuilder() + err := nb.AssignString(nd.String()[s.maxpadLen:]) + if err != nil { + return nil + } + return nb.Build().(dagpb.String) +} diff --git a/unixfs/node/hamt/shardeddir_test.go b/unixfs/node/hamt/shardeddir_test.go new file mode 100644 index 000000000..c4f2ec915 --- /dev/null +++ b/unixfs/node/hamt/shardeddir_test.go @@ -0,0 +1,203 @@ +package hamt_test + +import ( + "bytes" + "context" + "fmt" + "io" + "math/rand" + "sort" + "testing" + "time" + + format "github.com/ipfs/go-ipld-format" + "github.com/ipfs/go-merkledag" + dag "github.com/ipfs/go-merkledag" + mdtest "github.com/ipfs/go-merkledag/test" + ft "github.com/ipfs/go-unixfs" + legacy "github.com/ipfs/go-unixfs/hamt" + "github.com/ipfs/go-unixfsnode/hamt" + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/fluent/qp" + cidlink "github.com/ipld/go-ipld-prime/linking/cid" + "github.com/ipld/go-ipld-prime/schema" + "github.com/stretchr/testify/require" +) + +// For now these tests use legacy UnixFS HAMT builders until we finish a builder +// in go-ipld-prime +func shuffle(seed int64, arr []string) { + r := rand.New(rand.NewSource(seed)) + for i := 0; i < len(arr); i++ { + a := r.Intn(len(arr)) + b := r.Intn(len(arr)) + arr[a], arr[b] = arr[b], arr[a] + } +} + +func makeDir(ds format.DAGService, size int) ([]string, *legacy.Shard, error) { + return makeDirWidth(ds, size, 256) +} + +func makeDirWidth(ds format.DAGService, size, width int) ([]string, *legacy.Shard, error) { + ctx := context.Background() + + s, _ := legacy.NewShard(ds, width) + + var dirs []string + for i := 0; i < size; i++ { + dirs = append(dirs, fmt.Sprintf("DIRNAME%d", i)) + } + + shuffle(time.Now().UnixNano(), dirs) + + for i := 0; i < len(dirs); i++ { + nd := ft.EmptyDirNode() + ds.Add(ctx, nd) + err := s.Set(ctx, dirs[i], nd) + if err != nil { + return nil, nil, err + } + } + + return dirs, s, nil +} + +func assertLinksEqual(linksA []*format.Link, linksB []*format.Link) error { + + if len(linksA) != len(linksB) { + return fmt.Errorf("links arrays are different sizes") + } + + sort.Stable(dag.LinkSlice(linksA)) + sort.Stable(dag.LinkSlice(linksB)) + for i, a := range linksA { + b := linksB[i] + if a.Name != b.Name { + return fmt.Errorf("links names mismatch") + } + + if a.Cid.String() != b.Cid.String() { + return fmt.Errorf("link hashes dont match") + } + } + + return nil +} + +func mockDag() (format.DAGService, *ipld.LinkSystem) { + bsrv := mdtest.Bserv() + dsrv := merkledag.NewDAGService(bsrv) + lsys := cidlink.DefaultLinkSystem() + lsys.StorageReadOpener = func(lnkCtx ipld.LinkContext, lnk ipld.Link) (io.Reader, error) { + cidLink, ok := lnk.(cidlink.Link) + if !ok { + return nil, fmt.Errorf("invalid link type for loading: %v", lnk) + } + + blk, err := bsrv.GetBlock(lnkCtx.Ctx, cidLink.Cid) + if err != nil { + return nil, err + } + + return bytes.NewReader(blk.RawData()), nil + } + lsys.TrustedStorage = true + return dsrv, &lsys +} + +func TestBasicSet(t *testing.T) { + ds, lsys := mockDag() + for _, w := range []int{128, 256, 512, 1024, 2048, 4096} { + t.Run(fmt.Sprintf("BasicSet%d", w), func(t *testing.T) { + names, s, err := makeDirWidth(ds, 1000, w) + require.NoError(t, err) + ctx := context.Background() + legacyNode, err := s.Node() + require.NoError(t, err) + nd, err := lsys.Load(ipld.LinkContext{Ctx: ctx}, cidlink.Link{Cid: legacyNode.Cid()}, dagpb.Type.PBNode) + require.NoError(t, err) + hamtShard, err := hamt.AttemptHAMTShardFromNode(ctx, nd, lsys) + require.NoError(t, err) + for _, d := range names { + _, err := hamtShard.LookupByString(d) + require.NoError(t, err) + } + }) + } +} + +func TestIterator(t *testing.T) { + ds, lsys := mockDag() + _, s, err := makeDir(ds, 300) + if err != nil { + t.Fatal(err) + } + ctx := context.Background() + + legacyNode, err := s.Node() + require.NoError(t, err) + nds, err := legacy.NewHamtFromDag(ds, legacyNode) + require.NoError(t, err) + nd, err := lsys.Load(ipld.LinkContext{Ctx: ctx}, cidlink.Link{Cid: legacyNode.Cid()}, dagpb.Type.PBNode) + require.NoError(t, err) + hamtShard, err := hamt.AttemptHAMTShardFromNode(ctx, nd, lsys) + require.NoError(t, err) + + linksA, err := nds.EnumLinks(ctx) + require.NoError(t, err) + + require.Equal(t, int64(len(linksA)), hamtShard.Length()) + + linksB := make([]*format.Link, 0, len(linksA)) + iter := hamtShard.Iterator() + for !iter.Done() { + name, link := iter.Next() + linksB = append(linksB, &format.Link{ + Name: name.String(), + Cid: link.Link().(cidlink.Link).Cid, + }) + } + require.NoError(t, assertLinksEqual(linksA, linksB)) +} + +func TestLoadFailsFromNonShard(t *testing.T) { + ds, lsys := mockDag() + ctx := context.Background() + legacyNode := ft.EmptyDirNode() + ds.Add(ctx, legacyNode) + nd, err := lsys.Load(ipld.LinkContext{Ctx: ctx}, cidlink.Link{Cid: legacyNode.Cid()}, dagpb.Type.PBNode) + require.NoError(t, err) + _, err = hamt.AttemptHAMTShardFromNode(ctx, nd, lsys) + require.Error(t, err) + + // empty protobuf w/o data + nd, err = qp.BuildMap(dagpb.Type.PBNode, -1, func(ma ipld.MapAssembler) { + qp.MapEntry(ma, "Links", qp.List(-1, func(ipld.ListAssembler) {})) + }) + require.NoError(t, err) + + _, err = hamt.AttemptHAMTShardFromNode(ctx, nd, lsys) + require.Error(t, err) +} + +func TestFindNonExisting(t *testing.T) { + ds, lsys := mockDag() + _, s, err := makeDir(ds, 100) + if err != nil { + t.Fatal(err) + } + ctx := context.Background() + legacyNode, err := s.Node() + require.NoError(t, err) + nd, err := lsys.Load(ipld.LinkContext{Ctx: ctx}, cidlink.Link{Cid: legacyNode.Cid()}, dagpb.Type.PBNode) + require.NoError(t, err) + hamtShard, err := hamt.AttemptHAMTShardFromNode(ctx, nd, lsys) + require.NoError(t, err) + for i := 0; i < 200; i++ { + key := fmt.Sprintf("notfound%d", i) + _, err := hamtShard.LookupByString(key) + require.EqualError(t, err, schema.ErrNoSuchField{Field: ipld.PathSegmentOfString(key)}.Error()) + } +} diff --git a/unixfs/node/hamt/util.go b/unixfs/node/hamt/util.go new file mode 100644 index 000000000..d58ce5a66 --- /dev/null +++ b/unixfs/node/hamt/util.go @@ -0,0 +1,129 @@ +package hamt + +// adapted from https://github.com/ipfs/go-unixfs/blob/master/hamt/util.go + +import ( + "fmt" + + "math/bits" + + "github.com/Stebalien/go-bitfield" + "github.com/ipfs/go-unixfsnode/data" + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/spaolacci/murmur3" +) + +// hashBits is a helper that allows the reading of the 'next n bits' as an integer. +type hashBits struct { + b []byte + consumed int +} + +func mkmask(n int) byte { + return (1 << uint(n)) - 1 +} + +// Next returns the next 'i' bits of the hashBits value as an integer, or an +// error if there aren't enough bits. +func (hb *hashBits) Next(i int) (int, error) { + if hb.consumed+i > len(hb.b)*8 { + return 0, fmt.Errorf("sharded directory too deep") + } + return hb.next(i), nil +} + +func (hb *hashBits) next(i int) int { + curbi := hb.consumed / 8 + leftb := 8 - (hb.consumed % 8) + + curb := hb.b[curbi] + if i == leftb { + out := int(mkmask(i) & curb) + hb.consumed += i + return out + } else if i < leftb { + a := curb & mkmask(leftb) // mask out the high bits we don't want + b := a & ^mkmask(leftb-i) // mask out the low bits we don't want + c := b >> uint(leftb-i) // shift whats left down + hb.consumed += i + return int(c) + } else { + out := int(mkmask(leftb) & curb) + out <<= uint(i - leftb) + hb.consumed += leftb + out += hb.next(i - leftb) + return out + } +} + +func ValidateHAMTData(nd data.UnixFSData) error { + if nd.FieldDataType().Int() != data.Data_HAMTShard { + return data.ErrWrongNodeType{data.Data_HAMTShard, nd.FieldDataType().Int()} + } + + if !nd.FieldHashType().Exists() || uint64(nd.FieldHashType().Must().Int()) != HashMurmur3 { + return fmt.Errorf("only murmur3 supported as hash function") + } + + if !nd.FieldData().Exists() { + return fmt.Errorf("Data field not present") + } + + if !nd.FieldFanout().Exists() { + return fmt.Errorf("Fanout field not present") + } + if err := checkLogTwo(int(nd.FieldFanout().Must().Int())); err != nil { + return err + } + + return nil +} + +func Log2Size(nd data.UnixFSData) int { + return bits.TrailingZeros(uint(nd.FieldFanout().Must().Int())) +} + +func MaxPadLength(nd data.UnixFSData) int { + return len(fmt.Sprintf("%X", nd.FieldFanout().Must().Int()-1)) +} + +func BitField(nd data.UnixFSData) bitfield.Bitfield { + bf := bitfield.NewBitfield(int(nd.FieldFanout().Must().Int())) + bf.SetBytes(nd.FieldData().Must().Bytes()) + return bf +} + +func checkLogTwo(v int) error { + if v <= 0 { + return fmt.Errorf("hamt size should be a power of two") + } + lg2 := bits.TrailingZeros(uint(v)) + if 1< Date: Wed, 31 Mar 2021 21:13:55 -0700 Subject: [PATCH 05/43] feat(directory): seperate directory implementation move basic directory to its own package, redo root package based on more flexible refication and more flexible node prototype This commit was moved from ipfs/go-unixfsnode@67a7e3864a940b28c3b781f17ce24ca1b541549b --- unixfs/node/directory/basicdir.go | 168 +++++++++++++++++++++++++ unixfs/node/hamt/shardeddir.go | 16 +-- unixfs/node/link.go | 23 ---- unixfs/node/node.go | 201 ------------------------------ unixfs/node/nodeprototype.go | 43 +++++-- unixfs/node/reification.go | 44 +++++-- 6 files changed, 243 insertions(+), 252 deletions(-) create mode 100644 unixfs/node/directory/basicdir.go delete mode 100644 unixfs/node/link.go delete mode 100644 unixfs/node/node.go diff --git a/unixfs/node/directory/basicdir.go b/unixfs/node/directory/basicdir.go new file mode 100644 index 000000000..a766421fc --- /dev/null +++ b/unixfs/node/directory/basicdir.go @@ -0,0 +1,168 @@ +package directory + +import ( + "context" + + "github.com/ipfs/go-unixfsnode/data" + "github.com/ipfs/go-unixfsnode/iter" + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/schema" +) + +var _ ipld.Node = UnixFSBasicDir(nil) +var _ schema.TypedNode = UnixFSBasicDir(nil) + +type UnixFSBasicDir = *_UnixFSBasicDir + +type _UnixFSBasicDir struct { + _substrate dagpb.PBNode +} + +func NewUnixFSBasicDir(ctx context.Context, substrate dagpb.PBNode, nddata data.UnixFSData, _ *ipld.LinkSystem) (ipld.Node, error) { + if nddata.FieldDataType().Int() != data.Data_Directory { + return nil, data.ErrWrongNodeType{data.Data_Directory, nddata.FieldDataType().Int()} + } + return &_UnixFSBasicDir{_substrate: substrate}, nil +} + +func (n UnixFSBasicDir) Kind() ipld.Kind { + return n._substrate.Kind() +} + +// LookupByString looks for the key in the list of links with a matching name +func (n UnixFSBasicDir) LookupByString(key string) (ipld.Node, error) { + links := n._substrate.FieldLinks() + link := lookup(links, key) + if link == nil { + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} + } + return link, nil +} + +func (n UnixFSBasicDir) LookupByNode(key ipld.Node) (ipld.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} + +func (n UnixFSBasicDir) LookupByIndex(idx int64) (ipld.Node, error) { + return n._substrate.LookupByIndex(idx) +} + +func (n UnixFSBasicDir) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return n.LookupByString(seg.String()) +} + +func (n UnixFSBasicDir) MapIterator() ipld.MapIterator { + return iter.NewUnixFSDirMapIterator(n._substrate.Links.Iterator(), nil) +} + +// ListIterator returns an iterator which yields key-value pairs +// traversing the node. +// If the node kind is anything other than a list, nil will be returned. +// +// The iterator will yield every entry in the list; that is, it +// can be expected that itr.Next will be called node.Length times +// before itr.Done becomes true. +func (n UnixFSBasicDir) ListIterator() ipld.ListIterator { + return nil +} + +// Length returns the length of a list, or the number of entries in a map, +// or -1 if the node is not of list nor map kind. +func (n UnixFSBasicDir) Length() int64 { + return n._substrate.FieldLinks().Length() +} + +func (n UnixFSBasicDir) IsAbsent() bool { + return false +} + +func (n UnixFSBasicDir) IsNull() bool { + return false +} + +func (n UnixFSBasicDir) AsBool() (bool, error) { + return n._substrate.AsBool() +} + +func (n UnixFSBasicDir) AsInt() (int64, error) { + return n._substrate.AsInt() +} + +func (n UnixFSBasicDir) AsFloat() (float64, error) { + return n._substrate.AsFloat() +} + +func (n UnixFSBasicDir) AsString() (string, error) { + return n._substrate.AsString() +} + +func (n UnixFSBasicDir) AsBytes() ([]byte, error) { + return n._substrate.AsBytes() +} + +func (n UnixFSBasicDir) AsLink() (ipld.Link, error) { + return n._substrate.AsLink() +} + +func (n UnixFSBasicDir) Prototype() ipld.NodePrototype { + // TODO: should this return something? + // probobly not until we write the write interfaces + return nil +} + +// satisfy schema.TypedNode +func (UnixFSBasicDir) Type() schema.Type { + return nil /*TODO:typelit*/ +} + +func (n UnixFSBasicDir) Representation() ipld.Node { + return n._substrate.Representation() +} + +// Native map accessors + +func (n UnixFSBasicDir) Iterator() *iter.UnixFSDir__Itr { + + return iter.NewUnixFSDirIterator(n._substrate.Links.Iterator(), nil) +} + +func (n UnixFSBasicDir) Lookup(key dagpb.String) dagpb.Link { + return lookup(n._substrate.FieldLinks(), key.String()) +} + +// direct access to the links and data + +func (n UnixFSBasicDir) FieldLinks() dagpb.PBLinks { + return n._substrate.FieldLinks() +} + +func (n UnixFSBasicDir) FieldData() dagpb.MaybeBytes { + return n._substrate.FieldData() +} + +// we need to lookup by key in a list of dag pb links a fair amount, so just have +// a shortcut method +func lookup(links dagpb.PBLinks, key string) dagpb.Link { + li := links.Iterator() + for !li.Done() { + _, next := li.Next() + name := "" + if next.FieldName().Exists() { + name = next.FieldName().Must().String() + } + if key == name { + return next.FieldHash() + } + } + return nil +} + +// Substrate returns the underlying PBNode -- note: only the substrate will encode successfully to protobuf if writing +func (n UnixFSBasicDir) Substrate() ipld.Node { + return n._substrate +} diff --git a/unixfs/node/hamt/shardeddir.go b/unixfs/node/hamt/shardeddir.go index 89e6ebe05..1fa409936 100644 --- a/unixfs/node/hamt/shardeddir.go +++ b/unixfs/node/hamt/shardeddir.go @@ -56,14 +56,10 @@ func (n UnixFSHAMTShard) Kind() ipld.Kind { // LookupByString looks for the key in the list of links with a matching name func (n UnixFSHAMTShard) LookupByString(key string) (ipld.Node, error) { hv := &hashBits{b: hash([]byte(key))} - pbLink, err := n.lookup(key, hv) - if err != nil { - return nil, err - } - return pbLink.FieldHash(), nil + return n.lookup(key, hv) } -func (n UnixFSHAMTShard) lookup(key string, hv *hashBits) (dagpb.PBLink, error) { +func (n UnixFSHAMTShard) lookup(key string, hv *hashBits) (dagpb.Link, error) { log2 := Log2Size(n.data) maxPadLength := MaxPadLength(n.data) childIndex, err := hv.Next(log2) @@ -82,7 +78,7 @@ func (n UnixFSHAMTShard) lookup(key string, hv *hashBits) (dagpb.PBLink, error) } if isValue { if MatchKey(pbLink, key, maxPadLength) { - return pbLink, nil + return pbLink.FieldHash(), nil } } else { childNd, err := n.loadChild(pbLink) @@ -312,13 +308,13 @@ func (n UnixFSHAMTShard) Iterator() *iter.UnixFSDir__Itr { return iter.NewUnixFSDirIterator(listItr, st.transformNameNode) } -func (n UnixFSHAMTShard) Lookup(key dagpb.String) dagpb.PBLink { +func (n UnixFSHAMTShard) Lookup(key dagpb.String) dagpb.Link { hv := &hashBits{b: hash([]byte(key.String()))} - pbLink, err := n.lookup(key.String(), hv) + link, err := n.lookup(key.String(), hv) if err != nil { return nil } - return pbLink + return link } // direct access to the links and data diff --git a/unixfs/node/link.go b/unixfs/node/link.go deleted file mode 100644 index 21eeaa277..000000000 --- a/unixfs/node/link.go +++ /dev/null @@ -1,23 +0,0 @@ -package unixfsnode - -import ( - dagpb "github.com/ipld/go-codec-dagpb" - "github.com/ipld/go-ipld-prime" - "github.com/ipld/go-ipld-prime/schema" -) - -var _ ipld.Node = UnixFSLink(nil) -var _ schema.TypedNode = UnixFSLink(nil) -var _ schema.TypedLinkNode = UnixFSLink(nil) - -// UnixFSLink just adds a LinkTargetNodePrototype method to dagpb.Link so that you can cross -// link boundaries correctly in path traversals -type UnixFSLink = *_UnixFSLink - -type _UnixFSLink struct { - dagpb.Link -} - -func (n UnixFSLink) LinkTargetNodePrototype() ipld.NodePrototype { - return _UnixFSNode__Prototype{} -} diff --git a/unixfs/node/node.go b/unixfs/node/node.go deleted file mode 100644 index df4cf90ac..000000000 --- a/unixfs/node/node.go +++ /dev/null @@ -1,201 +0,0 @@ -package unixfsnode - -import ( - dagpb "github.com/ipld/go-codec-dagpb" - "github.com/ipld/go-ipld-prime" - "github.com/ipld/go-ipld-prime/schema" -) - -var _ ipld.Node = UnixFSNode(nil) -var _ schema.TypedNode = UnixFSNode(nil) - -type UnixFSNode = *_UnixFSNode - -type _UnixFSNode struct { - _substrate dagpb.PBNode -} - -func (n UnixFSNode) Kind() ipld.Kind { - return n._substrate.Kind() -} - -// LookupByString looks for the key in the list of links with a matching name -func (n UnixFSNode) LookupByString(key string) (ipld.Node, error) { - links := n._substrate.FieldLinks() - link := lookup(links, key) - if link == nil { - return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} - } - return link, nil -} - -func (n UnixFSNode) LookupByNode(key ipld.Node) (ipld.Node, error) { - ks, err := key.AsString() - if err != nil { - return nil, err - } - return n.LookupByString(ks) -} - -func (n UnixFSNode) LookupByIndex(idx int64) (ipld.Node, error) { - return n._substrate.LookupByIndex(idx) -} - -func (n UnixFSNode) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { - return n.LookupByString(seg.String()) -} - -func (n UnixFSNode) MapIterator() ipld.MapIterator { - return &UnixFSNode__MapItr{n._substrate.Links.Iterator()} -} - -// UnixFSNode map iterator iterates throught the links as if they were a map -// Note: for now it does return links with no name, where the key is just String("") -type UnixFSNode__MapItr struct { - _substrate *dagpb.PBLinks__Itr -} - -func (itr *UnixFSNode__MapItr) Next() (k ipld.Node, v ipld.Node, err error) { - _, next := itr._substrate.Next() - if next == nil { - return nil, nil, ipld.ErrIteratorOverread{} - } - if next.FieldName().Exists() { - return next.FieldName().Must(), &_UnixFSLink{next.FieldHash()}, nil - } - nb := dagpb.Type.String.NewBuilder() - err = nb.AssignString("") - if err != nil { - return nil, nil, err - } - s := nb.Build() - return s, next.FieldHash(), nil -} - -func (itr *UnixFSNode__MapItr) Done() bool { - return itr._substrate.Done() -} - -// ListIterator returns an iterator which yields key-value pairs -// traversing the node. -// If the node kind is anything other than a list, nil will be returned. -// -// The iterator will yield every entry in the list; that is, it -// can be expected that itr.Next will be called node.Length times -// before itr.Done becomes true. -func (n UnixFSNode) ListIterator() ipld.ListIterator { - return nil -} - -// Length returns the length of a list, or the number of entries in a map, -// or -1 if the node is not of list nor map kind. -func (n UnixFSNode) Length() int64 { - return n._substrate.FieldLinks().Length() -} - -func (n UnixFSNode) IsAbsent() bool { - return false -} - -func (n UnixFSNode) IsNull() bool { - return false -} - -func (n UnixFSNode) AsBool() (bool, error) { - return n._substrate.AsBool() -} - -func (n UnixFSNode) AsInt() (int64, error) { - return n._substrate.AsInt() -} - -func (n UnixFSNode) AsFloat() (float64, error) { - return n._substrate.AsFloat() -} - -func (n UnixFSNode) AsString() (string, error) { - return n._substrate.AsString() -} - -func (n UnixFSNode) AsBytes() ([]byte, error) { - return n._substrate.AsBytes() -} - -func (n UnixFSNode) AsLink() (ipld.Link, error) { - return n._substrate.AsLink() -} - -func (n UnixFSNode) Prototype() ipld.NodePrototype { - return _UnixFSNode__Prototype{} -} - -// satisfy schema.TypedNode -func (UnixFSNode) Type() schema.Type { - return nil /*TODO:typelit*/ -} - -func (n UnixFSNode) Representation() ipld.Node { - return n._substrate.Representation() -} - -// Native map accessors - -func (n UnixFSNode) Iterator() *UnixFSNode__Itr { - - return &UnixFSNode__Itr{n._substrate.Links.Iterator()} -} - -type UnixFSNode__Itr struct { - _substrate *dagpb.PBLinks__Itr -} - -func (itr *UnixFSNode__Itr) Next() (k dagpb.String, v UnixFSLink) { - _, next := itr._substrate.Next() - if next == nil { - return nil, nil - } - if next.FieldName().Exists() { - return next.FieldName().Must(), &_UnixFSLink{next.FieldHash()} - } - nb := dagpb.Type.String.NewBuilder() - err := nb.AssignString("") - if err != nil { - return nil, nil - } - s := nb.Build() - return s.(dagpb.String), &_UnixFSLink{next.FieldHash()} -} -func (itr *UnixFSNode__Itr) Done() bool { - return itr._substrate.Done() -} - -func (n UnixFSNode) Lookup(key dagpb.String) UnixFSLink { - return lookup(n._substrate.FieldLinks(), key.String()) -} - -// direct access to the links and data - -func (n UnixFSNode) FieldLinks() dagpb.PBLinks { - return n._substrate.FieldLinks() -} - -func (n UnixFSNode) FieldData() dagpb.MaybeBytes { - return n._substrate.FieldData() -} - -// we need to lookup by key in a list of dag pb links a fair amount, so just have -// a shortcut method -func lookup(links dagpb.PBLinks, key string) UnixFSLink { - li := links.Iterator() - for !li.Done() { - _, next := li.Next() - name := "" - if next.FieldName().Exists() { - name = next.FieldName().Must().String() - } - if key == name { - return &_UnixFSLink{next.FieldHash()} - } - } - return nil -} diff --git a/unixfs/node/nodeprototype.go b/unixfs/node/nodeprototype.go index 93847ec47..c480d3afc 100644 --- a/unixfs/node/nodeprototype.go +++ b/unixfs/node/nodeprototype.go @@ -1,38 +1,63 @@ package unixfsnode import ( + "context" + dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" + cidlink "github.com/ipld/go-ipld-prime/linking/cid" + "github.com/ipld/go-ipld-prime/traversal" ) +type prototypeChooser struct { + lsys *ipld.LinkSystem + existing traversal.LinkTargetNodePrototypeChooser +} + // NodeBuilder for UnixFS Nodes -- note: this expects underlying data that // has the same format as a normal dagpb node -- in fact, it uses the // exact same builder but then wraps at the end -var Type typeSlab - -type typeSlab struct { - UnixFSNode _UnixFSNode__Prototype +type _UnixFSNode__Prototype struct { + ctx context.Context + lsys *ipld.LinkSystem } -type _UnixFSNode__Prototype struct{} - -func (_UnixFSNode__Prototype) NewBuilder() ipld.NodeBuilder { +func (p _UnixFSNode__Prototype) NewBuilder() ipld.NodeBuilder { var nb _UnixFSNode__Builder + nb.ctx = p.ctx + nb.lsys = p.lsys nb.Reset() return &nb } type _UnixFSNode__Builder struct { ipld.NodeBuilder + ctx context.Context + lsys *ipld.LinkSystem } func (nb *_UnixFSNode__Builder) Build() ipld.Node { n := nb.NodeBuilder.Build().(dagpb.PBNode) - return &_UnixFSNode{_substrate: n} + un, err := Reify(nb.ctx, n, nb.lsys) + if err != nil { + return n + } + return un } func (nb *_UnixFSNode__Builder) Reset() { snb := dagpb.Type.PBNode.NewBuilder() - *nb = _UnixFSNode__Builder{snb} + *nb = _UnixFSNode__Builder{snb, nb.ctx, nb.lsys} +} + +func (pc prototypeChooser) choose(lnk ipld.Link, lnkCtx ipld.LinkContext) (ipld.NodePrototype, error) { + if lnk, ok := lnk.(cidlink.Link); ok && lnk.Cid.Prefix().Codec == 0x70 { + return _UnixFSNode__Prototype{lnkCtx.Ctx, pc.lsys}, nil + } + return pc.existing(lnk, lnkCtx) +} + +func AugmentPrototypeChooser(lsys *ipld.LinkSystem, existing traversal.LinkTargetNodePrototypeChooser) traversal.LinkTargetNodePrototypeChooser { + return prototypeChooser{lsys: lsys, existing: existing}.choose } diff --git a/unixfs/node/reification.go b/unixfs/node/reification.go index 4115c76bc..389a8dc78 100644 --- a/unixfs/node/reification.go +++ b/unixfs/node/reification.go @@ -1,30 +1,56 @@ package unixfsnode import ( + "context" "fmt" + "github.com/ipfs/go-unixfsnode/data" + "github.com/ipfs/go-unixfsnode/directory" + "github.com/ipfs/go-unixfsnode/hamt" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" ) -// Reify looks at an ipld Node and tries to interpret it as a UnixFSNode -// if successful, it returns the UnixFSNode -func Reify(maybePBNodeRoot ipld.Node) (ipld.Node, error) { +func asPBNode(maybePBNodeRoot ipld.Node) (dagpb.PBNode, error) { if pbNode, ok := maybePBNodeRoot.(dagpb.PBNode); ok { - return &_UnixFSNode{_substrate: pbNode}, nil + return pbNode, nil } // Shortcut didn't work. Process via the data model. // The AssignNode method on the pb node already contains all the logic necessary for this, so we use that. nb := dagpb.Type.PBNode.NewBuilder() if err := nb.AssignNode(maybePBNodeRoot); err != nil { - return nil, fmt.Errorf("unixfsnode.Reify failed: data does not match expected shape for Protobuf Node: %w", err) + return nil, err } - return &_UnixFSNode{nb.Build().(dagpb.PBNode)}, nil + return nb.Build().(dagpb.PBNode), nil +} +// Reify looks at an ipld Node and tries to interpret it as a UnixFSNode +// if successful, it returns the UnixFSNode +func Reify(ctx context.Context, maybePBNodeRoot ipld.Node, lsys *ipld.LinkSystem) (ipld.Node, error) { + pbNode, err := asPBNode(maybePBNodeRoot) + if err != nil { + return nil, fmt.Errorf("unixfsnode.Reify failed: data does not match expected shape for Protobuf Node: %w", err) + } + if !pbNode.FieldData().Exists() { + // no data field, therefore, not UnixFS + return pbNode, nil + } + data, err := data.DecodeUnixFSData(pbNode.Data.Must().Bytes()) + if err != nil { + // we could not decode the UnixFS data, therefore, not UnixFS + return pbNode, nil + } + builder, ok := reifyFuncs[data.FieldDataType().Int()] + if !ok { + return nil, fmt.Errorf("No reification for this UnixFS node type") + } + return builder(ctx, pbNode, data, lsys) } -// Substrate returns the underlying PBNode -- note: only the substrate will encode successfully to protobuf if writing -func (n UnixFSNode) Substrate() ipld.Node { - return n._substrate +type reifyTypeFunc func(context.Context, dagpb.PBNode, data.UnixFSData, *ipld.LinkSystem) (ipld.Node, error) + +var reifyFuncs = map[int64]reifyTypeFunc{ + data.Data_Directory: directory.NewUnixFSBasicDir, + data.Data_HAMTShard: hamt.NewUnixFSHAMTShard, } From 34a81a18d20dc0cfec525b76eb5c908df7ad1187 Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Thu, 1 Apr 2021 15:14:57 -0700 Subject: [PATCH 06/43] fix(unixfsnode): have reifier add path selection to normal nodes have reifier add path selection to all protobuf nodes, even ones that are not unixfs This commit was moved from ipfs/go-unixfsnode@d6733f6db69431075c9cf7b30e0ee1f6a082f4b0 --- unixfs/node/directory/basicdir.go | 22 +---- unixfs/node/pathpbnode.go | 142 ++++++++++++++++++++++++++++++ unixfs/node/reification.go | 10 ++- unixfs/node/utils/utils.go | 19 ++++ 4 files changed, 172 insertions(+), 21 deletions(-) create mode 100644 unixfs/node/pathpbnode.go create mode 100644 unixfs/node/utils/utils.go diff --git a/unixfs/node/directory/basicdir.go b/unixfs/node/directory/basicdir.go index a766421fc..efa7c5652 100644 --- a/unixfs/node/directory/basicdir.go +++ b/unixfs/node/directory/basicdir.go @@ -5,6 +5,7 @@ import ( "github.com/ipfs/go-unixfsnode/data" "github.com/ipfs/go-unixfsnode/iter" + "github.com/ipfs/go-unixfsnode/utils" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" "github.com/ipld/go-ipld-prime/schema" @@ -33,7 +34,7 @@ func (n UnixFSBasicDir) Kind() ipld.Kind { // LookupByString looks for the key in the list of links with a matching name func (n UnixFSBasicDir) LookupByString(key string) (ipld.Node, error) { links := n._substrate.FieldLinks() - link := lookup(links, key) + link := utils.Lookup(links, key) if link == nil { return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} } @@ -132,7 +133,7 @@ func (n UnixFSBasicDir) Iterator() *iter.UnixFSDir__Itr { } func (n UnixFSBasicDir) Lookup(key dagpb.String) dagpb.Link { - return lookup(n._substrate.FieldLinks(), key.String()) + return utils.Lookup(n._substrate.FieldLinks(), key.String()) } // direct access to the links and data @@ -145,23 +146,6 @@ func (n UnixFSBasicDir) FieldData() dagpb.MaybeBytes { return n._substrate.FieldData() } -// we need to lookup by key in a list of dag pb links a fair amount, so just have -// a shortcut method -func lookup(links dagpb.PBLinks, key string) dagpb.Link { - li := links.Iterator() - for !li.Done() { - _, next := li.Next() - name := "" - if next.FieldName().Exists() { - name = next.FieldName().Must().String() - } - if key == name { - return next.FieldHash() - } - } - return nil -} - // Substrate returns the underlying PBNode -- note: only the substrate will encode successfully to protobuf if writing func (n UnixFSBasicDir) Substrate() ipld.Node { return n._substrate diff --git a/unixfs/node/pathpbnode.go b/unixfs/node/pathpbnode.go new file mode 100644 index 000000000..969c53c3a --- /dev/null +++ b/unixfs/node/pathpbnode.go @@ -0,0 +1,142 @@ +package unixfsnode + +import ( + "github.com/ipfs/go-unixfsnode/iter" + "github.com/ipfs/go-unixfsnode/utils" + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/schema" +) + +var _ ipld.Node = PathedPBNode(nil) +var _ schema.TypedNode = PathedPBNode(nil) + +type PathedPBNode = *_PathedPBNode + +type _PathedPBNode struct { + _substrate dagpb.PBNode +} + +func (n PathedPBNode) Kind() ipld.Kind { + return n._substrate.Kind() +} + +// LookupByString looks for the key in the list of links with a matching name +func (n PathedPBNode) LookupByString(key string) (ipld.Node, error) { + links := n._substrate.FieldLinks() + link := utils.Lookup(links, key) + if link == nil { + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} + } + return link, nil +} + +func (n PathedPBNode) LookupByNode(key ipld.Node) (ipld.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} + +func (n PathedPBNode) LookupByIndex(idx int64) (ipld.Node, error) { + return n._substrate.LookupByIndex(idx) +} + +func (n PathedPBNode) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return n.LookupByString(seg.String()) +} + +func (n PathedPBNode) MapIterator() ipld.MapIterator { + return iter.NewUnixFSDirMapIterator(n._substrate.Links.Iterator(), nil) +} + +// ListIterator returns an iterator which yields key-value pairs +// traversing the node. +// If the node kind is anything other than a list, nil will be returned. +// +// The iterator will yield every entry in the list; that is, it +// can be expected that itr.Next will be called node.Length times +// before itr.Done becomes true. +func (n PathedPBNode) ListIterator() ipld.ListIterator { + return nil +} + +// Length returns the length of a list, or the number of entries in a map, +// or -1 if the node is not of list nor map kind. +func (n PathedPBNode) Length() int64 { + return n._substrate.FieldLinks().Length() +} + +func (n PathedPBNode) IsAbsent() bool { + return false +} + +func (n PathedPBNode) IsNull() bool { + return false +} + +func (n PathedPBNode) AsBool() (bool, error) { + return n._substrate.AsBool() +} + +func (n PathedPBNode) AsInt() (int64, error) { + return n._substrate.AsInt() +} + +func (n PathedPBNode) AsFloat() (float64, error) { + return n._substrate.AsFloat() +} + +func (n PathedPBNode) AsString() (string, error) { + return n._substrate.AsString() +} + +func (n PathedPBNode) AsBytes() ([]byte, error) { + return n._substrate.AsBytes() +} + +func (n PathedPBNode) AsLink() (ipld.Link, error) { + return n._substrate.AsLink() +} + +func (n PathedPBNode) Prototype() ipld.NodePrototype { + // TODO: should this return something? + // probobly not until we write the write interfaces + return nil +} + +// satisfy schema.TypedNode +func (PathedPBNode) Type() schema.Type { + return nil /*TODO:typelit*/ +} + +func (n PathedPBNode) Representation() ipld.Node { + return n._substrate.Representation() +} + +// Native map accessors + +func (n PathedPBNode) Iterator() *iter.UnixFSDir__Itr { + + return iter.NewUnixFSDirIterator(n._substrate.Links.Iterator(), nil) +} + +func (n PathedPBNode) Lookup(key dagpb.String) dagpb.Link { + return utils.Lookup(n._substrate.FieldLinks(), key.String()) +} + +// direct access to the links and data + +func (n PathedPBNode) FieldLinks() dagpb.PBLinks { + return n._substrate.FieldLinks() +} + +func (n PathedPBNode) FieldData() dagpb.MaybeBytes { + return n._substrate.FieldData() +} + +// Substrate returns the underlying PBNode -- note: only the substrate will encode successfully to protobuf if writing +func (n PathedPBNode) Substrate() ipld.Node { + return n._substrate +} diff --git a/unixfs/node/reification.go b/unixfs/node/reification.go index 389a8dc78..2d8bb54bc 100644 --- a/unixfs/node/reification.go +++ b/unixfs/node/reification.go @@ -34,12 +34,12 @@ func Reify(ctx context.Context, maybePBNodeRoot ipld.Node, lsys *ipld.LinkSystem } if !pbNode.FieldData().Exists() { // no data field, therefore, not UnixFS - return pbNode, nil + return defaultReifier(ctx, pbNode, lsys) } data, err := data.DecodeUnixFSData(pbNode.Data.Must().Bytes()) if err != nil { // we could not decode the UnixFS data, therefore, not UnixFS - return pbNode, nil + return defaultReifier(ctx, pbNode, lsys) } builder, ok := reifyFuncs[data.FieldDataType().Int()] if !ok { @@ -54,3 +54,9 @@ var reifyFuncs = map[int64]reifyTypeFunc{ data.Data_Directory: directory.NewUnixFSBasicDir, data.Data_HAMTShard: hamt.NewUnixFSHAMTShard, } + +// treat non-unixFS nodes like directories -- allow them to lookup by link +// TODO: Make this a separate node as directors gain more functionality +func defaultReifier(_ context.Context, substrate dagpb.PBNode, _ *ipld.LinkSystem) (ipld.Node, error) { + return &_PathedPBNode{_substrate: substrate}, nil +} diff --git a/unixfs/node/utils/utils.go b/unixfs/node/utils/utils.go new file mode 100644 index 000000000..9543835d1 --- /dev/null +++ b/unixfs/node/utils/utils.go @@ -0,0 +1,19 @@ +package utils + +import dagpb "github.com/ipld/go-codec-dagpb" + +// Lookup finds a name key in a list of dag pb links +func Lookup(links dagpb.PBLinks, key string) dagpb.Link { + li := links.Iterator() + for !li.Done() { + _, next := li.Next() + name := "" + if next.FieldName().Exists() { + name = next.FieldName().Must().String() + } + if key == name { + return next.FieldHash() + } + } + return nil +} From 1e0dabf8aa24acd214e500439d790459f74d82b7 Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Thu, 1 Apr 2021 18:31:39 -0700 Subject: [PATCH 07/43] fix(unixfsnode): cleanup from comments respond to PR comments -- make error types, etc This commit was moved from ipfs/go-unixfsnode@1854f92b2bc8e4d52bd744f638ff1a49194f2b57 --- unixfs/node/data/builder/builder.go | 35 +- unixfs/node/data/doc.go | 14 + unixfs/node/data/errors.go | 21 + unixfs/node/data/format_test.go | 40 +- unixfs/node/data/ipldsch_satisfaction.go | 605 ++++++++++------------- unixfs/node/data/permissions.go | 2 + unixfs/node/data/unmarshal.go | 23 +- unixfs/node/hamt/errors.go | 40 ++ unixfs/node/hamt/shardeddir.go | 13 +- unixfs/node/hamt/util.go | 16 +- 10 files changed, 404 insertions(+), 405 deletions(-) create mode 100644 unixfs/node/data/doc.go create mode 100644 unixfs/node/hamt/errors.go diff --git a/unixfs/node/data/builder/builder.go b/unixfs/node/data/builder/builder.go index b52a1241c..1326f23b5 100644 --- a/unixfs/node/data/builder/builder.go +++ b/unixfs/node/data/builder/builder.go @@ -2,7 +2,6 @@ package builder import ( "errors" - "fmt" "strconv" "time" @@ -11,7 +10,18 @@ import ( "github.com/ipld/go-ipld-prime/fluent/qp" ) -func BuildUnixFs(fn func(*Builder)) (data.UnixFSData, error) { +// BuildUnixFS provides a clean, validated interface to building data structures +// that match the UnixFS protobuf encoded in the Data member of a ProtoNode +// with sensible defaults +// +// smallFileData, err := BuildUnixFS(func(b *Builder) { +// Data(b, []byte{"hello world"}) +// MTime(b, func(tb TimeBuilder) { +// Time(tb, time.Now()) +// }) +// }) +// +func BuildUnixFS(fn func(*Builder)) (data.UnixFSData, error) { nd, err := qp.BuildMap(data.Type.UnixFSData, -1, func(ma ipld.MapAssembler) { b := &Builder{MapAssembler: ma} fn(b) @@ -28,30 +38,35 @@ func BuildUnixFs(fn func(*Builder)) (data.UnixFSData, error) { return nd.(data.UnixFSData), nil } +// Builder is an interface for making UnixFS data nodes type Builder struct { ipld.MapAssembler hasDataType bool hasBlockSizes bool } +// DataType sets the default on a builder for a UnixFS node - default is File func DataType(b *Builder, dataType int64) { _, ok := data.DataTypeNames[dataType] if !ok { - panic(fmt.Errorf("Type: %d is not valid", dataType)) + panic(data.ErrInvalidDataType{dataType}) } qp.MapEntry(b.MapAssembler, "DataType", qp.Int(dataType)) b.hasDataType = true } +// Data sets the data member inside the UnixFS data func Data(b *Builder, data []byte) { qp.MapEntry(b.MapAssembler, "Data", qp.Bytes(data)) - } +// FileSize sets the file size which should be the size of actual bytes underneath +// this node for large files, w/o additional bytes to encode intermediate nodes func FileSize(b *Builder, fileSize uint64) { qp.MapEntry(b.MapAssembler, "FileSize", qp.Int(int64(fileSize))) } +// BlockSizes encodes block sizes for each child node func BlockSizes(b *Builder, blockSizes []uint64) { qp.MapEntry(b.MapAssembler, "BlockSizes", qp.List(int64(len(blockSizes)), func(la ipld.ListAssembler) { for _, bs := range blockSizes { @@ -61,14 +76,17 @@ func BlockSizes(b *Builder, blockSizes []uint64) { b.hasBlockSizes = true } +// HashFunc sets the hash function for this node -- only applicable to HAMT func HashFunc(b *Builder, hashFunc uint64) { qp.MapEntry(b.MapAssembler, "HashFunc", qp.Int(int64(hashFunc))) } +// Fanout sets the fanout in a HAMT tree func Fanout(b *Builder, fanout uint64) { qp.MapEntry(b.MapAssembler, "Fanout", qp.Int(int64(fanout))) } +// Permissions sets file permissions for the Mode member of the UnixFS node func Permissions(b *Builder, mode int) { mode = mode & 0xFFF qp.MapEntry(b.MapAssembler, "Mode", qp.Int(int64(mode))) @@ -81,6 +99,8 @@ func parseModeString(modeString string) (uint64, error) { return strconv.ParseUint(modeString, 10, 32) } +// PermissionsString sets file permissions for the Mode member of the UnixFS node, +// parsed from a typical octect encoded permission string (eg '0755') func PermissionsString(b *Builder, modeString string) { mode64, err := parseModeString(modeString) if err != nil { @@ -90,24 +110,31 @@ func PermissionsString(b *Builder, modeString string) { qp.MapEntry(b.MapAssembler, "Mode", qp.Int(int64(mode64))) } +// Mtime sets the modification time for this node using the time builder interface +// and associated methods func Mtime(b *Builder, fn func(tb TimeBuilder)) { qp.MapEntry(b.MapAssembler, "Mtime", qp.Map(-1, func(ma ipld.MapAssembler) { fn(ma) })) } +// TimeBuilder is a simple interface for constructing the time member of UnixFS data type TimeBuilder ipld.MapAssembler +// Time sets the modification time from a golang time value func Time(ma TimeBuilder, t time.Time) { Seconds(ma, t.Unix()) FractionalNanoseconds(ma, int32(t.Nanosecond())) } +// Seconds sets the seconds for a modification time func Seconds(ma TimeBuilder, seconds int64) { qp.MapEntry(ma, "Seconds", qp.Int(seconds)) } +// FractionalNanoseconds sets the nanoseconds for a modification time (must +// be between 0 & a billion) func FractionalNanoseconds(ma TimeBuilder, nanoseconds int32) { if nanoseconds < 0 || nanoseconds > 999999999 { panic(errors.New("mtime-nsecs must be within the range [0,999999999]")) diff --git a/unixfs/node/data/doc.go b/unixfs/node/data/doc.go new file mode 100644 index 000000000..6bb9a49e8 --- /dev/null +++ b/unixfs/node/data/doc.go @@ -0,0 +1,14 @@ +/* +Package data provides tools for working with the UnixFS data structure that +is encoded in the "Data" field of the larger a DagPB encoded IPLD node. + +See https://github.com/ipfs/specs/blob/master/UNIXFS.md for more information +about this data structure. + +This package provides an IPLD Prime compatible node interface for this data +structure, as well as methods for serializing and deserializing the data +structure to protobuf +*/ +package data + +//go:generate go run ./gen diff --git a/unixfs/node/data/errors.go b/unixfs/node/data/errors.go index 4a61dc66f..9cbe179fa 100644 --- a/unixfs/node/data/errors.go +++ b/unixfs/node/data/errors.go @@ -2,6 +2,8 @@ package data import ( "fmt" + + "google.golang.org/protobuf/encoding/protowire" ) type ErrWrongNodeType struct { @@ -20,3 +22,22 @@ func (e ErrWrongNodeType) Error() string { } return fmt.Sprintf("Incorrect Node Type: (UnixFSData) expected type: %s, actual type: %s", expectedName, actualName) } + +type ErrWrongWireType struct { + Module string + Field string + Expected protowire.Type + Actual protowire.Type +} + +func (e ErrWrongWireType) Error() string { + return fmt.Sprintf("protobuf: (%s) invalid wireType, field: %s, expected %d, got %d", e.Module, e.Field, e.Expected, e.Actual) +} + +type ErrInvalidDataType struct { + DataType int64 +} + +func (e ErrInvalidDataType) Error() string { + return fmt.Sprintf("Type: %d is not valid", e.DataType) +} diff --git a/unixfs/node/data/format_test.go b/unixfs/node/data/format_test.go index f9096aab4..d14a0ed6a 100644 --- a/unixfs/node/data/format_test.go +++ b/unixfs/node/data/format_test.go @@ -39,7 +39,7 @@ var symlink = loadFixture("symlink.txt.unixfs") func TestUnixfsFormat(t *testing.T) { t.Run("defaults to file", func(t *testing.T) { - data, err := builder.BuildUnixFs(func(*builder.Builder) {}) + data, err := builder.BuildUnixFS(func(*builder.Builder) {}) require.NoError(t, err) require.Equal(t, Data_File, data.FieldDataType().Int()) marshaled := EncodeUnixFSData(data) @@ -52,7 +52,7 @@ func TestUnixfsFormat(t *testing.T) { }) t.Run("raw", func(t *testing.T) { - data, err := builder.BuildUnixFs(func(b *builder.Builder) { + data, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_Raw) builder.Data(b, []byte("bananas")) }) @@ -67,7 +67,7 @@ func TestUnixfsFormat(t *testing.T) { }) t.Run("directory", func(t *testing.T) { - data, err := builder.BuildUnixFs(func(b *builder.Builder) { + data, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_Directory) }) require.NoError(t, err) @@ -81,7 +81,7 @@ func TestUnixfsFormat(t *testing.T) { }) t.Run("HAMTShard", func(t *testing.T) { - data, err := builder.BuildUnixFs(func(b *builder.Builder) { + data, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_HAMTShard) }) require.NoError(t, err) @@ -95,7 +95,7 @@ func TestUnixfsFormat(t *testing.T) { }) t.Run("file", func(t *testing.T) { - data, err := builder.BuildUnixFs(func(b *builder.Builder) { + data, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_File) builder.Data(b, []byte("batata")) }) @@ -110,7 +110,7 @@ func TestUnixfsFormat(t *testing.T) { }) t.Run("file add blocksize", func(t *testing.T) { - data, err := builder.BuildUnixFs(func(b *builder.Builder) { + data, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_File) builder.BlockSizes(b, []uint64{256}) }) @@ -127,7 +127,7 @@ func TestUnixfsFormat(t *testing.T) { t.Run("mode", func(t *testing.T) { mode, err := strconv.ParseInt("0555", 8, 32) require.NoError(t, err) - data, err := builder.BuildUnixFs(func(b *builder.Builder) { + data, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_File) builder.Permissions(b, int(mode)) }) @@ -139,7 +139,7 @@ func TestUnixfsFormat(t *testing.T) { }) t.Run("default mode for files", func(t *testing.T) { - data, err := builder.BuildUnixFs(func(b *builder.Builder) { + data, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_File) }) require.NoError(t, err) @@ -150,7 +150,7 @@ func TestUnixfsFormat(t *testing.T) { }) t.Run("default mode for directories", func(t *testing.T) { - data, err := builder.BuildUnixFs(func(b *builder.Builder) { + data, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_Directory) }) require.NoError(t, err) @@ -161,7 +161,7 @@ func TestUnixfsFormat(t *testing.T) { }) t.Run("default mode for hamt shards", func(t *testing.T) { - data, err := builder.BuildUnixFs(func(b *builder.Builder) { + data, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_HAMTShard) }) require.NoError(t, err) @@ -174,7 +174,7 @@ func TestUnixfsFormat(t *testing.T) { t.Run("mode as string", func(t *testing.T) { mode, err := strconv.ParseInt("0555", 8, 32) require.NoError(t, err) - data, err := builder.BuildUnixFs(func(b *builder.Builder) { + data, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_File) builder.PermissionsString(b, "0555") }) @@ -186,7 +186,7 @@ func TestUnixfsFormat(t *testing.T) { }) t.Run("mtime", func(t *testing.T) { - data, err := builder.BuildUnixFs(func(b *builder.Builder) { + data, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_File) builder.Mtime(b, func(tb builder.TimeBuilder) { builder.Seconds(tb, 5) @@ -204,7 +204,7 @@ func TestUnixfsFormat(t *testing.T) { seconds := now.Unix() nanosecond := now.Nanosecond() - data, err := builder.BuildUnixFs(func(b *builder.Builder) { + data, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_File) builder.Mtime(b, func(tb builder.TimeBuilder) { builder.Time(tb, now) @@ -222,7 +222,7 @@ func TestUnixfsFormat(t *testing.T) { }) t.Run("omits default file mode from protobuf", func(t *testing.T) { - data, err := builder.BuildUnixFs(func(b *builder.Builder) { + data, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_File) builder.Permissions(b, 0o0644) }) @@ -237,7 +237,7 @@ func TestUnixfsFormat(t *testing.T) { }) t.Run("omits default directory mode from protobuf", func(t *testing.T) { - data, err := builder.BuildUnixFs(func(b *builder.Builder) { + data, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_Directory) builder.Permissions(b, 0o0755) }) @@ -272,7 +272,7 @@ func TestUnixfsFormat(t *testing.T) { t.Run("ignores high bits in mode passed to constructor", func(t *testing.T) { mode := 0o0100644 // similar to output from fs.stat - entry, err := builder.BuildUnixFs(func(b *builder.Builder) { + entry, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_File) builder.Permissions(b, mode) }) @@ -291,7 +291,7 @@ func TestUnixfsFormat(t *testing.T) { // figuring out what is this metadata for https://github.com/ipfs/js-ipfs-data-importing/issues/3#issuecomment-182336526 t.Run("metadata", func(t *testing.T) { - data, err := builder.BuildUnixFs(func(b *builder.Builder) { + data, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_Metadata) }) require.NoError(t, err) @@ -304,7 +304,7 @@ func TestUnixfsFormat(t *testing.T) { }) t.Run("symlink", func(t *testing.T) { - data, err := builder.BuildUnixFs(func(b *builder.Builder) { + data, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_Symlink) }) require.NoError(t, err) @@ -318,7 +318,7 @@ func TestUnixfsFormat(t *testing.T) { }) t.Run("invalid type", func(t *testing.T) { - _, err := builder.BuildUnixFs(func(b *builder.Builder) { + _, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, 9999) }) require.EqualError(t, err, "Type: 9999 is not valid") @@ -365,7 +365,7 @@ func TestInterop(t *testing.T) { }) t.Run("empty", func(t *testing.T) { - data, err := builder.BuildUnixFs(func(b *builder.Builder) { + data, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, Data_File) }) require.NoError(t, err) diff --git a/unixfs/node/data/ipldsch_satisfaction.go b/unixfs/node/data/ipldsch_satisfaction.go index 2907b2445..f12024f52 100644 --- a/unixfs/node/data/ipldsch_satisfaction.go +++ b/unixfs/node/data/ipldsch_satisfaction.go @@ -26,15 +26,14 @@ func (n *_BlockSizes) LookupMaybe(idx int64) MaybeInt { } } -var _BlockSizes__valueAbsent = _Int__Maybe{m: schema.Maybe_Absent} - +var _BlockSizes__valueAbsent = _Int__Maybe{m:schema.Maybe_Absent} func (n BlockSizes) Iterator() *BlockSizes__Itr { return &BlockSizes__Itr{n, 0} } type BlockSizes__Itr struct { - n BlockSizes - idx int + n BlockSizes + idx int } func (itr *BlockSizes__Itr) Next() (idx int64, v Int) { @@ -67,14 +66,14 @@ func (m MaybeBlockSizes) Exists() bool { } func (m MaybeBlockSizes) AsNode() ipld.Node { switch m.m { - case schema.Maybe_Absent: - return ipld.Absent - case schema.Maybe_Null: - return ipld.Null - case schema.Maybe_Value: - return m.v - default: - panic("unreachable") + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") } } func (m MaybeBlockSizes) Must() BlockSizes { @@ -83,10 +82,8 @@ func (m MaybeBlockSizes) Must() BlockSizes { } return m.v } - var _ ipld.Node = (BlockSizes)(&_BlockSizes{}) var _ schema.TypedNode = (BlockSizes)(&_BlockSizes{}) - func (BlockSizes) Kind() ipld.Kind { return ipld.Kind_List } @@ -122,8 +119,8 @@ func (n BlockSizes) ListIterator() ipld.ListIterator { } type _BlockSizes__ListItr struct { - n BlockSizes - idx int + n BlockSizes + idx int } func (itr *_BlockSizes__ListItr) Next() (idx int64, v ipld.Node, _ error) { @@ -170,7 +167,6 @@ func (BlockSizes) AsLink() (ipld.Link, error) { func (BlockSizes) Prototype() ipld.NodePrototype { return _BlockSizes__Prototype{} } - type _BlockSizes__Prototype struct{} func (_BlockSizes__Prototype) NewBuilder() ipld.NodeBuilder { @@ -178,11 +174,9 @@ func (_BlockSizes__Prototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } - type _BlockSizes__Builder struct { _BlockSizes__Assembler } - func (nb *_BlockSizes__Builder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -194,10 +188,9 @@ func (nb *_BlockSizes__Builder) Reset() { var m schema.Maybe *nb = _BlockSizes__Builder{_BlockSizes__Assembler{w: &w, m: &m}} } - type _BlockSizes__Assembler struct { - w *_BlockSizes - m *schema.Maybe + w *_BlockSizes + m *schema.Maybe state laState cm schema.Maybe @@ -354,11 +347,8 @@ func (BlockSizes) Type() schema.Type { func (n BlockSizes) Representation() ipld.Node { return (*_BlockSizes__Repr)(n) } - type _BlockSizes__Repr _BlockSizes - var _ ipld.Node = &_BlockSizes__Repr{} - func (_BlockSizes__Repr) Kind() ipld.Kind { return ipld.Kind_List } @@ -436,7 +426,6 @@ func (_BlockSizes__Repr) AsLink() (ipld.Link, error) { func (_BlockSizes__Repr) Prototype() ipld.NodePrototype { return _BlockSizes__ReprPrototype{} } - type _BlockSizes__ReprPrototype struct{} func (_BlockSizes__ReprPrototype) NewBuilder() ipld.NodeBuilder { @@ -444,11 +433,9 @@ func (_BlockSizes__ReprPrototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } - type _BlockSizes__ReprBuilder struct { _BlockSizes__ReprAssembler } - func (nb *_BlockSizes__ReprBuilder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -460,10 +447,9 @@ func (nb *_BlockSizes__ReprBuilder) Reset() { var m schema.Maybe *nb = _BlockSizes__ReprBuilder{_BlockSizes__ReprAssembler{w: &w, m: &m}} } - type _BlockSizes__ReprAssembler struct { - w *_BlockSizes - m *schema.Maybe + w *_BlockSizes + m *schema.Maybe state laState cm schema.Maybe @@ -622,7 +608,6 @@ func (_Bytes__Prototype) FromBytes(v []byte) (Bytes, error) { n := _Bytes{v} return &n, nil } - type _Bytes__Maybe struct { m schema.Maybe v Bytes @@ -640,14 +625,14 @@ func (m MaybeBytes) Exists() bool { } func (m MaybeBytes) AsNode() ipld.Node { switch m.m { - case schema.Maybe_Absent: - return ipld.Absent - case schema.Maybe_Null: - return ipld.Null - case schema.Maybe_Value: - return m.v - default: - panic("unreachable") + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") } } func (m MaybeBytes) Must() Bytes { @@ -656,10 +641,8 @@ func (m MaybeBytes) Must() Bytes { } return m.v } - var _ ipld.Node = (Bytes)(&_Bytes{}) var _ schema.TypedNode = (Bytes)(&_Bytes{}) - func (Bytes) Kind() ipld.Kind { return ipld.Kind_Bytes } @@ -711,7 +694,6 @@ func (Bytes) AsLink() (ipld.Link, error) { func (Bytes) Prototype() ipld.NodePrototype { return _Bytes__Prototype{} } - type _Bytes__Prototype struct{} func (_Bytes__Prototype) NewBuilder() ipld.NodeBuilder { @@ -719,11 +701,9 @@ func (_Bytes__Prototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } - type _Bytes__Builder struct { _Bytes__Assembler } - func (nb *_Bytes__Builder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -735,7 +715,6 @@ func (nb *_Bytes__Builder) Reset() { var m schema.Maybe *nb = _Bytes__Builder{_Bytes__Assembler{w: &w, m: &m}} } - type _Bytes__Assembler struct { w *_Bytes m *schema.Maybe @@ -820,11 +799,8 @@ func (Bytes) Type() schema.Type { func (n Bytes) Representation() ipld.Node { return (*_Bytes__Repr)(n) } - type _Bytes__Repr = _Bytes - var _ ipld.Node = &_Bytes__Repr{} - type _Bytes__ReprPrototype = _Bytes__Prototype type _Bytes__ReprAssembler = _Bytes__Assembler @@ -835,7 +811,6 @@ func (_Int__Prototype) FromInt(v int64) (Int, error) { n := _Int{v} return &n, nil } - type _Int__Maybe struct { m schema.Maybe v Int @@ -853,14 +828,14 @@ func (m MaybeInt) Exists() bool { } func (m MaybeInt) AsNode() ipld.Node { switch m.m { - case schema.Maybe_Absent: - return ipld.Absent - case schema.Maybe_Null: - return ipld.Null - case schema.Maybe_Value: - return m.v - default: - panic("unreachable") + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") } } func (m MaybeInt) Must() Int { @@ -869,10 +844,8 @@ func (m MaybeInt) Must() Int { } return m.v } - var _ ipld.Node = (Int)(&_Int{}) var _ schema.TypedNode = (Int)(&_Int{}) - func (Int) Kind() ipld.Kind { return ipld.Kind_Int } @@ -924,7 +897,6 @@ func (Int) AsLink() (ipld.Link, error) { func (Int) Prototype() ipld.NodePrototype { return _Int__Prototype{} } - type _Int__Prototype struct{} func (_Int__Prototype) NewBuilder() ipld.NodeBuilder { @@ -932,11 +904,9 @@ func (_Int__Prototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } - type _Int__Builder struct { _Int__Assembler } - func (nb *_Int__Builder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -948,7 +918,6 @@ func (nb *_Int__Builder) Reset() { var m schema.Maybe *nb = _Int__Builder{_Int__Assembler{w: &w, m: &m}} } - type _Int__Assembler struct { w *_Int m *schema.Maybe @@ -1033,11 +1002,8 @@ func (Int) Type() schema.Type { func (n Int) Representation() ipld.Node { return (*_Int__Repr)(n) } - type _Int__Repr = _Int - var _ ipld.Node = &_Int__Repr{} - type _Int__ReprPrototype = _Int__Prototype type _Int__ReprAssembler = _Int__Assembler @@ -1052,7 +1018,6 @@ func (_String__Prototype) FromString(v string) (String, error) { n := _String{v} return &n, nil } - type _String__Maybe struct { m schema.Maybe v String @@ -1070,14 +1035,14 @@ func (m MaybeString) Exists() bool { } func (m MaybeString) AsNode() ipld.Node { switch m.m { - case schema.Maybe_Absent: - return ipld.Absent - case schema.Maybe_Null: - return ipld.Null - case schema.Maybe_Value: - return m.v - default: - panic("unreachable") + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") } } func (m MaybeString) Must() String { @@ -1086,10 +1051,8 @@ func (m MaybeString) Must() String { } return m.v } - var _ ipld.Node = (String)(&_String{}) var _ schema.TypedNode = (String)(&_String{}) - func (String) Kind() ipld.Kind { return ipld.Kind_String } @@ -1141,7 +1104,6 @@ func (String) AsLink() (ipld.Link, error) { func (String) Prototype() ipld.NodePrototype { return _String__Prototype{} } - type _String__Prototype struct{} func (_String__Prototype) NewBuilder() ipld.NodeBuilder { @@ -1149,11 +1111,9 @@ func (_String__Prototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } - type _String__Builder struct { _String__Assembler } - func (nb *_String__Builder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -1165,7 +1125,6 @@ func (nb *_String__Builder) Reset() { var m schema.Maybe *nb = _String__Builder{_String__Assembler{w: &w, m: &m}} } - type _String__Assembler struct { w *_String m *schema.Maybe @@ -1250,14 +1209,12 @@ func (String) Type() schema.Type { func (n String) Representation() ipld.Node { return (*_String__Repr)(n) } - type _String__Repr = _String - var _ ipld.Node = &_String__Repr{} - type _String__ReprPrototype = _String__Prototype type _String__ReprAssembler = _String__Assembler + func (n _UnixFSData) FieldDataType() Int { return &n.DataType } @@ -1282,7 +1239,6 @@ func (n _UnixFSData) FieldMode() MaybeInt { func (n _UnixFSData) FieldMtime() MaybeUnixTime { return &n.Mtime } - type _UnixFSData__Maybe struct { m schema.Maybe v UnixFSData @@ -1300,14 +1256,14 @@ func (m MaybeUnixFSData) Exists() bool { } func (m MaybeUnixFSData) AsNode() ipld.Node { switch m.m { - case schema.Maybe_Absent: - return ipld.Absent - case schema.Maybe_Null: - return ipld.Null - case schema.Maybe_Value: - return m.v - default: - panic("unreachable") + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") } } func (m MaybeUnixFSData) Must() UnixFSData { @@ -1316,20 +1272,18 @@ func (m MaybeUnixFSData) Must() UnixFSData { } return m.v } - var ( - fieldName__UnixFSData_DataType = _String{"DataType"} - fieldName__UnixFSData_Data = _String{"Data"} - fieldName__UnixFSData_FileSize = _String{"FileSize"} + fieldName__UnixFSData_DataType = _String{"DataType"} + fieldName__UnixFSData_Data = _String{"Data"} + fieldName__UnixFSData_FileSize = _String{"FileSize"} fieldName__UnixFSData_BlockSizes = _String{"BlockSizes"} - fieldName__UnixFSData_HashType = _String{"HashType"} - fieldName__UnixFSData_Fanout = _String{"Fanout"} - fieldName__UnixFSData_Mode = _String{"Mode"} - fieldName__UnixFSData_Mtime = _String{"Mtime"} + fieldName__UnixFSData_HashType = _String{"HashType"} + fieldName__UnixFSData_Fanout = _String{"Fanout"} + fieldName__UnixFSData_Mode = _String{"Mode"} + fieldName__UnixFSData_Mtime = _String{"Mtime"} ) var _ ipld.Node = (UnixFSData)(&_UnixFSData{}) var _ schema.TypedNode = (UnixFSData)(&_UnixFSData{}) - func (UnixFSData) Kind() ipld.Kind { return ipld.Kind_Map } @@ -1391,12 +1345,11 @@ func (n UnixFSData) MapIterator() ipld.MapIterator { } type _UnixFSData__MapItr struct { - n UnixFSData - idx int + n UnixFSData + idx int } -func (itr *_UnixFSData__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) { - if itr.idx >= 8 { +func (itr *_UnixFSData__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) {if itr.idx >= 8 { return nil, nil, ipld.ErrIteratorOverread{} } switch itr.idx { @@ -1491,7 +1444,6 @@ func (UnixFSData) AsLink() (ipld.Link, error) { func (UnixFSData) Prototype() ipld.NodePrototype { return _UnixFSData__Prototype{} } - type _UnixFSData__Prototype struct{} func (_UnixFSData__Prototype) NewBuilder() ipld.NodeBuilder { @@ -1499,11 +1451,9 @@ func (_UnixFSData__Prototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } - type _UnixFSData__Builder struct { _UnixFSData__Assembler } - func (nb *_UnixFSData__Builder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -1515,24 +1465,23 @@ func (nb *_UnixFSData__Builder) Reset() { var m schema.Maybe *nb = _UnixFSData__Builder{_UnixFSData__Assembler{w: &w, m: &m}} } - type _UnixFSData__Assembler struct { - w *_UnixFSData - m *schema.Maybe + w *_UnixFSData + m *schema.Maybe state maState - s int - f int + s int + f int - cm schema.Maybe - ca_DataType _Int__Assembler - ca_Data _Bytes__Assembler - ca_FileSize _Int__Assembler + cm schema.Maybe + ca_DataType _Int__Assembler + ca_Data _Bytes__Assembler + ca_FileSize _Int__Assembler ca_BlockSizes _BlockSizes__Assembler - ca_HashType _Int__Assembler - ca_Fanout _Int__Assembler - ca_Mode _Int__Assembler - ca_Mtime _UnixTime__Assembler -} + ca_HashType _Int__Assembler + ca_Fanout _Int__Assembler + ca_Mode _Int__Assembler + ca_Mtime _UnixTime__Assembler + } func (na *_UnixFSData__Assembler) reset() { na.state = maState_initial @@ -1548,17 +1497,16 @@ func (na *_UnixFSData__Assembler) reset() { } var ( - fieldBit__UnixFSData_DataType = 1 << 0 - fieldBit__UnixFSData_Data = 1 << 1 - fieldBit__UnixFSData_FileSize = 1 << 2 - fieldBit__UnixFSData_BlockSizes = 1 << 3 - fieldBit__UnixFSData_HashType = 1 << 4 - fieldBit__UnixFSData_Fanout = 1 << 5 - fieldBit__UnixFSData_Mode = 1 << 6 - fieldBit__UnixFSData_Mtime = 1 << 7 - fieldBits__UnixFSData_sufficient = 0 + 1<<0 + 1<<3 + fieldBit__UnixFSData_DataType = 1 << 0 + fieldBit__UnixFSData_Data = 1 << 1 + fieldBit__UnixFSData_FileSize = 1 << 2 + fieldBit__UnixFSData_BlockSizes = 1 << 3 + fieldBit__UnixFSData_HashType = 1 << 4 + fieldBit__UnixFSData_Fanout = 1 << 5 + fieldBit__UnixFSData_Mode = 1 << 6 + fieldBit__UnixFSData_Mtime = 1 << 7 + fieldBits__UnixFSData_sufficient = 0 + 1 << 0 + 1 << 3 ) - func (na *_UnixFSData__Assembler) BeginMap(int64) (ipld.MapAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: @@ -1745,7 +1693,7 @@ func (ma *_UnixFSData__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, e } switch k { case "DataType": - if ma.s&fieldBit__UnixFSData_DataType != 0 { + if ma.s & fieldBit__UnixFSData_DataType != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_DataType} } ma.s += fieldBit__UnixFSData_DataType @@ -1755,7 +1703,7 @@ func (ma *_UnixFSData__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, e ma.ca_DataType.m = &ma.cm return &ma.ca_DataType, nil case "Data": - if ma.s&fieldBit__UnixFSData_Data != 0 { + if ma.s & fieldBit__UnixFSData_Data != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Data} } ma.s += fieldBit__UnixFSData_Data @@ -1765,7 +1713,7 @@ func (ma *_UnixFSData__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, e ma.ca_Data.m = &ma.w.Data.m return &ma.ca_Data, nil case "FileSize": - if ma.s&fieldBit__UnixFSData_FileSize != 0 { + if ma.s & fieldBit__UnixFSData_FileSize != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_FileSize} } ma.s += fieldBit__UnixFSData_FileSize @@ -1775,7 +1723,7 @@ func (ma *_UnixFSData__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, e ma.ca_FileSize.m = &ma.w.FileSize.m return &ma.ca_FileSize, nil case "BlockSizes": - if ma.s&fieldBit__UnixFSData_BlockSizes != 0 { + if ma.s & fieldBit__UnixFSData_BlockSizes != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_BlockSizes} } ma.s += fieldBit__UnixFSData_BlockSizes @@ -1785,7 +1733,7 @@ func (ma *_UnixFSData__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, e ma.ca_BlockSizes.m = &ma.cm return &ma.ca_BlockSizes, nil case "HashType": - if ma.s&fieldBit__UnixFSData_HashType != 0 { + if ma.s & fieldBit__UnixFSData_HashType != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_HashType} } ma.s += fieldBit__UnixFSData_HashType @@ -1795,7 +1743,7 @@ func (ma *_UnixFSData__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, e ma.ca_HashType.m = &ma.w.HashType.m return &ma.ca_HashType, nil case "Fanout": - if ma.s&fieldBit__UnixFSData_Fanout != 0 { + if ma.s & fieldBit__UnixFSData_Fanout != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Fanout} } ma.s += fieldBit__UnixFSData_Fanout @@ -1805,7 +1753,7 @@ func (ma *_UnixFSData__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, e ma.ca_Fanout.m = &ma.w.Fanout.m return &ma.ca_Fanout, nil case "Mode": - if ma.s&fieldBit__UnixFSData_Mode != 0 { + if ma.s & fieldBit__UnixFSData_Mode != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mode} } ma.s += fieldBit__UnixFSData_Mode @@ -1815,7 +1763,7 @@ func (ma *_UnixFSData__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, e ma.ca_Mode.m = &ma.w.Mode.m return &ma.ca_Mode, nil case "Mtime": - if ma.s&fieldBit__UnixFSData_Mtime != 0 { + if ma.s & fieldBit__UnixFSData_Mtime != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mtime} } ma.s += fieldBit__UnixFSData_Mtime @@ -1825,7 +1773,7 @@ func (ma *_UnixFSData__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, e ma.ca_Mtime.m = &ma.w.Mtime.m return &ma.ca_Mtime, nil } - return nil, ipld.ErrInvalidKey{TypeName: "data.UnixFSData", Key: &_String{k}} + return nil, ipld.ErrInvalidKey{TypeName:"data.UnixFSData", Key:&_String{k}} } func (ma *_UnixFSData__Assembler) AssembleKey() ipld.NodeAssembler { switch ma.state { @@ -1911,12 +1859,12 @@ func (ma *_UnixFSData__Assembler) Finish() error { case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } - if ma.s&fieldBits__UnixFSData_sufficient != fieldBits__UnixFSData_sufficient { + if ma.s & fieldBits__UnixFSData_sufficient != fieldBits__UnixFSData_sufficient { err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} - if ma.s&fieldBit__UnixFSData_DataType == 0 { + if ma.s & fieldBit__UnixFSData_DataType == 0 { err.Missing = append(err.Missing, "DataType") } - if ma.s&fieldBit__UnixFSData_BlockSizes == 0 { + if ma.s & fieldBit__UnixFSData_BlockSizes == 0 { err.Missing = append(err.Missing, "BlockSizes") } return err @@ -1931,9 +1879,7 @@ func (ma *_UnixFSData__Assembler) KeyPrototype() ipld.NodePrototype { func (ma *_UnixFSData__Assembler) ValuePrototype(k string) ipld.NodePrototype { panic("todo structbuilder mapassembler valueprototype") } - type _UnixFSData__KeyAssembler _UnixFSData__Assembler - func (_UnixFSData__KeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { return mixins.StringAssembler{"data.UnixFSData.KeyAssembler"}.BeginMap(0) } @@ -1958,63 +1904,63 @@ func (ka *_UnixFSData__KeyAssembler) AssignString(k string) error { } switch k { case "DataType": - if ka.s&fieldBit__UnixFSData_DataType != 0 { + if ka.s & fieldBit__UnixFSData_DataType != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_DataType} } ka.s += fieldBit__UnixFSData_DataType ka.state = maState_expectValue ka.f = 0 case "Data": - if ka.s&fieldBit__UnixFSData_Data != 0 { + if ka.s & fieldBit__UnixFSData_Data != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Data} } ka.s += fieldBit__UnixFSData_Data ka.state = maState_expectValue ka.f = 1 case "FileSize": - if ka.s&fieldBit__UnixFSData_FileSize != 0 { + if ka.s & fieldBit__UnixFSData_FileSize != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_FileSize} } ka.s += fieldBit__UnixFSData_FileSize ka.state = maState_expectValue ka.f = 2 case "BlockSizes": - if ka.s&fieldBit__UnixFSData_BlockSizes != 0 { + if ka.s & fieldBit__UnixFSData_BlockSizes != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_BlockSizes} } ka.s += fieldBit__UnixFSData_BlockSizes ka.state = maState_expectValue ka.f = 3 case "HashType": - if ka.s&fieldBit__UnixFSData_HashType != 0 { + if ka.s & fieldBit__UnixFSData_HashType != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_HashType} } ka.s += fieldBit__UnixFSData_HashType ka.state = maState_expectValue ka.f = 4 case "Fanout": - if ka.s&fieldBit__UnixFSData_Fanout != 0 { + if ka.s & fieldBit__UnixFSData_Fanout != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Fanout} } ka.s += fieldBit__UnixFSData_Fanout ka.state = maState_expectValue ka.f = 5 case "Mode": - if ka.s&fieldBit__UnixFSData_Mode != 0 { + if ka.s & fieldBit__UnixFSData_Mode != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mode} } ka.s += fieldBit__UnixFSData_Mode ka.state = maState_expectValue ka.f = 6 case "Mtime": - if ka.s&fieldBit__UnixFSData_Mtime != 0 { + if ka.s & fieldBit__UnixFSData_Mtime != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mtime} } ka.s += fieldBit__UnixFSData_Mtime ka.state = maState_expectValue ka.f = 7 default: - return ipld.ErrInvalidKey{TypeName: "data.UnixFSData", Key: &_String{k}} + return ipld.ErrInvalidKey{TypeName:"data.UnixFSData", Key:&_String{k}} } return nil } @@ -2040,21 +1986,18 @@ func (UnixFSData) Type() schema.Type { func (n UnixFSData) Representation() ipld.Node { return (*_UnixFSData__Repr)(n) } - type _UnixFSData__Repr _UnixFSData - var ( - fieldName__UnixFSData_DataType_serial = _String{"DataType"} - fieldName__UnixFSData_Data_serial = _String{"Data"} - fieldName__UnixFSData_FileSize_serial = _String{"FileSize"} + fieldName__UnixFSData_DataType_serial = _String{"DataType"} + fieldName__UnixFSData_Data_serial = _String{"Data"} + fieldName__UnixFSData_FileSize_serial = _String{"FileSize"} fieldName__UnixFSData_BlockSizes_serial = _String{"BlockSizes"} - fieldName__UnixFSData_HashType_serial = _String{"HashType"} - fieldName__UnixFSData_Fanout_serial = _String{"Fanout"} - fieldName__UnixFSData_Mode_serial = _String{"Mode"} - fieldName__UnixFSData_Mtime_serial = _String{"Mtime"} + fieldName__UnixFSData_HashType_serial = _String{"HashType"} + fieldName__UnixFSData_Fanout_serial = _String{"Fanout"} + fieldName__UnixFSData_Mode_serial = _String{"Mode"} + fieldName__UnixFSData_Mtime_serial = _String{"Mtime"} ) var _ ipld.Node = &_UnixFSData__Repr{} - func (_UnixFSData__Repr) Kind() ipld.Kind { return ipld.Kind_Map } @@ -2143,9 +2086,7 @@ type _UnixFSData__ReprMapItr struct { end int } -func (itr *_UnixFSData__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) { -advance: - if itr.idx >= 8 { +func (itr *_UnixFSData__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) {advance:if itr.idx >= 8 { return nil, nil, ipld.ErrIteratorOverread{} } switch itr.idx { @@ -2258,7 +2199,6 @@ func (_UnixFSData__Repr) AsLink() (ipld.Link, error) { func (_UnixFSData__Repr) Prototype() ipld.NodePrototype { return _UnixFSData__ReprPrototype{} } - type _UnixFSData__ReprPrototype struct{} func (_UnixFSData__ReprPrototype) NewBuilder() ipld.NodeBuilder { @@ -2266,11 +2206,9 @@ func (_UnixFSData__ReprPrototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } - type _UnixFSData__ReprBuilder struct { _UnixFSData__ReprAssembler } - func (nb *_UnixFSData__ReprBuilder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -2282,24 +2220,23 @@ func (nb *_UnixFSData__ReprBuilder) Reset() { var m schema.Maybe *nb = _UnixFSData__ReprBuilder{_UnixFSData__ReprAssembler{w: &w, m: &m}} } - type _UnixFSData__ReprAssembler struct { - w *_UnixFSData - m *schema.Maybe + w *_UnixFSData + m *schema.Maybe state maState - s int - f int + s int + f int - cm schema.Maybe - ca_DataType _Int__ReprAssembler - ca_Data _Bytes__ReprAssembler - ca_FileSize _Int__ReprAssembler + cm schema.Maybe + ca_DataType _Int__ReprAssembler + ca_Data _Bytes__ReprAssembler + ca_FileSize _Int__ReprAssembler ca_BlockSizes _BlockSizes__ReprAssembler - ca_HashType _Int__ReprAssembler - ca_Fanout _Int__ReprAssembler - ca_Mode _Int__ReprAssembler - ca_Mtime _UnixTime__ReprAssembler -} + ca_HashType _Int__ReprAssembler + ca_Fanout _Int__ReprAssembler + ca_Mode _Int__ReprAssembler + ca_Mtime _UnixTime__ReprAssembler + } func (na *_UnixFSData__ReprAssembler) reset() { na.state = maState_initial @@ -2406,8 +2343,7 @@ func (ma *_UnixFSData__ReprAssembler) valueFinishTidy() bool { switch ma.f { case 0: switch ma.cm { - case schema.Maybe_Value: - ma.cm = schema.Maybe_Absent + case schema.Maybe_Value:ma.cm = schema.Maybe_Absent ma.state = maState_initial return true default: @@ -2433,8 +2369,7 @@ func (ma *_UnixFSData__ReprAssembler) valueFinishTidy() bool { } case 3: switch ma.cm { - case schema.Maybe_Value: - ma.cm = schema.Maybe_Absent + case schema.Maybe_Value:ma.cm = schema.Maybe_Absent ma.state = maState_initial return true default: @@ -2497,7 +2432,7 @@ func (ma *_UnixFSData__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssemble } switch k { case "DataType": - if ma.s&fieldBit__UnixFSData_DataType != 0 { + if ma.s & fieldBit__UnixFSData_DataType != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_DataType_serial} } ma.s += fieldBit__UnixFSData_DataType @@ -2507,7 +2442,7 @@ func (ma *_UnixFSData__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssemble ma.ca_DataType.m = &ma.cm return &ma.ca_DataType, nil case "Data": - if ma.s&fieldBit__UnixFSData_Data != 0 { + if ma.s & fieldBit__UnixFSData_Data != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Data_serial} } ma.s += fieldBit__UnixFSData_Data @@ -2515,10 +2450,10 @@ func (ma *_UnixFSData__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssemble ma.f = 1 ma.ca_Data.w = ma.w.Data.v ma.ca_Data.m = &ma.w.Data.m - + return &ma.ca_Data, nil case "FileSize": - if ma.s&fieldBit__UnixFSData_FileSize != 0 { + if ma.s & fieldBit__UnixFSData_FileSize != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_FileSize_serial} } ma.s += fieldBit__UnixFSData_FileSize @@ -2526,10 +2461,10 @@ func (ma *_UnixFSData__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssemble ma.f = 2 ma.ca_FileSize.w = ma.w.FileSize.v ma.ca_FileSize.m = &ma.w.FileSize.m - + return &ma.ca_FileSize, nil case "BlockSizes": - if ma.s&fieldBit__UnixFSData_BlockSizes != 0 { + if ma.s & fieldBit__UnixFSData_BlockSizes != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_BlockSizes_serial} } ma.s += fieldBit__UnixFSData_BlockSizes @@ -2539,7 +2474,7 @@ func (ma *_UnixFSData__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssemble ma.ca_BlockSizes.m = &ma.cm return &ma.ca_BlockSizes, nil case "HashType": - if ma.s&fieldBit__UnixFSData_HashType != 0 { + if ma.s & fieldBit__UnixFSData_HashType != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_HashType_serial} } ma.s += fieldBit__UnixFSData_HashType @@ -2547,10 +2482,10 @@ func (ma *_UnixFSData__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssemble ma.f = 4 ma.ca_HashType.w = ma.w.HashType.v ma.ca_HashType.m = &ma.w.HashType.m - + return &ma.ca_HashType, nil case "Fanout": - if ma.s&fieldBit__UnixFSData_Fanout != 0 { + if ma.s & fieldBit__UnixFSData_Fanout != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Fanout_serial} } ma.s += fieldBit__UnixFSData_Fanout @@ -2558,10 +2493,10 @@ func (ma *_UnixFSData__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssemble ma.f = 5 ma.ca_Fanout.w = ma.w.Fanout.v ma.ca_Fanout.m = &ma.w.Fanout.m - + return &ma.ca_Fanout, nil case "Mode": - if ma.s&fieldBit__UnixFSData_Mode != 0 { + if ma.s & fieldBit__UnixFSData_Mode != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mode_serial} } ma.s += fieldBit__UnixFSData_Mode @@ -2569,10 +2504,10 @@ func (ma *_UnixFSData__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssemble ma.f = 6 ma.ca_Mode.w = ma.w.Mode.v ma.ca_Mode.m = &ma.w.Mode.m - + return &ma.ca_Mode, nil case "Mtime": - if ma.s&fieldBit__UnixFSData_Mtime != 0 { + if ma.s & fieldBit__UnixFSData_Mtime != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mtime_serial} } ma.s += fieldBit__UnixFSData_Mtime @@ -2580,11 +2515,11 @@ func (ma *_UnixFSData__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssemble ma.f = 7 ma.ca_Mtime.w = ma.w.Mtime.v ma.ca_Mtime.m = &ma.w.Mtime.m - + return &ma.ca_Mtime, nil default: } - return nil, ipld.ErrInvalidKey{TypeName: "data.UnixFSData.Repr", Key: &_String{k}} + return nil, ipld.ErrInvalidKey{TypeName:"data.UnixFSData.Repr", Key:&_String{k}} } func (ma *_UnixFSData__ReprAssembler) AssembleKey() ipld.NodeAssembler { switch ma.state { @@ -2626,12 +2561,12 @@ func (ma *_UnixFSData__ReprAssembler) AssembleValue() ipld.NodeAssembler { case 1: ma.ca_Data.w = ma.w.Data.v ma.ca_Data.m = &ma.w.Data.m - + return &ma.ca_Data case 2: ma.ca_FileSize.w = ma.w.FileSize.v ma.ca_FileSize.m = &ma.w.FileSize.m - + return &ma.ca_FileSize case 3: ma.ca_BlockSizes.w = &ma.w.BlockSizes @@ -2640,22 +2575,22 @@ func (ma *_UnixFSData__ReprAssembler) AssembleValue() ipld.NodeAssembler { case 4: ma.ca_HashType.w = ma.w.HashType.v ma.ca_HashType.m = &ma.w.HashType.m - + return &ma.ca_HashType case 5: ma.ca_Fanout.w = ma.w.Fanout.v ma.ca_Fanout.m = &ma.w.Fanout.m - + return &ma.ca_Fanout case 6: ma.ca_Mode.w = ma.w.Mode.v ma.ca_Mode.m = &ma.w.Mode.m - + return &ma.ca_Mode case 7: ma.ca_Mtime.w = ma.w.Mtime.v ma.ca_Mtime.m = &ma.w.Mtime.m - + return &ma.ca_Mtime default: panic("unreachable") @@ -2676,12 +2611,12 @@ func (ma *_UnixFSData__ReprAssembler) Finish() error { case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } - if ma.s&fieldBits__UnixFSData_sufficient != fieldBits__UnixFSData_sufficient { + if ma.s & fieldBits__UnixFSData_sufficient != fieldBits__UnixFSData_sufficient { err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} - if ma.s&fieldBit__UnixFSData_DataType == 0 { + if ma.s & fieldBit__UnixFSData_DataType == 0 { err.Missing = append(err.Missing, "DataType") } - if ma.s&fieldBit__UnixFSData_BlockSizes == 0 { + if ma.s & fieldBit__UnixFSData_BlockSizes == 0 { err.Missing = append(err.Missing, "BlockSizes") } return err @@ -2696,9 +2631,7 @@ func (ma *_UnixFSData__ReprAssembler) KeyPrototype() ipld.NodePrototype { func (ma *_UnixFSData__ReprAssembler) ValuePrototype(k string) ipld.NodePrototype { panic("todo structbuilder mapassembler repr valueprototype") } - type _UnixFSData__ReprKeyAssembler _UnixFSData__ReprAssembler - func (_UnixFSData__ReprKeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.BeginMap(0) } @@ -2723,7 +2656,7 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { } switch k { case "DataType": - if ka.s&fieldBit__UnixFSData_DataType != 0 { + if ka.s & fieldBit__UnixFSData_DataType != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_DataType_serial} } ka.s += fieldBit__UnixFSData_DataType @@ -2731,7 +2664,7 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { ka.f = 0 return nil case "Data": - if ka.s&fieldBit__UnixFSData_Data != 0 { + if ka.s & fieldBit__UnixFSData_Data != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Data_serial} } ka.s += fieldBit__UnixFSData_Data @@ -2739,7 +2672,7 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { ka.f = 1 return nil case "FileSize": - if ka.s&fieldBit__UnixFSData_FileSize != 0 { + if ka.s & fieldBit__UnixFSData_FileSize != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_FileSize_serial} } ka.s += fieldBit__UnixFSData_FileSize @@ -2747,7 +2680,7 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { ka.f = 2 return nil case "BlockSizes": - if ka.s&fieldBit__UnixFSData_BlockSizes != 0 { + if ka.s & fieldBit__UnixFSData_BlockSizes != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_BlockSizes_serial} } ka.s += fieldBit__UnixFSData_BlockSizes @@ -2755,7 +2688,7 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { ka.f = 3 return nil case "HashType": - if ka.s&fieldBit__UnixFSData_HashType != 0 { + if ka.s & fieldBit__UnixFSData_HashType != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_HashType_serial} } ka.s += fieldBit__UnixFSData_HashType @@ -2763,7 +2696,7 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { ka.f = 4 return nil case "Fanout": - if ka.s&fieldBit__UnixFSData_Fanout != 0 { + if ka.s & fieldBit__UnixFSData_Fanout != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Fanout_serial} } ka.s += fieldBit__UnixFSData_Fanout @@ -2771,7 +2704,7 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { ka.f = 5 return nil case "Mode": - if ka.s&fieldBit__UnixFSData_Mode != 0 { + if ka.s & fieldBit__UnixFSData_Mode != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mode_serial} } ka.s += fieldBit__UnixFSData_Mode @@ -2779,7 +2712,7 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { ka.f = 6 return nil case "Mtime": - if ka.s&fieldBit__UnixFSData_Mtime != 0 { + if ka.s & fieldBit__UnixFSData_Mtime != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mtime_serial} } ka.s += fieldBit__UnixFSData_Mtime @@ -2787,7 +2720,7 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { ka.f = 7 return nil } - return ipld.ErrInvalidKey{TypeName: "data.UnixFSData.Repr", Key: &_String{k}} + return ipld.ErrInvalidKey{TypeName:"data.UnixFSData.Repr", Key:&_String{k}} } func (_UnixFSData__ReprKeyAssembler) AssignBytes([]byte) error { return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.AssignBytes(nil) @@ -2806,10 +2739,10 @@ func (_UnixFSData__ReprKeyAssembler) Prototype() ipld.NodePrototype { return _String__Prototype{} } + func (n _UnixFSMetadata) FieldMimeType() MaybeString { return &n.MimeType } - type _UnixFSMetadata__Maybe struct { m schema.Maybe v UnixFSMetadata @@ -2827,14 +2760,14 @@ func (m MaybeUnixFSMetadata) Exists() bool { } func (m MaybeUnixFSMetadata) AsNode() ipld.Node { switch m.m { - case schema.Maybe_Absent: - return ipld.Absent - case schema.Maybe_Null: - return ipld.Null - case schema.Maybe_Value: - return m.v - default: - panic("unreachable") + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") } } func (m MaybeUnixFSMetadata) Must() UnixFSMetadata { @@ -2843,13 +2776,11 @@ func (m MaybeUnixFSMetadata) Must() UnixFSMetadata { } return m.v } - var ( fieldName__UnixFSMetadata_MimeType = _String{"MimeType"} ) var _ ipld.Node = (UnixFSMetadata)(&_UnixFSMetadata{}) var _ schema.TypedNode = (UnixFSMetadata)(&_UnixFSMetadata{}) - func (UnixFSMetadata) Kind() ipld.Kind { return ipld.Kind_Map } @@ -2882,12 +2813,11 @@ func (n UnixFSMetadata) MapIterator() ipld.MapIterator { } type _UnixFSMetadata__MapItr struct { - n UnixFSMetadata - idx int + n UnixFSMetadata + idx int } -func (itr *_UnixFSMetadata__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) { - if itr.idx >= 1 { +func (itr *_UnixFSMetadata__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) {if itr.idx >= 1 { return nil, nil, ipld.ErrIteratorOverread{} } switch itr.idx { @@ -2941,7 +2871,6 @@ func (UnixFSMetadata) AsLink() (ipld.Link, error) { func (UnixFSMetadata) Prototype() ipld.NodePrototype { return _UnixFSMetadata__Prototype{} } - type _UnixFSMetadata__Prototype struct{} func (_UnixFSMetadata__Prototype) NewBuilder() ipld.NodeBuilder { @@ -2949,11 +2878,9 @@ func (_UnixFSMetadata__Prototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } - type _UnixFSMetadata__Builder struct { _UnixFSMetadata__Assembler } - func (nb *_UnixFSMetadata__Builder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -2965,17 +2892,16 @@ func (nb *_UnixFSMetadata__Builder) Reset() { var m schema.Maybe *nb = _UnixFSMetadata__Builder{_UnixFSMetadata__Assembler{w: &w, m: &m}} } - type _UnixFSMetadata__Assembler struct { - w *_UnixFSMetadata - m *schema.Maybe + w *_UnixFSMetadata + m *schema.Maybe state maState - s int - f int + s int + f int - cm schema.Maybe + cm schema.Maybe ca_MimeType _String__Assembler -} + } func (na *_UnixFSMetadata__Assembler) reset() { na.state = maState_initial @@ -2984,10 +2910,9 @@ func (na *_UnixFSMetadata__Assembler) reset() { } var ( - fieldBit__UnixFSMetadata_MimeType = 1 << 0 + fieldBit__UnixFSMetadata_MimeType = 1 << 0 fieldBits__UnixFSMetadata_sufficient = 0 ) - func (na *_UnixFSMetadata__Assembler) BeginMap(int64) (ipld.MapAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: @@ -3109,7 +3034,7 @@ func (ma *_UnixFSMetadata__Assembler) AssembleEntry(k string) (ipld.NodeAssemble } switch k { case "MimeType": - if ma.s&fieldBit__UnixFSMetadata_MimeType != 0 { + if ma.s & fieldBit__UnixFSMetadata_MimeType != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSMetadata_MimeType} } ma.s += fieldBit__UnixFSMetadata_MimeType @@ -3119,7 +3044,7 @@ func (ma *_UnixFSMetadata__Assembler) AssembleEntry(k string) (ipld.NodeAssemble ma.ca_MimeType.m = &ma.w.MimeType.m return &ma.ca_MimeType, nil } - return nil, ipld.ErrInvalidKey{TypeName: "data.UnixFSMetadata", Key: &_String{k}} + return nil, ipld.ErrInvalidKey{TypeName:"data.UnixFSMetadata", Key:&_String{k}} } func (ma *_UnixFSMetadata__Assembler) AssembleKey() ipld.NodeAssembler { switch ma.state { @@ -3177,7 +3102,7 @@ func (ma *_UnixFSMetadata__Assembler) Finish() error { case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } - if ma.s&fieldBits__UnixFSMetadata_sufficient != fieldBits__UnixFSMetadata_sufficient { + if ma.s & fieldBits__UnixFSMetadata_sufficient != fieldBits__UnixFSMetadata_sufficient { err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} return err } @@ -3191,9 +3116,7 @@ func (ma *_UnixFSMetadata__Assembler) KeyPrototype() ipld.NodePrototype { func (ma *_UnixFSMetadata__Assembler) ValuePrototype(k string) ipld.NodePrototype { panic("todo structbuilder mapassembler valueprototype") } - type _UnixFSMetadata__KeyAssembler _UnixFSMetadata__Assembler - func (_UnixFSMetadata__KeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { return mixins.StringAssembler{"data.UnixFSMetadata.KeyAssembler"}.BeginMap(0) } @@ -3218,14 +3141,14 @@ func (ka *_UnixFSMetadata__KeyAssembler) AssignString(k string) error { } switch k { case "MimeType": - if ka.s&fieldBit__UnixFSMetadata_MimeType != 0 { + if ka.s & fieldBit__UnixFSMetadata_MimeType != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSMetadata_MimeType} } ka.s += fieldBit__UnixFSMetadata_MimeType ka.state = maState_expectValue ka.f = 0 default: - return ipld.ErrInvalidKey{TypeName: "data.UnixFSMetadata", Key: &_String{k}} + return ipld.ErrInvalidKey{TypeName:"data.UnixFSMetadata", Key:&_String{k}} } return nil } @@ -3251,14 +3174,11 @@ func (UnixFSMetadata) Type() schema.Type { func (n UnixFSMetadata) Representation() ipld.Node { return (*_UnixFSMetadata__Repr)(n) } - type _UnixFSMetadata__Repr _UnixFSMetadata - var ( fieldName__UnixFSMetadata_MimeType_serial = _String{"MimeType"} ) var _ ipld.Node = &_UnixFSMetadata__Repr{} - func (_UnixFSMetadata__Repr) Kind() ipld.Kind { return ipld.Kind_Map } @@ -3303,9 +3223,7 @@ type _UnixFSMetadata__ReprMapItr struct { end int } -func (itr *_UnixFSMetadata__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) { -advance: - if itr.idx >= 1 { +func (itr *_UnixFSMetadata__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) {advance:if itr.idx >= 1 { return nil, nil, ipld.ErrIteratorOverread{} } switch itr.idx { @@ -3362,7 +3280,6 @@ func (_UnixFSMetadata__Repr) AsLink() (ipld.Link, error) { func (_UnixFSMetadata__Repr) Prototype() ipld.NodePrototype { return _UnixFSMetadata__ReprPrototype{} } - type _UnixFSMetadata__ReprPrototype struct{} func (_UnixFSMetadata__ReprPrototype) NewBuilder() ipld.NodeBuilder { @@ -3370,11 +3287,9 @@ func (_UnixFSMetadata__ReprPrototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } - type _UnixFSMetadata__ReprBuilder struct { _UnixFSMetadata__ReprAssembler } - func (nb *_UnixFSMetadata__ReprBuilder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -3386,17 +3301,16 @@ func (nb *_UnixFSMetadata__ReprBuilder) Reset() { var m schema.Maybe *nb = _UnixFSMetadata__ReprBuilder{_UnixFSMetadata__ReprAssembler{w: &w, m: &m}} } - type _UnixFSMetadata__ReprAssembler struct { - w *_UnixFSMetadata - m *schema.Maybe + w *_UnixFSMetadata + m *schema.Maybe state maState - s int - f int + s int + f int - cm schema.Maybe + cm schema.Maybe ca_MimeType _String__ReprAssembler -} + } func (na *_UnixFSMetadata__ReprAssembler) reset() { na.state = maState_initial @@ -3524,7 +3438,7 @@ func (ma *_UnixFSMetadata__ReprAssembler) AssembleEntry(k string) (ipld.NodeAsse } switch k { case "MimeType": - if ma.s&fieldBit__UnixFSMetadata_MimeType != 0 { + if ma.s & fieldBit__UnixFSMetadata_MimeType != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSMetadata_MimeType_serial} } ma.s += fieldBit__UnixFSMetadata_MimeType @@ -3532,11 +3446,11 @@ func (ma *_UnixFSMetadata__ReprAssembler) AssembleEntry(k string) (ipld.NodeAsse ma.f = 0 ma.ca_MimeType.w = ma.w.MimeType.v ma.ca_MimeType.m = &ma.w.MimeType.m - + return &ma.ca_MimeType, nil default: } - return nil, ipld.ErrInvalidKey{TypeName: "data.UnixFSMetadata.Repr", Key: &_String{k}} + return nil, ipld.ErrInvalidKey{TypeName:"data.UnixFSMetadata.Repr", Key:&_String{k}} } func (ma *_UnixFSMetadata__ReprAssembler) AssembleKey() ipld.NodeAssembler { switch ma.state { @@ -3574,7 +3488,7 @@ func (ma *_UnixFSMetadata__ReprAssembler) AssembleValue() ipld.NodeAssembler { case 0: ma.ca_MimeType.w = ma.w.MimeType.v ma.ca_MimeType.m = &ma.w.MimeType.m - + return &ma.ca_MimeType default: panic("unreachable") @@ -3595,7 +3509,7 @@ func (ma *_UnixFSMetadata__ReprAssembler) Finish() error { case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } - if ma.s&fieldBits__UnixFSMetadata_sufficient != fieldBits__UnixFSMetadata_sufficient { + if ma.s & fieldBits__UnixFSMetadata_sufficient != fieldBits__UnixFSMetadata_sufficient { err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} return err } @@ -3609,9 +3523,7 @@ func (ma *_UnixFSMetadata__ReprAssembler) KeyPrototype() ipld.NodePrototype { func (ma *_UnixFSMetadata__ReprAssembler) ValuePrototype(k string) ipld.NodePrototype { panic("todo structbuilder mapassembler repr valueprototype") } - type _UnixFSMetadata__ReprKeyAssembler _UnixFSMetadata__ReprAssembler - func (_UnixFSMetadata__ReprKeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.BeginMap(0) } @@ -3636,7 +3548,7 @@ func (ka *_UnixFSMetadata__ReprKeyAssembler) AssignString(k string) error { } switch k { case "MimeType": - if ka.s&fieldBit__UnixFSMetadata_MimeType != 0 { + if ka.s & fieldBit__UnixFSMetadata_MimeType != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSMetadata_MimeType_serial} } ka.s += fieldBit__UnixFSMetadata_MimeType @@ -3644,7 +3556,7 @@ func (ka *_UnixFSMetadata__ReprKeyAssembler) AssignString(k string) error { ka.f = 0 return nil } - return ipld.ErrInvalidKey{TypeName: "data.UnixFSMetadata.Repr", Key: &_String{k}} + return ipld.ErrInvalidKey{TypeName:"data.UnixFSMetadata.Repr", Key:&_String{k}} } func (_UnixFSMetadata__ReprKeyAssembler) AssignBytes([]byte) error { return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.AssignBytes(nil) @@ -3663,13 +3575,13 @@ func (_UnixFSMetadata__ReprKeyAssembler) Prototype() ipld.NodePrototype { return _String__Prototype{} } + func (n _UnixTime) FieldSeconds() Int { return &n.Seconds } func (n _UnixTime) FieldFractionalNanoseconds() MaybeInt { return &n.FractionalNanoseconds } - type _UnixTime__Maybe struct { m schema.Maybe v UnixTime @@ -3687,14 +3599,14 @@ func (m MaybeUnixTime) Exists() bool { } func (m MaybeUnixTime) AsNode() ipld.Node { switch m.m { - case schema.Maybe_Absent: - return ipld.Absent - case schema.Maybe_Null: - return ipld.Null - case schema.Maybe_Value: - return m.v - default: - panic("unreachable") + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") } } func (m MaybeUnixTime) Must() UnixTime { @@ -3703,14 +3615,12 @@ func (m MaybeUnixTime) Must() UnixTime { } return m.v } - var ( - fieldName__UnixTime_Seconds = _String{"Seconds"} + fieldName__UnixTime_Seconds = _String{"Seconds"} fieldName__UnixTime_FractionalNanoseconds = _String{"FractionalNanoseconds"} ) var _ ipld.Node = (UnixTime)(&_UnixTime{}) var _ schema.TypedNode = (UnixTime)(&_UnixTime{}) - func (UnixTime) Kind() ipld.Kind { return ipld.Kind_Map } @@ -3745,12 +3655,11 @@ func (n UnixTime) MapIterator() ipld.MapIterator { } type _UnixTime__MapItr struct { - n UnixTime - idx int + n UnixTime + idx int } -func (itr *_UnixTime__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) { - if itr.idx >= 2 { +func (itr *_UnixTime__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) {if itr.idx >= 2 { return nil, nil, ipld.ErrIteratorOverread{} } switch itr.idx { @@ -3807,7 +3716,6 @@ func (UnixTime) AsLink() (ipld.Link, error) { func (UnixTime) Prototype() ipld.NodePrototype { return _UnixTime__Prototype{} } - type _UnixTime__Prototype struct{} func (_UnixTime__Prototype) NewBuilder() ipld.NodeBuilder { @@ -3815,11 +3723,9 @@ func (_UnixTime__Prototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } - type _UnixTime__Builder struct { _UnixTime__Assembler } - func (nb *_UnixTime__Builder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -3831,18 +3737,17 @@ func (nb *_UnixTime__Builder) Reset() { var m schema.Maybe *nb = _UnixTime__Builder{_UnixTime__Assembler{w: &w, m: &m}} } - type _UnixTime__Assembler struct { - w *_UnixTime - m *schema.Maybe + w *_UnixTime + m *schema.Maybe state maState - s int - f int + s int + f int - cm schema.Maybe - ca_Seconds _Int__Assembler + cm schema.Maybe + ca_Seconds _Int__Assembler ca_FractionalNanoseconds _Int__Assembler -} + } func (na *_UnixTime__Assembler) reset() { na.state = maState_initial @@ -3852,11 +3757,10 @@ func (na *_UnixTime__Assembler) reset() { } var ( - fieldBit__UnixTime_Seconds = 1 << 0 + fieldBit__UnixTime_Seconds = 1 << 0 fieldBit__UnixTime_FractionalNanoseconds = 1 << 1 - fieldBits__UnixTime_sufficient = 0 + 1<<0 + fieldBits__UnixTime_sufficient = 0 + 1 << 0 ) - func (na *_UnixTime__Assembler) BeginMap(int64) (ipld.MapAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: @@ -3988,7 +3892,7 @@ func (ma *_UnixTime__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, err } switch k { case "Seconds": - if ma.s&fieldBit__UnixTime_Seconds != 0 { + if ma.s & fieldBit__UnixTime_Seconds != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_Seconds} } ma.s += fieldBit__UnixTime_Seconds @@ -3998,7 +3902,7 @@ func (ma *_UnixTime__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, err ma.ca_Seconds.m = &ma.cm return &ma.ca_Seconds, nil case "FractionalNanoseconds": - if ma.s&fieldBit__UnixTime_FractionalNanoseconds != 0 { + if ma.s & fieldBit__UnixTime_FractionalNanoseconds != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_FractionalNanoseconds} } ma.s += fieldBit__UnixTime_FractionalNanoseconds @@ -4008,7 +3912,7 @@ func (ma *_UnixTime__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, err ma.ca_FractionalNanoseconds.m = &ma.w.FractionalNanoseconds.m return &ma.ca_FractionalNanoseconds, nil } - return nil, ipld.ErrInvalidKey{TypeName: "data.UnixTime", Key: &_String{k}} + return nil, ipld.ErrInvalidKey{TypeName:"data.UnixTime", Key:&_String{k}} } func (ma *_UnixTime__Assembler) AssembleKey() ipld.NodeAssembler { switch ma.state { @@ -4070,9 +3974,9 @@ func (ma *_UnixTime__Assembler) Finish() error { case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } - if ma.s&fieldBits__UnixTime_sufficient != fieldBits__UnixTime_sufficient { + if ma.s & fieldBits__UnixTime_sufficient != fieldBits__UnixTime_sufficient { err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} - if ma.s&fieldBit__UnixTime_Seconds == 0 { + if ma.s & fieldBit__UnixTime_Seconds == 0 { err.Missing = append(err.Missing, "Seconds") } return err @@ -4087,9 +3991,7 @@ func (ma *_UnixTime__Assembler) KeyPrototype() ipld.NodePrototype { func (ma *_UnixTime__Assembler) ValuePrototype(k string) ipld.NodePrototype { panic("todo structbuilder mapassembler valueprototype") } - type _UnixTime__KeyAssembler _UnixTime__Assembler - func (_UnixTime__KeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { return mixins.StringAssembler{"data.UnixTime.KeyAssembler"}.BeginMap(0) } @@ -4114,21 +4016,21 @@ func (ka *_UnixTime__KeyAssembler) AssignString(k string) error { } switch k { case "Seconds": - if ka.s&fieldBit__UnixTime_Seconds != 0 { + if ka.s & fieldBit__UnixTime_Seconds != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_Seconds} } ka.s += fieldBit__UnixTime_Seconds ka.state = maState_expectValue ka.f = 0 case "FractionalNanoseconds": - if ka.s&fieldBit__UnixTime_FractionalNanoseconds != 0 { + if ka.s & fieldBit__UnixTime_FractionalNanoseconds != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_FractionalNanoseconds} } ka.s += fieldBit__UnixTime_FractionalNanoseconds ka.state = maState_expectValue ka.f = 1 default: - return ipld.ErrInvalidKey{TypeName: "data.UnixTime", Key: &_String{k}} + return ipld.ErrInvalidKey{TypeName:"data.UnixTime", Key:&_String{k}} } return nil } @@ -4154,15 +4056,12 @@ func (UnixTime) Type() schema.Type { func (n UnixTime) Representation() ipld.Node { return (*_UnixTime__Repr)(n) } - type _UnixTime__Repr _UnixTime - var ( - fieldName__UnixTime_Seconds_serial = _String{"Seconds"} + fieldName__UnixTime_Seconds_serial = _String{"Seconds"} fieldName__UnixTime_FractionalNanoseconds_serial = _String{"FractionalNanoseconds"} ) var _ ipld.Node = &_UnixTime__Repr{} - func (_UnixTime__Repr) Kind() ipld.Kind { return ipld.Kind_Map } @@ -4209,9 +4108,7 @@ type _UnixTime__ReprMapItr struct { end int } -func (itr *_UnixTime__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) { -advance: - if itr.idx >= 2 { +func (itr *_UnixTime__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) {advance:if itr.idx >= 2 { return nil, nil, ipld.ErrIteratorOverread{} } switch itr.idx { @@ -4271,7 +4168,6 @@ func (_UnixTime__Repr) AsLink() (ipld.Link, error) { func (_UnixTime__Repr) Prototype() ipld.NodePrototype { return _UnixTime__ReprPrototype{} } - type _UnixTime__ReprPrototype struct{} func (_UnixTime__ReprPrototype) NewBuilder() ipld.NodeBuilder { @@ -4279,11 +4175,9 @@ func (_UnixTime__ReprPrototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } - type _UnixTime__ReprBuilder struct { _UnixTime__ReprAssembler } - func (nb *_UnixTime__ReprBuilder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -4295,18 +4189,17 @@ func (nb *_UnixTime__ReprBuilder) Reset() { var m schema.Maybe *nb = _UnixTime__ReprBuilder{_UnixTime__ReprAssembler{w: &w, m: &m}} } - type _UnixTime__ReprAssembler struct { - w *_UnixTime - m *schema.Maybe + w *_UnixTime + m *schema.Maybe state maState - s int - f int + s int + f int - cm schema.Maybe - ca_Seconds _Int__ReprAssembler + cm schema.Maybe + ca_Seconds _Int__ReprAssembler ca_FractionalNanoseconds _Int__ReprAssembler -} + } func (na *_UnixTime__ReprAssembler) reset() { na.state = maState_initial @@ -4407,8 +4300,7 @@ func (ma *_UnixTime__ReprAssembler) valueFinishTidy() bool { switch ma.f { case 0: switch ma.cm { - case schema.Maybe_Value: - ma.cm = schema.Maybe_Absent + case schema.Maybe_Value:ma.cm = schema.Maybe_Absent ma.state = maState_initial return true default: @@ -4444,7 +4336,7 @@ func (ma *_UnixTime__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssembler, } switch k { case "Seconds": - if ma.s&fieldBit__UnixTime_Seconds != 0 { + if ma.s & fieldBit__UnixTime_Seconds != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_Seconds_serial} } ma.s += fieldBit__UnixTime_Seconds @@ -4454,7 +4346,7 @@ func (ma *_UnixTime__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssembler, ma.ca_Seconds.m = &ma.cm return &ma.ca_Seconds, nil case "FractionalNanoseconds": - if ma.s&fieldBit__UnixTime_FractionalNanoseconds != 0 { + if ma.s & fieldBit__UnixTime_FractionalNanoseconds != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_FractionalNanoseconds_serial} } ma.s += fieldBit__UnixTime_FractionalNanoseconds @@ -4462,11 +4354,11 @@ func (ma *_UnixTime__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssembler, ma.f = 1 ma.ca_FractionalNanoseconds.w = ma.w.FractionalNanoseconds.v ma.ca_FractionalNanoseconds.m = &ma.w.FractionalNanoseconds.m - + return &ma.ca_FractionalNanoseconds, nil default: } - return nil, ipld.ErrInvalidKey{TypeName: "data.UnixTime.Repr", Key: &_String{k}} + return nil, ipld.ErrInvalidKey{TypeName:"data.UnixTime.Repr", Key:&_String{k}} } func (ma *_UnixTime__ReprAssembler) AssembleKey() ipld.NodeAssembler { switch ma.state { @@ -4508,7 +4400,7 @@ func (ma *_UnixTime__ReprAssembler) AssembleValue() ipld.NodeAssembler { case 1: ma.ca_FractionalNanoseconds.w = ma.w.FractionalNanoseconds.v ma.ca_FractionalNanoseconds.m = &ma.w.FractionalNanoseconds.m - + return &ma.ca_FractionalNanoseconds default: panic("unreachable") @@ -4529,9 +4421,9 @@ func (ma *_UnixTime__ReprAssembler) Finish() error { case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } - if ma.s&fieldBits__UnixTime_sufficient != fieldBits__UnixTime_sufficient { + if ma.s & fieldBits__UnixTime_sufficient != fieldBits__UnixTime_sufficient { err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} - if ma.s&fieldBit__UnixTime_Seconds == 0 { + if ma.s & fieldBit__UnixTime_Seconds == 0 { err.Missing = append(err.Missing, "Seconds") } return err @@ -4546,9 +4438,7 @@ func (ma *_UnixTime__ReprAssembler) KeyPrototype() ipld.NodePrototype { func (ma *_UnixTime__ReprAssembler) ValuePrototype(k string) ipld.NodePrototype { panic("todo structbuilder mapassembler repr valueprototype") } - type _UnixTime__ReprKeyAssembler _UnixTime__ReprAssembler - func (_UnixTime__ReprKeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.BeginMap(0) } @@ -4573,7 +4463,7 @@ func (ka *_UnixTime__ReprKeyAssembler) AssignString(k string) error { } switch k { case "Seconds": - if ka.s&fieldBit__UnixTime_Seconds != 0 { + if ka.s & fieldBit__UnixTime_Seconds != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_Seconds_serial} } ka.s += fieldBit__UnixTime_Seconds @@ -4581,7 +4471,7 @@ func (ka *_UnixTime__ReprKeyAssembler) AssignString(k string) error { ka.f = 0 return nil case "FractionalNanoseconds": - if ka.s&fieldBit__UnixTime_FractionalNanoseconds != 0 { + if ka.s & fieldBit__UnixTime_FractionalNanoseconds != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_FractionalNanoseconds_serial} } ka.s += fieldBit__UnixTime_FractionalNanoseconds @@ -4589,7 +4479,7 @@ func (ka *_UnixTime__ReprKeyAssembler) AssignString(k string) error { ka.f = 1 return nil } - return ipld.ErrInvalidKey{TypeName: "data.UnixTime.Repr", Key: &_String{k}} + return ipld.ErrInvalidKey{TypeName:"data.UnixTime.Repr", Key:&_String{k}} } func (_UnixTime__ReprKeyAssembler) AssignBytes([]byte) error { return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.AssignBytes(nil) @@ -4607,3 +4497,4 @@ func (ka *_UnixTime__ReprKeyAssembler) AssignNode(v ipld.Node) error { func (_UnixTime__ReprKeyAssembler) Prototype() ipld.NodePrototype { return _String__Prototype{} } + diff --git a/unixfs/node/data/permissions.go b/unixfs/node/data/permissions.go index d0b4dff7a..47230ea17 100644 --- a/unixfs/node/data/permissions.go +++ b/unixfs/node/data/permissions.go @@ -11,6 +11,8 @@ func (u UnixFSData) Permissions() int { return DefaultPermissions(u) } +// DefaultPermissions gets the default permissions for a UnixFS object based on its +// type func DefaultPermissions(u UnixFSData) int { if u.FieldDataType().Int() == Data_File { return FilePermissionsDefault diff --git a/unixfs/node/data/unmarshal.go b/unixfs/node/data/unmarshal.go index 7fbd76c64..6e0fcddcc 100644 --- a/unixfs/node/data/unmarshal.go +++ b/unixfs/node/data/unmarshal.go @@ -2,7 +2,6 @@ package data import ( "errors" - "fmt" "math" "github.com/ipld/go-ipld-prime" @@ -40,7 +39,7 @@ func consumeUnixFSData(remaining []byte, ma ipld.MapAssembler) error { switch fieldNum { case Data_DataTypeWireNum: if wireType != protowire.VarintType { - return fmt.Errorf("protobuf: (UnixFSData) invalid wireType, field: DataType, expected %d, got %d", protowire.VarintType, wireType) + return ErrWrongWireType{"UnixFSData", "DataType", protowire.VarintType, wireType} } dataType, n := protowire.ConsumeVarint(remaining) if n < 0 { @@ -50,7 +49,7 @@ func consumeUnixFSData(remaining []byte, ma ipld.MapAssembler) error { qp.MapEntry(ma, "DataType", qp.Int(int64(dataType))) case Data_DataWireNum: if wireType != protowire.BytesType { - return fmt.Errorf("protobuf: (UnixFSData) invalid wireType, field: Data, expected %d, got %d", protowire.VarintType, wireType) + return ErrWrongWireType{"UnixFSData", "Data", protowire.VarintType, wireType} } data, n := protowire.ConsumeBytes(remaining) if n < 0 { @@ -60,7 +59,7 @@ func consumeUnixFSData(remaining []byte, ma ipld.MapAssembler) error { qp.MapEntry(ma, "Data", qp.Bytes(data)) case Data_FileSizeWireNum: if wireType != protowire.VarintType { - return fmt.Errorf("protobuf: (UnixFSData) invalid wireType, field: FileSize, expected %d, got %d", protowire.VarintType, wireType) + return ErrWrongWireType{"UnixFSData", "FileSize", protowire.VarintType, wireType} } fileSize, n := protowire.ConsumeVarint(remaining) if n < 0 { @@ -112,11 +111,11 @@ func consumeUnixFSData(remaining []byte, ma ipld.MapAssembler) error { } })) default: - return fmt.Errorf("protobuf: (UnixFSData) invalid wireType, field: BlockSizes, got %d", wireType) + return ErrWrongWireType{"UnixFSData", "BlockSizes", protowire.VarintType, wireType} } case Data_HashTypeWireNum: if wireType != protowire.VarintType { - return fmt.Errorf("protobuf: (UnixFSData) invalid wireType, field: HashType, expected %d, got %d", protowire.VarintType, wireType) + return ErrWrongWireType{"UnixFSData", "HashType", protowire.VarintType, wireType} } hashType, n := protowire.ConsumeVarint(remaining) if n < 0 { @@ -126,7 +125,7 @@ func consumeUnixFSData(remaining []byte, ma ipld.MapAssembler) error { qp.MapEntry(ma, "HashType", qp.Int(int64(hashType))) case Data_FanoutWireNum: if wireType != protowire.VarintType { - return fmt.Errorf("protobuf: (UnixFSData) invalid wireType, field: Fanout, expected %d, got %d", protowire.VarintType, wireType) + return ErrWrongWireType{"UnixFSData", "Fanout", protowire.VarintType, wireType} } fanout, n := protowire.ConsumeVarint(remaining) if n < 0 { @@ -136,7 +135,7 @@ func consumeUnixFSData(remaining []byte, ma ipld.MapAssembler) error { qp.MapEntry(ma, "Fanout", qp.Int(int64(fanout))) case Data_ModeWireNum: if wireType != protowire.VarintType { - return fmt.Errorf("protobuf: (UnixFSData) invalid wireType, field: Mode, expected %d, got %d", protowire.VarintType, wireType) + return ErrWrongWireType{"UnixFSData", "Mode", protowire.VarintType, wireType} } mode, n := protowire.ConsumeVarint(remaining) if n < 0 { @@ -149,7 +148,7 @@ func consumeUnixFSData(remaining []byte, ma ipld.MapAssembler) error { qp.MapEntry(ma, "Mode", qp.Int(int64(mode))) case Data_MTimeWireNum: if wireType != protowire.BytesType { - return fmt.Errorf("protobuf: (UnixFSData) invalid wireType, field: Mtime, expected %d, got %d", protowire.BytesType, wireType) + return ErrWrongWireType{"UnixFSData", "Mtime", protowire.BytesType, wireType} } mTimeBytes, n := protowire.ConsumeBytes(remaining) if n < 0 { @@ -215,7 +214,7 @@ func consumeUnixTime(remaining []byte, ma ipld.MapAssembler) error { switch fieldNum { case UnixTime_SecondsWireNum: if wireType != protowire.VarintType { - return fmt.Errorf("protobuf: (UnixTime) invalid wireType, field: Seconds, expected %d, got %d", protowire.VarintType, wireType) + return ErrWrongWireType{"UnixTime", "Seconds", protowire.VarintType, wireType} } seconds, n := protowire.ConsumeVarint(remaining) if n < 0 { @@ -225,7 +224,7 @@ func consumeUnixTime(remaining []byte, ma ipld.MapAssembler) error { qp.MapEntry(ma, "Seconds", qp.Int(int64(seconds))) case UnixTime_FractionalNanosecondsWireNum: if wireType != protowire.Fixed32Type { - return fmt.Errorf("protobuf: (UnixTime) invalid wireType, field: FractionalNanoseconds, expected %d, got %d", protowire.Fixed32Type, wireType) + return ErrWrongWireType{"UnixTime", "FractionalNanoseconds", protowire.Fixed32Type, wireType} } fractionalNanoseconds, n := protowire.ConsumeFixed32(remaining) if n < 0 { @@ -284,7 +283,7 @@ func consumeUnixFSMetadata(remaining []byte, ma ipld.MapAssembler) error { switch fieldNum { case Metadata_MimeTypeWireNum: if wireType != protowire.BytesType { - return fmt.Errorf("protobuf: (UnixFSMetadata) invalid wireType, field: MimeType, expected %d, got %d", protowire.VarintType, wireType) + return ErrWrongWireType{"UnixFSMetadata", "MimeType", protowire.VarintType, wireType} } mimeTypeBytes, n := protowire.ConsumeBytes(remaining) if n < 0 { diff --git a/unixfs/node/hamt/errors.go b/unixfs/node/hamt/errors.go new file mode 100644 index 000000000..1c2aa2b68 --- /dev/null +++ b/unixfs/node/hamt/errors.go @@ -0,0 +1,40 @@ +package hamt + +import "fmt" + +type errorType string + +func (e errorType) Error() string { + return string(e) +} + +const ( + // ErrNotProtobuf indicates an error attempting to load a HAMT from a non-protobuf node + ErrNotProtobuf errorType = "node was not a protobuf node" + // ErrNotUnixFSNode indicates an error attempting to load a HAMT from a generic protobuf node + ErrNotUnixFSNode errorType = "node was not a UnixFS node" + // ErrInvalidChildIndex indicates there is no link to load for the given child index + ErrInvalidChildIndex errorType = "invalid index passed to operate children (likely corrupt bitfield)" + // ErrHAMTTooDeep indicates we attempted to load from a HAMT node that went past the depth of the tree + ErrHAMTTooDeep errorType = "sharded directory too deep" + // ErrInvalidHashFunc indicates the HAMT node's hash function is unsupported (must be Murmur3) + ErrInvalidHashFunc errorType = "only murmur3 supported as hash function" + // ErrNoDataField indicates the HAMT node's UnixFS structure lacked a data field, which is + // where a bit mask is stored + ErrNoDataField errorType = "Data field not present" + // ErrNoFanoutField indicates the HAMT node's UnixFS structure lacked a fanout field, which is required + ErrNoFanoutField errorType = "Fanout field not present" + // ErrHAMTSizeInvalid indicates the HAMT's size property was not an exact power of 2 + ErrHAMTSizeInvalid errorType = "hamt size should be a power of two" + // ErrMissingLinkName indicates a link in a HAMT had no Name property (required for all HAMTs) + ErrMissingLinkName errorType = "missing link name" +) + +// ErrInvalidLinkName indicates a link's name was too short for a HAMT +type ErrInvalidLinkName struct { + Name string +} + +func (e ErrInvalidLinkName) Error() string { + return fmt.Sprintf("invalid link name '%s'", e.Name) +} diff --git a/unixfs/node/hamt/shardeddir.go b/unixfs/node/hamt/shardeddir.go index 1fa409936..0db2dd888 100644 --- a/unixfs/node/hamt/shardeddir.go +++ b/unixfs/node/hamt/shardeddir.go @@ -20,6 +20,8 @@ const ( var _ ipld.Node = UnixFSHAMTShard(nil) var _ schema.TypedNode = UnixFSHAMTShard(nil) +// UnixFSHAMTShared is an IPLD Prime Node that provides a read interface +// to a UnixFS HAMT type UnixFSHAMTShard = *_UnixFSHAMTShard type _UnixFSHAMTShard struct { @@ -32,6 +34,8 @@ type _UnixFSHAMTShard struct { cachedLength int64 } +// NewUnixFSHAMTShard attempts to construct a UnixFSHAMTShard node from the base protobuf node plus +// a decoded UnixFSData structure func NewUnixFSHAMTShard(ctx context.Context, substrate dagpb.PBNode, data data.UnixFSData, lsys *ipld.LinkSystem) (ipld.Node, error) { if err := ValidateHAMTData(data); err != nil { return nil, err @@ -54,7 +58,7 @@ func (n UnixFSHAMTShard) Kind() ipld.Kind { } // LookupByString looks for the key in the list of links with a matching name -func (n UnixFSHAMTShard) LookupByString(key string) (ipld.Node, error) { +func (n *_UnixFSHAMTShard) LookupByString(key string) (ipld.Node, error) { hv := &hashBits{b: hash([]byte(key))} return n.lookup(key, hv) } @@ -91,13 +95,14 @@ func (n UnixFSHAMTShard) lookup(key string, hv *hashBits) (dagpb.Link, error) { return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} } +// AttemptHAMTShardFromNode attempts to read a HAMT shard from a general protobuf node func AttemptHAMTShardFromNode(ctx context.Context, nd ipld.Node, lsys *ipld.LinkSystem) (UnixFSHAMTShard, error) { pbnd, ok := nd.(dagpb.PBNode) if !ok { - return nil, fmt.Errorf("hamt.AttemptHAMTShardFromNode: child node was not a protobuf node") + return nil, fmt.Errorf("hamt.AttemptHAMTShardFromNode: %w", ErrNotProtobuf) } if !pbnd.FieldData().Exists() { - return nil, fmt.Errorf("hamt.AttemptHAMTShardFromNode: child node was not a UnixFS node") + return nil, fmt.Errorf("hamt.AttemptHAMTShardFromNode: %w", ErrNotUnixFSNode) } data, err := data.DecodeUnixFSData(pbnd.FieldData().Must().Bytes()) if err != nil { @@ -330,7 +335,7 @@ func (n UnixFSHAMTShard) FieldData() dagpb.MaybeBytes { func (n UnixFSHAMTShard) getChildLink(childIndex int) (dagpb.PBLink, error) { linkIndex := n.bitfield.OnesBefore(childIndex) if linkIndex >= int(n.FieldLinks().Length()) || linkIndex < 0 { - return nil, fmt.Errorf("invalid index passed to operate children (likely corrupt bitfield)") + return nil, ErrInvalidChildIndex } return n.FieldLinks().Lookup(int64(linkIndex)), nil } diff --git a/unixfs/node/hamt/util.go b/unixfs/node/hamt/util.go index d58ce5a66..d262de49b 100644 --- a/unixfs/node/hamt/util.go +++ b/unixfs/node/hamt/util.go @@ -27,7 +27,7 @@ func mkmask(n int) byte { // error if there aren't enough bits. func (hb *hashBits) Next(i int) (int, error) { if hb.consumed+i > len(hb.b)*8 { - return 0, fmt.Errorf("sharded directory too deep") + return 0, ErrHAMTTooDeep } return hb.next(i), nil } @@ -62,15 +62,15 @@ func ValidateHAMTData(nd data.UnixFSData) error { } if !nd.FieldHashType().Exists() || uint64(nd.FieldHashType().Must().Int()) != HashMurmur3 { - return fmt.Errorf("only murmur3 supported as hash function") + return ErrInvalidHashFunc } if !nd.FieldData().Exists() { - return fmt.Errorf("Data field not present") + return ErrNoDataField } if !nd.FieldFanout().Exists() { - return fmt.Errorf("Fanout field not present") + return ErrNoFanoutField } if err := checkLogTwo(int(nd.FieldFanout().Must().Int())); err != nil { return err @@ -95,11 +95,11 @@ func BitField(nd data.UnixFSData) bitfield.Bitfield { func checkLogTwo(v int) error { if v <= 0 { - return fmt.Errorf("hamt size should be a power of two") + return ErrHAMTSizeInvalid } lg2 := bits.TrailingZeros(uint(v)) if 1< Date: Fri, 2 Apr 2021 14:41:42 -0700 Subject: [PATCH 08/43] feat(reification): use new prime node reification Use ipld-primes reifier to avoid uncomfortable node prototype stuff This commit was moved from ipfs/go-unixfsnode@de45652f269f2e975bbce5bf9f164d2b1e0dd653 --- unixfs/node/hamt/shardeddir.go | 5 +++ unixfs/node/nodeprototype.go | 63 ---------------------------------- unixfs/node/reification.go | 30 +++++----------- 3 files changed, 14 insertions(+), 84 deletions(-) delete mode 100644 unixfs/node/nodeprototype.go diff --git a/unixfs/node/hamt/shardeddir.go b/unixfs/node/hamt/shardeddir.go index 0db2dd888..865dcfc7f 100644 --- a/unixfs/node/hamt/shardeddir.go +++ b/unixfs/node/hamt/shardeddir.go @@ -97,6 +97,11 @@ func (n UnixFSHAMTShard) lookup(key string, hv *hashBits) (dagpb.Link, error) { // AttemptHAMTShardFromNode attempts to read a HAMT shard from a general protobuf node func AttemptHAMTShardFromNode(ctx context.Context, nd ipld.Node, lsys *ipld.LinkSystem) (UnixFSHAMTShard, error) { + // shortcut if node is already a hamt + hnd, ok := nd.(UnixFSHAMTShard) + if ok { + return hnd, nil + } pbnd, ok := nd.(dagpb.PBNode) if !ok { return nil, fmt.Errorf("hamt.AttemptHAMTShardFromNode: %w", ErrNotProtobuf) diff --git a/unixfs/node/nodeprototype.go b/unixfs/node/nodeprototype.go deleted file mode 100644 index c480d3afc..000000000 --- a/unixfs/node/nodeprototype.go +++ /dev/null @@ -1,63 +0,0 @@ -package unixfsnode - -import ( - "context" - - dagpb "github.com/ipld/go-codec-dagpb" - "github.com/ipld/go-ipld-prime" - cidlink "github.com/ipld/go-ipld-prime/linking/cid" - "github.com/ipld/go-ipld-prime/traversal" -) - -type prototypeChooser struct { - lsys *ipld.LinkSystem - existing traversal.LinkTargetNodePrototypeChooser -} - -// NodeBuilder for UnixFS Nodes -- note: this expects underlying data that -// has the same format as a normal dagpb node -- in fact, it uses the -// exact same builder but then wraps at the end - -type _UnixFSNode__Prototype struct { - ctx context.Context - lsys *ipld.LinkSystem -} - -func (p _UnixFSNode__Prototype) NewBuilder() ipld.NodeBuilder { - var nb _UnixFSNode__Builder - nb.ctx = p.ctx - nb.lsys = p.lsys - nb.Reset() - return &nb -} - -type _UnixFSNode__Builder struct { - ipld.NodeBuilder - ctx context.Context - lsys *ipld.LinkSystem -} - -func (nb *_UnixFSNode__Builder) Build() ipld.Node { - n := nb.NodeBuilder.Build().(dagpb.PBNode) - un, err := Reify(nb.ctx, n, nb.lsys) - if err != nil { - return n - } - return un -} - -func (nb *_UnixFSNode__Builder) Reset() { - snb := dagpb.Type.PBNode.NewBuilder() - *nb = _UnixFSNode__Builder{snb, nb.ctx, nb.lsys} -} - -func (pc prototypeChooser) choose(lnk ipld.Link, lnkCtx ipld.LinkContext) (ipld.NodePrototype, error) { - if lnk, ok := lnk.(cidlink.Link); ok && lnk.Cid.Prefix().Codec == 0x70 { - return _UnixFSNode__Prototype{lnkCtx.Ctx, pc.lsys}, nil - } - return pc.existing(lnk, lnkCtx) -} - -func AugmentPrototypeChooser(lsys *ipld.LinkSystem, existing traversal.LinkTargetNodePrototypeChooser) traversal.LinkTargetNodePrototypeChooser { - return prototypeChooser{lsys: lsys, existing: existing}.choose -} diff --git a/unixfs/node/reification.go b/unixfs/node/reification.go index 2d8bb54bc..9666dfc26 100644 --- a/unixfs/node/reification.go +++ b/unixfs/node/reification.go @@ -11,41 +11,27 @@ import ( "github.com/ipld/go-ipld-prime" ) -func asPBNode(maybePBNodeRoot ipld.Node) (dagpb.PBNode, error) { - if pbNode, ok := maybePBNodeRoot.(dagpb.PBNode); ok { - return pbNode, nil - } - - // Shortcut didn't work. Process via the data model. - // The AssignNode method on the pb node already contains all the logic necessary for this, so we use that. - nb := dagpb.Type.PBNode.NewBuilder() - if err := nb.AssignNode(maybePBNodeRoot); err != nil { - return nil, err - } - return nb.Build().(dagpb.PBNode), nil -} - // Reify looks at an ipld Node and tries to interpret it as a UnixFSNode // if successful, it returns the UnixFSNode -func Reify(ctx context.Context, maybePBNodeRoot ipld.Node, lsys *ipld.LinkSystem) (ipld.Node, error) { - pbNode, err := asPBNode(maybePBNodeRoot) - if err != nil { - return nil, fmt.Errorf("unixfsnode.Reify failed: data does not match expected shape for Protobuf Node: %w", err) +func Reify(lnkCtx ipld.LinkContext, maybePBNodeRoot ipld.Node, lsys *ipld.LinkSystem) (ipld.Node, error) { + pbNode, ok := maybePBNodeRoot.(dagpb.PBNode) + if !ok { + return maybePBNodeRoot, nil } if !pbNode.FieldData().Exists() { // no data field, therefore, not UnixFS - return defaultReifier(ctx, pbNode, lsys) + return defaultReifier(lnkCtx.Ctx, pbNode, lsys) } data, err := data.DecodeUnixFSData(pbNode.Data.Must().Bytes()) if err != nil { // we could not decode the UnixFS data, therefore, not UnixFS - return defaultReifier(ctx, pbNode, lsys) + return defaultReifier(lnkCtx.Ctx, pbNode, lsys) } builder, ok := reifyFuncs[data.FieldDataType().Int()] if !ok { return nil, fmt.Errorf("No reification for this UnixFS node type") } - return builder(ctx, pbNode, data, lsys) + return builder(lnkCtx.Ctx, pbNode, data, lsys) } type reifyTypeFunc func(context.Context, dagpb.PBNode, data.UnixFSData, *ipld.LinkSystem) (ipld.Node, error) @@ -60,3 +46,5 @@ var reifyFuncs = map[int64]reifyTypeFunc{ func defaultReifier(_ context.Context, substrate dagpb.PBNode, _ *ipld.LinkSystem) (ipld.Node, error) { return &_PathedPBNode{_substrate: substrate}, nil } + +var _ ipld.NodeReifier = Reify From f25054d5fe672f80e00d20110c5d5baa628e2d76 Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Fri, 2 Apr 2021 19:22:54 -0700 Subject: [PATCH 09/43] fix(unixfsnode): respond to PR comments This commit was moved from ipfs/go-unixfsnode@e56e007be4f9f78e9d06e73fce3440a859cc9c93 --- unixfs/node/data/builder/builder.go | 34 +++++++-------- unixfs/node/data/datatypes.go | 12 ++++++ unixfs/node/data/errors.go | 4 +- unixfs/node/data/format_test.go | 9 ++-- unixfs/node/data/marshal.go | 2 +- unixfs/node/data/permissions.go | 12 +++--- unixfs/node/data/unmarshal.go | 66 ++++++++++++----------------- unixfs/node/data/wirenumbers.go | 2 +- unixfs/node/hamt/errors.go | 8 ++-- unixfs/node/hamt/shardeddir.go | 38 ++++++++--------- unixfs/node/hamt/util.go | 35 +++++++-------- unixfs/node/reification.go | 2 +- 12 files changed, 114 insertions(+), 110 deletions(-) diff --git a/unixfs/node/data/builder/builder.go b/unixfs/node/data/builder/builder.go index 1326f23b5..212653dc7 100644 --- a/unixfs/node/data/builder/builder.go +++ b/unixfs/node/data/builder/builder.go @@ -16,7 +16,7 @@ import ( // // smallFileData, err := BuildUnixFS(func(b *Builder) { // Data(b, []byte{"hello world"}) -// MTime(b, func(tb TimeBuilder) { +// Mtime(b, func(tb TimeBuilder) { // Time(tb, time.Now()) // }) // }) @@ -26,10 +26,10 @@ func BuildUnixFS(fn func(*Builder)) (data.UnixFSData, error) { b := &Builder{MapAssembler: ma} fn(b) if !b.hasBlockSizes { - qp.MapEntry(ma, "BlockSizes", qp.List(0, func(ipld.ListAssembler) {})) + qp.MapEntry(ma, data.Field__BlockSizes, qp.List(0, func(ipld.ListAssembler) {})) } if !b.hasDataType { - qp.MapEntry(ma, "DataType", qp.Int(data.Data_File)) + qp.MapEntry(ma, data.Field__DataType, qp.Int(data.Data_File)) } }) if err != nil { @@ -51,24 +51,24 @@ func DataType(b *Builder, dataType int64) { if !ok { panic(data.ErrInvalidDataType{dataType}) } - qp.MapEntry(b.MapAssembler, "DataType", qp.Int(dataType)) + qp.MapEntry(b.MapAssembler, data.Field__DataType, qp.Int(dataType)) b.hasDataType = true } // Data sets the data member inside the UnixFS data -func Data(b *Builder, data []byte) { - qp.MapEntry(b.MapAssembler, "Data", qp.Bytes(data)) +func Data(b *Builder, dataBytes []byte) { + qp.MapEntry(b.MapAssembler, data.Field__Data, qp.Bytes(dataBytes)) } // FileSize sets the file size which should be the size of actual bytes underneath // this node for large files, w/o additional bytes to encode intermediate nodes func FileSize(b *Builder, fileSize uint64) { - qp.MapEntry(b.MapAssembler, "FileSize", qp.Int(int64(fileSize))) + qp.MapEntry(b.MapAssembler, data.Field__FileSize, qp.Int(int64(fileSize))) } // BlockSizes encodes block sizes for each child node func BlockSizes(b *Builder, blockSizes []uint64) { - qp.MapEntry(b.MapAssembler, "BlockSizes", qp.List(int64(len(blockSizes)), func(la ipld.ListAssembler) { + qp.MapEntry(b.MapAssembler, data.Field__BlockSizes, qp.List(int64(len(blockSizes)), func(la ipld.ListAssembler) { for _, bs := range blockSizes { qp.ListEntry(la, qp.Int(int64(bs))) } @@ -76,20 +76,20 @@ func BlockSizes(b *Builder, blockSizes []uint64) { b.hasBlockSizes = true } -// HashFunc sets the hash function for this node -- only applicable to HAMT -func HashFunc(b *Builder, hashFunc uint64) { - qp.MapEntry(b.MapAssembler, "HashFunc", qp.Int(int64(hashFunc))) +// HashType sets the hash function for this node -- only applicable to HAMT +func HashType(b *Builder, hashType uint64) { + qp.MapEntry(b.MapAssembler, data.Field__HashType, qp.Int(int64(hashType))) } // Fanout sets the fanout in a HAMT tree func Fanout(b *Builder, fanout uint64) { - qp.MapEntry(b.MapAssembler, "Fanout", qp.Int(int64(fanout))) + qp.MapEntry(b.MapAssembler, data.Field__Fanout, qp.Int(int64(fanout))) } // Permissions sets file permissions for the Mode member of the UnixFS node func Permissions(b *Builder, mode int) { mode = mode & 0xFFF - qp.MapEntry(b.MapAssembler, "Mode", qp.Int(int64(mode))) + qp.MapEntry(b.MapAssembler, data.Field__Mode, qp.Int(int64(mode))) } func parseModeString(modeString string) (uint64, error) { @@ -107,13 +107,13 @@ func PermissionsString(b *Builder, modeString string) { panic(err) } mode64 = mode64 & 0xFFF - qp.MapEntry(b.MapAssembler, "Mode", qp.Int(int64(mode64))) + qp.MapEntry(b.MapAssembler, data.Field__Mode, qp.Int(int64(mode64))) } // Mtime sets the modification time for this node using the time builder interface // and associated methods func Mtime(b *Builder, fn func(tb TimeBuilder)) { - qp.MapEntry(b.MapAssembler, "Mtime", qp.Map(-1, func(ma ipld.MapAssembler) { + qp.MapEntry(b.MapAssembler, data.Field__Mtime, qp.Map(-1, func(ma ipld.MapAssembler) { fn(ma) })) } @@ -129,7 +129,7 @@ func Time(ma TimeBuilder, t time.Time) { // Seconds sets the seconds for a modification time func Seconds(ma TimeBuilder, seconds int64) { - qp.MapEntry(ma, "Seconds", qp.Int(seconds)) + qp.MapEntry(ma, data.Field__Seconds, qp.Int(seconds)) } @@ -139,5 +139,5 @@ func FractionalNanoseconds(ma TimeBuilder, nanoseconds int32) { if nanoseconds < 0 || nanoseconds > 999999999 { panic(errors.New("mtime-nsecs must be within the range [0,999999999]")) } - qp.MapEntry(ma, "FractionalNanoseconds", qp.Int(int64(nanoseconds))) + qp.MapEntry(ma, data.Field__Nanoseconds, qp.Int(int64(nanoseconds))) } diff --git a/unixfs/node/data/datatypes.go b/unixfs/node/data/datatypes.go index 9acab920b..514384810 100644 --- a/unixfs/node/data/datatypes.go +++ b/unixfs/node/data/datatypes.go @@ -26,3 +26,15 @@ var DataTypeValues = map[string]int64{ "Symlink": Data_Symlink, "HAMTShard": Data_HAMTShard, } + +const Field__DataType = "DataType" +const Field__Data = "Data" +const Field__FileSize = "FileSize" +const Field__BlockSizes = "BlockSizes" +const Field__HashType = "HashType" +const Field__Fanout = "Fanout" +const Field__Mode = "Mode" +const Field__Mtime = "Mtime" +const Field__Seconds = "Seconds" +const Field__Nanoseconds = "FractionalNanoseconds" +const Field__MimeType = "MimeType" diff --git a/unixfs/node/data/errors.go b/unixfs/node/data/errors.go index 9cbe179fa..9ef5943aa 100644 --- a/unixfs/node/data/errors.go +++ b/unixfs/node/data/errors.go @@ -20,7 +20,7 @@ func (e ErrWrongNodeType) Error() string { if !ok { actualName = "Unknown Type" } - return fmt.Sprintf("Incorrect Node Type: (UnixFSData) expected type: %s, actual type: %s", expectedName, actualName) + return fmt.Sprintf("incorrect Node Type: (UnixFSData) expected type: %s, actual type: %s", expectedName, actualName) } type ErrWrongWireType struct { @@ -39,5 +39,5 @@ type ErrInvalidDataType struct { } func (e ErrInvalidDataType) Error() string { - return fmt.Sprintf("Type: %d is not valid", e.DataType) + return fmt.Sprintf("type: %d is not valid", e.DataType) } diff --git a/unixfs/node/data/format_test.go b/unixfs/node/data/format_test.go index d14a0ed6a..776bca3e9 100644 --- a/unixfs/node/data/format_test.go +++ b/unixfs/node/data/format_test.go @@ -11,6 +11,7 @@ import ( "testing" "time" + "github.com/ipfs/go-unixfsnode/data" . "github.com/ipfs/go-unixfsnode/data" "github.com/ipfs/go-unixfsnode/data/builder" "github.com/ipld/go-ipld-prime" @@ -253,9 +254,9 @@ func TestUnixfsFormat(t *testing.T) { t.Run("respects high bits in mode read from buffer", func(t *testing.T) { mode := 0o0100644 // similar to output from fs.stat nd, err := qp.BuildMap(Type.UnixFSData, -1, func(ma ipld.MapAssembler) { - qp.MapEntry(ma, "DataType", qp.Int(Data_File)) - qp.MapEntry(ma, "BlockSizes", qp.List(0, func(ipld.ListAssembler) {})) - qp.MapEntry(ma, "Mode", qp.Int(int64(mode))) + qp.MapEntry(ma, data.Field__DataType, qp.Int(Data_File)) + qp.MapEntry(ma, data.Field__BlockSizes, qp.List(0, func(ipld.ListAssembler) {})) + qp.MapEntry(ma, data.Field__Mode, qp.Int(int64(mode))) }) require.NoError(t, err) und, ok := nd.(UnixFSData) @@ -321,7 +322,7 @@ func TestUnixfsFormat(t *testing.T) { _, err := builder.BuildUnixFS(func(b *builder.Builder) { builder.DataType(b, 9999) }) - require.EqualError(t, err, "Type: 9999 is not valid") + require.EqualError(t, err, "type: 9999 is not valid") }) } diff --git a/unixfs/node/data/marshal.go b/unixfs/node/data/marshal.go index 7bef639ed..79dbb50cf 100644 --- a/unixfs/node/data/marshal.go +++ b/unixfs/node/data/marshal.go @@ -49,7 +49,7 @@ func AppendEncodeUnixFSData(enc []byte, node UnixFSData) []byte { size += protowire.SizeTag(2) size += protowire.SizeFixed32() } - enc = protowire.AppendTag(enc, Data_MTimeWireNum, protowire.BytesType) + enc = protowire.AppendTag(enc, Data_MtimeWireNum, protowire.BytesType) enc = protowire.AppendVarint(enc, uint64(size)) enc = AppendEncodeUnixTime(enc, mtime) } diff --git a/unixfs/node/data/permissions.go b/unixfs/node/data/permissions.go index 47230ea17..00652e65f 100644 --- a/unixfs/node/data/permissions.go +++ b/unixfs/node/data/permissions.go @@ -14,14 +14,14 @@ func (u UnixFSData) Permissions() int { // DefaultPermissions gets the default permissions for a UnixFS object based on its // type func DefaultPermissions(u UnixFSData) int { - if u.FieldDataType().Int() == Data_File { + switch u.FieldDataType().Int() { + case Data_File: return FilePermissionsDefault - } - if u.FieldDataType().Int() == Data_Directory { + case Data_Directory: return DirectorPerimissionsDefault - } - if u.FieldDataType().Int() == Data_HAMTShard { + case Data_HAMTShard: return HAMTShardPerimissionsDefault + default: + return 0 } - return 0 } diff --git a/unixfs/node/data/unmarshal.go b/unixfs/node/data/unmarshal.go index 6e0fcddcc..c46ed62ad 100644 --- a/unixfs/node/data/unmarshal.go +++ b/unixfs/node/data/unmarshal.go @@ -26,10 +26,7 @@ func consumeUnixFSData(remaining []byte, ma ipld.MapAssembler) error { var bsa ipld.NodeBuilder var la ipld.ListAssembler var packedBlockSizes bool - for { - if len(remaining) == 0 { - break - } + for len(remaining) != 0 { fieldNum, wireType, n := protowire.ConsumeTag(remaining) if n < 0 { @@ -39,34 +36,34 @@ func consumeUnixFSData(remaining []byte, ma ipld.MapAssembler) error { switch fieldNum { case Data_DataTypeWireNum: if wireType != protowire.VarintType { - return ErrWrongWireType{"UnixFSData", "DataType", protowire.VarintType, wireType} + return ErrWrongWireType{"UnixFSData", Field__DataType, protowire.VarintType, wireType} } dataType, n := protowire.ConsumeVarint(remaining) if n < 0 { return protowire.ParseError(n) } remaining = remaining[n:] - qp.MapEntry(ma, "DataType", qp.Int(int64(dataType))) + qp.MapEntry(ma, Field__DataType, qp.Int(int64(dataType))) case Data_DataWireNum: if wireType != protowire.BytesType { - return ErrWrongWireType{"UnixFSData", "Data", protowire.VarintType, wireType} + return ErrWrongWireType{"UnixFSData", Field__Data, protowire.VarintType, wireType} } data, n := protowire.ConsumeBytes(remaining) if n < 0 { return protowire.ParseError(n) } remaining = remaining[n:] - qp.MapEntry(ma, "Data", qp.Bytes(data)) + qp.MapEntry(ma, Field__Data, qp.Bytes(data)) case Data_FileSizeWireNum: if wireType != protowire.VarintType { - return ErrWrongWireType{"UnixFSData", "FileSize", protowire.VarintType, wireType} + return ErrWrongWireType{"UnixFSData", Field__FileSize, protowire.VarintType, wireType} } fileSize, n := protowire.ConsumeVarint(remaining) if n < 0 { return protowire.ParseError(n) } remaining = remaining[n:] - qp.MapEntry(ma, "FileSize", qp.Int(int64(fileSize))) + qp.MapEntry(ma, Field__FileSize, qp.Int(int64(fileSize))) case Data_BlockSizesWireNum: switch wireType { case protowire.VarintType: @@ -104,38 +101,38 @@ func consumeUnixFSData(remaining []byte, ma ipld.MapAssembler) error { blockSizeCount++ } } - qp.MapEntry(ma, "BlockSizes", qp.List(blockSizeCount, func(la ipld.ListAssembler) { + qp.MapEntry(ma, Field__BlockSizes, qp.List(blockSizeCount, func(la ipld.ListAssembler) { err := consumeBlockSizes(blockSizesBytes, blockSizeCount, la) if err != nil { panic(err) } })) default: - return ErrWrongWireType{"UnixFSData", "BlockSizes", protowire.VarintType, wireType} + return ErrWrongWireType{"UnixFSData", Field__BlockSizes, protowire.VarintType, wireType} } case Data_HashTypeWireNum: if wireType != protowire.VarintType { - return ErrWrongWireType{"UnixFSData", "HashType", protowire.VarintType, wireType} + return ErrWrongWireType{"UnixFSData", Field__HashType, protowire.VarintType, wireType} } hashType, n := protowire.ConsumeVarint(remaining) if n < 0 { return protowire.ParseError(n) } remaining = remaining[n:] - qp.MapEntry(ma, "HashType", qp.Int(int64(hashType))) + qp.MapEntry(ma, Field__HashType, qp.Int(int64(hashType))) case Data_FanoutWireNum: if wireType != protowire.VarintType { - return ErrWrongWireType{"UnixFSData", "Fanout", protowire.VarintType, wireType} + return ErrWrongWireType{"UnixFSData", Field__Fanout, protowire.VarintType, wireType} } fanout, n := protowire.ConsumeVarint(remaining) if n < 0 { return protowire.ParseError(n) } remaining = remaining[n:] - qp.MapEntry(ma, "Fanout", qp.Int(int64(fanout))) + qp.MapEntry(ma, Field__Fanout, qp.Int(int64(fanout))) case Data_ModeWireNum: if wireType != protowire.VarintType { - return ErrWrongWireType{"UnixFSData", "Mode", protowire.VarintType, wireType} + return ErrWrongWireType{"UnixFSData", Field__Mode, protowire.VarintType, wireType} } mode, n := protowire.ConsumeVarint(remaining) if n < 0 { @@ -145,17 +142,17 @@ func consumeUnixFSData(remaining []byte, ma ipld.MapAssembler) error { return errors.New("mode should be a 32 bit value") } remaining = remaining[n:] - qp.MapEntry(ma, "Mode", qp.Int(int64(mode))) - case Data_MTimeWireNum: + qp.MapEntry(ma, Field__Mode, qp.Int(int64(mode))) + case Data_MtimeWireNum: if wireType != protowire.BytesType { - return ErrWrongWireType{"UnixFSData", "Mtime", protowire.BytesType, wireType} + return ErrWrongWireType{"UnixFSData", Field__Mtime, protowire.BytesType, wireType} } mTimeBytes, n := protowire.ConsumeBytes(remaining) if n < 0 { return protowire.ParseError(n) } remaining = remaining[n:] - qp.MapEntry(ma, "Mtime", qp.Map(-1, func(ma ipld.MapAssembler) { + qp.MapEntry(ma, Field__Mtime, qp.Map(-1, func(ma ipld.MapAssembler) { err := consumeUnixTime(mTimeBytes, ma) if err != nil { panic(err) @@ -171,14 +168,14 @@ func consumeUnixFSData(remaining []byte, ma ipld.MapAssembler) error { } if !packedBlockSizes { if la == nil { - qp.MapEntry(ma, "BlockSizes", qp.List(0, func(ipld.ListAssembler) {})) + qp.MapEntry(ma, Field__BlockSizes, qp.List(0, func(ipld.ListAssembler) {})) } else { err := la.Finish() if err != nil { return err } nd := bsa.Build() - qp.MapEntry(ma, "BlockSizes", qp.Node(nd)) + qp.MapEntry(ma, Field__BlockSizes, qp.Node(nd)) } } return nil @@ -200,11 +197,7 @@ func consumeBlockSizes(remaining []byte, count int64, la ipld.ListAssembler) err } func consumeUnixTime(remaining []byte, ma ipld.MapAssembler) error { - for { - if len(remaining) == 0 { - break - } - + for len(remaining) != 0 { fieldNum, wireType, n := protowire.ConsumeTag(remaining) if n < 0 { return protowire.ParseError(n) @@ -214,24 +207,24 @@ func consumeUnixTime(remaining []byte, ma ipld.MapAssembler) error { switch fieldNum { case UnixTime_SecondsWireNum: if wireType != protowire.VarintType { - return ErrWrongWireType{"UnixTime", "Seconds", protowire.VarintType, wireType} + return ErrWrongWireType{"UnixTime", Field__Seconds, protowire.VarintType, wireType} } seconds, n := protowire.ConsumeVarint(remaining) if n < 0 { return protowire.ParseError(n) } remaining = remaining[n:] - qp.MapEntry(ma, "Seconds", qp.Int(int64(seconds))) + qp.MapEntry(ma, Field__Seconds, qp.Int(int64(seconds))) case UnixTime_FractionalNanosecondsWireNum: if wireType != protowire.Fixed32Type { - return ErrWrongWireType{"UnixTime", "FractionalNanoseconds", protowire.Fixed32Type, wireType} + return ErrWrongWireType{"UnixTime", Field__Nanoseconds, protowire.Fixed32Type, wireType} } fractionalNanoseconds, n := protowire.ConsumeFixed32(remaining) if n < 0 { return protowire.ParseError(n) } remaining = remaining[n:] - qp.MapEntry(ma, "FractionalNanoseconds", qp.Int(int64(fractionalNanoseconds))) + qp.MapEntry(ma, Field__Nanoseconds, qp.Int(int64(fractionalNanoseconds))) default: n := protowire.ConsumeFieldValue(fieldNum, wireType, remaining) if n < 0 { @@ -269,10 +262,7 @@ func DecodeUnixFSMetadata(src []byte) (UnixFSMetadata, error) { } func consumeUnixFSMetadata(remaining []byte, ma ipld.MapAssembler) error { - for { - if len(remaining) == 0 { - break - } + for len(remaining) != 0 { fieldNum, wireType, n := protowire.ConsumeTag(remaining) if n < 0 { @@ -283,14 +273,14 @@ func consumeUnixFSMetadata(remaining []byte, ma ipld.MapAssembler) error { switch fieldNum { case Metadata_MimeTypeWireNum: if wireType != protowire.BytesType { - return ErrWrongWireType{"UnixFSMetadata", "MimeType", protowire.VarintType, wireType} + return ErrWrongWireType{"UnixFSMetadata", Field__MimeType, protowire.VarintType, wireType} } mimeTypeBytes, n := protowire.ConsumeBytes(remaining) if n < 0 { return protowire.ParseError(n) } remaining = remaining[n:] - qp.MapEntry(ma, "MimeType", qp.String(string(mimeTypeBytes))) + qp.MapEntry(ma, Field__MimeType, qp.String(string(mimeTypeBytes))) default: n := protowire.ConsumeFieldValue(fieldNum, wireType, remaining) if n < 0 { diff --git a/unixfs/node/data/wirenumbers.go b/unixfs/node/data/wirenumbers.go index 43c8aab76..5bb146256 100644 --- a/unixfs/node/data/wirenumbers.go +++ b/unixfs/node/data/wirenumbers.go @@ -10,7 +10,7 @@ const ( Data_HashTypeWireNum protowire.Number = 5 Data_FanoutWireNum protowire.Number = 6 Data_ModeWireNum protowire.Number = 7 - Data_MTimeWireNum protowire.Number = 8 + Data_MtimeWireNum protowire.Number = 8 UnixTime_SecondsWireNum protowire.Number = 1 UnixTime_FractionalNanosecondsWireNum protowire.Number = 2 Metadata_MimeTypeWireNum protowire.Number = 1 diff --git a/unixfs/node/hamt/errors.go b/unixfs/node/hamt/errors.go index 1c2aa2b68..e24e9361d 100644 --- a/unixfs/node/hamt/errors.go +++ b/unixfs/node/hamt/errors.go @@ -17,13 +17,13 @@ const ( ErrInvalidChildIndex errorType = "invalid index passed to operate children (likely corrupt bitfield)" // ErrHAMTTooDeep indicates we attempted to load from a HAMT node that went past the depth of the tree ErrHAMTTooDeep errorType = "sharded directory too deep" - // ErrInvalidHashFunc indicates the HAMT node's hash function is unsupported (must be Murmur3) - ErrInvalidHashFunc errorType = "only murmur3 supported as hash function" + // ErrInvalidHashType indicates the HAMT node's hash function is unsupported (must be Murmur3) + ErrInvalidHashType errorType = "only murmur3 supported as hash function" // ErrNoDataField indicates the HAMT node's UnixFS structure lacked a data field, which is // where a bit mask is stored - ErrNoDataField errorType = "Data field not present" + ErrNoDataField errorType = "'Data' field not present" // ErrNoFanoutField indicates the HAMT node's UnixFS structure lacked a fanout field, which is required - ErrNoFanoutField errorType = "Fanout field not present" + ErrNoFanoutField errorType = "'Fanout' field not present" // ErrHAMTSizeInvalid indicates the HAMT's size property was not an exact power of 2 ErrHAMTSizeInvalid errorType = "hamt size should be a power of two" // ErrMissingLinkName indicates a link in a HAMT had no Name property (required for all HAMTs) diff --git a/unixfs/node/hamt/shardeddir.go b/unixfs/node/hamt/shardeddir.go index 865dcfc7f..553baea6e 100644 --- a/unixfs/node/hamt/shardeddir.go +++ b/unixfs/node/hamt/shardeddir.go @@ -37,11 +37,11 @@ type _UnixFSHAMTShard struct { // NewUnixFSHAMTShard attempts to construct a UnixFSHAMTShard node from the base protobuf node plus // a decoded UnixFSData structure func NewUnixFSHAMTShard(ctx context.Context, substrate dagpb.PBNode, data data.UnixFSData, lsys *ipld.LinkSystem) (ipld.Node, error) { - if err := ValidateHAMTData(data); err != nil { + if err := validateHAMTData(data); err != nil { return nil, err } shardCache := make(map[ipld.Link]*_UnixFSHAMTShard, substrate.FieldLinks().Length()) - bf := BitField(data) + bf := bitField(data) return &_UnixFSHAMTShard{ ctx: ctx, _substrate: substrate, @@ -64,8 +64,8 @@ func (n *_UnixFSHAMTShard) LookupByString(key string) (ipld.Node, error) { } func (n UnixFSHAMTShard) lookup(key string, hv *hashBits) (dagpb.Link, error) { - log2 := Log2Size(n.data) - maxPadLength := MaxPadLength(n.data) + log2 := log2Size(n.data) + maxPadLen := maxPadLength(n.data) childIndex, err := hv.Next(log2) if err != nil { return nil, err @@ -76,12 +76,12 @@ func (n UnixFSHAMTShard) lookup(key string, hv *hashBits) (dagpb.Link, error) { if err != nil { return nil, err } - isValue, err := IsValueLink(pbLink, maxPadLength) + isValue, err := isValueLink(pbLink, maxPadLen) if err != nil { return nil, err } if isValue { - if MatchKey(pbLink, key, maxPadLength) { + if MatchKey(pbLink, key, maxPadLen) { return pbLink.FieldHash(), nil } } else { @@ -154,13 +154,13 @@ func (n UnixFSHAMTShard) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error } func (n UnixFSHAMTShard) MapIterator() ipld.MapIterator { - maxpadLen := MaxPadLength(n.data) + maxPadLen := maxPadLength(n.data) listItr := &_UnixFSShardedDir__ListItr{ _substrate: n.FieldLinks().Iterator(), - maxpadlen: maxpadLen, + maxPadLen: maxPadLen, nd: n, } - st := stringTransformer{maxpadLen: maxpadLen} + st := stringTransformer{maxPadLen: maxPadLen} return iter.NewUnixFSDirMapIterator(listItr, st.transformNameNode) } @@ -168,7 +168,7 @@ type _UnixFSShardedDir__ListItr struct { _substrate *dagpb.PBLinks__Itr childIter *_UnixFSShardedDir__ListItr nd UnixFSHAMTShard - maxpadlen int + maxPadLen int total int64 } @@ -189,7 +189,7 @@ func (itr *_UnixFSShardedDir__ListItr) next() dagpb.PBLink { return nil } _, next := itr._substrate.Next() - isValue, err := IsValueLink(next, itr.maxpadlen) + isValue, err := isValueLink(next, itr.maxPadLen) if err != nil { return nil } @@ -203,7 +203,7 @@ func (itr *_UnixFSShardedDir__ListItr) next() dagpb.PBLink { itr.childIter = &_UnixFSShardedDir__ListItr{ _substrate: child._substrate.FieldLinks().Iterator(), nd: child, - maxpadlen: MaxPadLength(child.data), + maxPadLen: maxPadLength(child.data), } } @@ -235,12 +235,12 @@ func (n UnixFSHAMTShard) Length() int64 { if n.cachedLength != -1 { return n.cachedLength } - maxpadLen := MaxPadLength(n.data) + maxPadLen := maxPadLength(n.data) total := int64(0) itr := n.FieldLinks().Iterator() for !itr.Done() { _, pbLink := itr.Next() - isValue, err := IsValueLink(pbLink, maxpadLen) + isValue, err := isValueLink(pbLink, maxPadLen) if err != nil { continue } @@ -308,13 +308,13 @@ func (n UnixFSHAMTShard) Representation() ipld.Node { // Native map accessors func (n UnixFSHAMTShard) Iterator() *iter.UnixFSDir__Itr { - maxpadLen := MaxPadLength(n.data) + maxPadLen := maxPadLength(n.data) listItr := &_UnixFSShardedDir__ListItr{ _substrate: n.FieldLinks().Iterator(), - maxpadlen: maxpadLen, + maxPadLen: maxPadLen, nd: n, } - st := stringTransformer{maxpadLen: maxpadLen} + st := stringTransformer{maxPadLen: maxPadLen} return iter.NewUnixFSDirIterator(listItr, st.transformNameNode) } @@ -350,12 +350,12 @@ func (n UnixFSHAMTShard) hasChild(childIndex int) bool { } type stringTransformer struct { - maxpadLen int + maxPadLen int } func (s stringTransformer) transformNameNode(nd dagpb.String) dagpb.String { nb := dagpb.Type.String.NewBuilder() - err := nb.AssignString(nd.String()[s.maxpadLen:]) + err := nb.AssignString(nd.String()[s.maxPadLen:]) if err != nil { return nil } diff --git a/unixfs/node/hamt/util.go b/unixfs/node/hamt/util.go index d262de49b..7d412fd0e 100644 --- a/unixfs/node/hamt/util.go +++ b/unixfs/node/hamt/util.go @@ -41,28 +41,29 @@ func (hb *hashBits) next(i int) int { out := int(mkmask(i) & curb) hb.consumed += i return out - } else if i < leftb { + } + if i < leftb { a := curb & mkmask(leftb) // mask out the high bits we don't want b := a & ^mkmask(leftb-i) // mask out the low bits we don't want c := b >> uint(leftb-i) // shift whats left down hb.consumed += i return int(c) - } else { - out := int(mkmask(leftb) & curb) - out <<= uint(i - leftb) - hb.consumed += leftb - out += hb.next(i - leftb) - return out } + out := int(mkmask(leftb) & curb) + out <<= uint(i - leftb) + hb.consumed += leftb + out += hb.next(i - leftb) + return out + } -func ValidateHAMTData(nd data.UnixFSData) error { +func validateHAMTData(nd data.UnixFSData) error { if nd.FieldDataType().Int() != data.Data_HAMTShard { return data.ErrWrongNodeType{data.Data_HAMTShard, nd.FieldDataType().Int()} } if !nd.FieldHashType().Exists() || uint64(nd.FieldHashType().Must().Int()) != HashMurmur3 { - return ErrInvalidHashFunc + return ErrInvalidHashType } if !nd.FieldData().Exists() { @@ -79,15 +80,15 @@ func ValidateHAMTData(nd data.UnixFSData) error { return nil } -func Log2Size(nd data.UnixFSData) int { +func log2Size(nd data.UnixFSData) int { return bits.TrailingZeros(uint(nd.FieldFanout().Must().Int())) } -func MaxPadLength(nd data.UnixFSData) int { +func maxPadLength(nd data.UnixFSData) int { return len(fmt.Sprintf("%X", nd.FieldFanout().Must().Int()-1)) } -func BitField(nd data.UnixFSData) bitfield.Bitfield { +func bitField(nd data.UnixFSData) bitfield.Bitfield { bf := bitfield.NewBitfield(int(nd.FieldFanout().Must().Int())) bf.SetBytes(nd.FieldData().Must().Bytes()) return bf @@ -110,20 +111,20 @@ func hash(val []byte) []byte { return h.Sum(nil) } -func IsValueLink(pbLink dagpb.PBLink, maxpadlen int) (bool, error) { +func isValueLink(pbLink dagpb.PBLink, maxPadLen int) (bool, error) { if !pbLink.FieldName().Exists() { return false, ErrMissingLinkName } name := pbLink.FieldName().Must().String() - if len(name) < maxpadlen { + if len(name) < maxPadLen { return false, ErrInvalidLinkName{name} } - if len(name) == maxpadlen { + if len(name) == maxPadLen { return false, nil } return true, nil } -func MatchKey(pbLink dagpb.PBLink, key string, maxpadlen int) bool { - return pbLink.FieldName().Must().String()[maxpadlen:] == key +func MatchKey(pbLink dagpb.PBLink, key string, maxPadLen int) bool { + return pbLink.FieldName().Must().String()[maxPadLen:] == key } diff --git a/unixfs/node/reification.go b/unixfs/node/reification.go index 9666dfc26..aef0e58eb 100644 --- a/unixfs/node/reification.go +++ b/unixfs/node/reification.go @@ -29,7 +29,7 @@ func Reify(lnkCtx ipld.LinkContext, maybePBNodeRoot ipld.Node, lsys *ipld.LinkSy } builder, ok := reifyFuncs[data.FieldDataType().Int()] if !ok { - return nil, fmt.Errorf("No reification for this UnixFS node type") + return nil, fmt.Errorf("no reification for this UnixFS node type") } return builder(lnkCtx.Ctx, pbNode, data, lsys) } From 50aff336c4e97b32b014d85eba39fa7b3e77e39c Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Mon, 5 Apr 2021 12:27:26 -0700 Subject: [PATCH 10/43] feat(reifier): don't error on missing reification for now This commit was moved from ipfs/go-unixfsnode@37e399dc322e45938f5e99f1fdd1b660144d9a9c --- unixfs/node/reification.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/unixfs/node/reification.go b/unixfs/node/reification.go index aef0e58eb..9a0244c44 100644 --- a/unixfs/node/reification.go +++ b/unixfs/node/reification.go @@ -37,6 +37,10 @@ func Reify(lnkCtx ipld.LinkContext, maybePBNodeRoot ipld.Node, lsys *ipld.LinkSy type reifyTypeFunc func(context.Context, dagpb.PBNode, data.UnixFSData, *ipld.LinkSystem) (ipld.Node, error) var reifyFuncs = map[int64]reifyTypeFunc{ + data.Data_File: defaultUnixFSReifier, + data.Data_Metadata: defaultUnixFSReifier, + data.Data_Raw: defaultUnixFSReifier, + data.Data_Symlink: defaultUnixFSReifier, data.Data_Directory: directory.NewUnixFSBasicDir, data.Data_HAMTShard: hamt.NewUnixFSHAMTShard, } @@ -47,4 +51,8 @@ func defaultReifier(_ context.Context, substrate dagpb.PBNode, _ *ipld.LinkSyste return &_PathedPBNode{_substrate: substrate}, nil } +func defaultUnixFSReifier(ctx context.Context, substrate dagpb.PBNode, _ data.UnixFSData, ls *ipld.LinkSystem) (ipld.Node, error) { + return defaultReifier(ctx, substrate, ls) +} + var _ ipld.NodeReifier = Reify From 84c68c49aeab493d85c5bc77458f9d3b871acf8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 19 Jun 2021 10:33:41 +0100 Subject: [PATCH 11/43] data: update ipld-prime version to fix codegen issues The generated code now passes vet and fmt. Three vet warnings remain, but outside generated code. This commit was moved from ipfs/go-unixfsnode@db2fdc853fc9b09bfe7d9115cffd7e3936066f8b --- unixfs/node/data/ipldsch_minima.go | 25 +- unixfs/node/data/ipldsch_satisfaction.go | 1199 +++++++++++----------- unixfs/node/data/ipldsch_types.go | 42 +- 3 files changed, 661 insertions(+), 605 deletions(-) diff --git a/unixfs/node/data/ipldsch_minima.go b/unixfs/node/data/ipldsch_minima.go index 64b5433c5..30cc512ab 100644 --- a/unixfs/node/data/ipldsch_minima.go +++ b/unixfs/node/data/ipldsch_minima.go @@ -10,14 +10,14 @@ import ( ) const ( - midvalue = schema.Maybe(4) + midvalue = schema.Maybe(4) allowNull = schema.Maybe(5) ) type maState uint8 const ( - maState_initial maState = iota + maState_initial maState = iota maState_midKey maState_expectValue maState_midValue @@ -27,24 +27,25 @@ const ( type laState uint8 const ( - laState_initial laState = iota + laState_initial laState = iota laState_midValue laState_finished ) + type _ErrorThunkAssembler struct { e error } -func (ea _ErrorThunkAssembler) BeginMap(_ int64) (ipld.MapAssembler, error) { return nil, ea.e } +func (ea _ErrorThunkAssembler) BeginMap(_ int64) (ipld.MapAssembler, error) { return nil, ea.e } func (ea _ErrorThunkAssembler) BeginList(_ int64) (ipld.ListAssembler, error) { return nil, ea.e } -func (ea _ErrorThunkAssembler) AssignNull() error { return ea.e } -func (ea _ErrorThunkAssembler) AssignBool(bool) error { return ea.e } -func (ea _ErrorThunkAssembler) AssignInt(int64) error { return ea.e } -func (ea _ErrorThunkAssembler) AssignFloat(float64) error { return ea.e } -func (ea _ErrorThunkAssembler) AssignString(string) error { return ea.e } -func (ea _ErrorThunkAssembler) AssignBytes([]byte) error { return ea.e } -func (ea _ErrorThunkAssembler) AssignLink(ipld.Link) error { return ea.e } -func (ea _ErrorThunkAssembler) AssignNode(ipld.Node) error { return ea.e } +func (ea _ErrorThunkAssembler) AssignNull() error { return ea.e } +func (ea _ErrorThunkAssembler) AssignBool(bool) error { return ea.e } +func (ea _ErrorThunkAssembler) AssignInt(int64) error { return ea.e } +func (ea _ErrorThunkAssembler) AssignFloat(float64) error { return ea.e } +func (ea _ErrorThunkAssembler) AssignString(string) error { return ea.e } +func (ea _ErrorThunkAssembler) AssignBytes([]byte) error { return ea.e } +func (ea _ErrorThunkAssembler) AssignLink(ipld.Link) error { return ea.e } +func (ea _ErrorThunkAssembler) AssignNode(ipld.Node) error { return ea.e } func (ea _ErrorThunkAssembler) Prototype() ipld.NodePrototype { panic(fmt.Errorf("cannot get prototype from error-carrying assembler: already derailed with error: %w", ea.e)) } diff --git a/unixfs/node/data/ipldsch_satisfaction.go b/unixfs/node/data/ipldsch_satisfaction.go index f12024f52..296b87a57 100644 --- a/unixfs/node/data/ipldsch_satisfaction.go +++ b/unixfs/node/data/ipldsch_satisfaction.go @@ -22,18 +22,19 @@ func (n *_BlockSizes) LookupMaybe(idx int64) MaybeInt { v := &n.x[idx] return &_Int__Maybe{ m: schema.Maybe_Value, - v: v, + v: *v, } } -var _BlockSizes__valueAbsent = _Int__Maybe{m:schema.Maybe_Absent} +var _BlockSizes__valueAbsent = _Int__Maybe{m: schema.Maybe_Absent} + func (n BlockSizes) Iterator() *BlockSizes__Itr { return &BlockSizes__Itr{n, 0} } type BlockSizes__Itr struct { - n BlockSizes - idx int + n BlockSizes + idx int } func (itr *BlockSizes__Itr) Next() (idx int64, v Int) { @@ -51,7 +52,7 @@ func (itr *BlockSizes__Itr) Done() bool { type _BlockSizes__Maybe struct { m schema.Maybe - v BlockSizes + v _BlockSizes } type MaybeBlockSizes = *_BlockSizes__Maybe @@ -66,29 +67,31 @@ func (m MaybeBlockSizes) Exists() bool { } func (m MaybeBlockSizes) AsNode() ipld.Node { switch m.m { - case schema.Maybe_Absent: - return ipld.Absent - case schema.Maybe_Null: - return ipld.Null - case schema.Maybe_Value: - return m.v - default: - panic("unreachable") + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return &m.v + default: + panic("unreachable") } } func (m MaybeBlockSizes) Must() BlockSizes { if !m.Exists() { panic("unbox of a maybe rejected") } - return m.v + return &m.v } + var _ ipld.Node = (BlockSizes)(&_BlockSizes{}) var _ schema.TypedNode = (BlockSizes)(&_BlockSizes{}) + func (BlockSizes) Kind() ipld.Kind { return ipld.Kind_List } func (BlockSizes) LookupByString(string) (ipld.Node, error) { - return mixins.List{"data.BlockSizes"}.LookupByString("") + return mixins.List{TypeName: "data.BlockSizes"}.LookupByString("") } func (n BlockSizes) LookupByNode(k ipld.Node) (ipld.Node, error) { idx, err := k.AsInt() @@ -119,8 +122,8 @@ func (n BlockSizes) ListIterator() ipld.ListIterator { } type _BlockSizes__ListItr struct { - n BlockSizes - idx int + n BlockSizes + idx int } func (itr *_BlockSizes__ListItr) Next() (idx int64, v ipld.Node, _ error) { @@ -147,26 +150,27 @@ func (BlockSizes) IsNull() bool { return false } func (BlockSizes) AsBool() (bool, error) { - return mixins.List{"data.BlockSizes"}.AsBool() + return mixins.List{TypeName: "data.BlockSizes"}.AsBool() } func (BlockSizes) AsInt() (int64, error) { - return mixins.List{"data.BlockSizes"}.AsInt() + return mixins.List{TypeName: "data.BlockSizes"}.AsInt() } func (BlockSizes) AsFloat() (float64, error) { - return mixins.List{"data.BlockSizes"}.AsFloat() + return mixins.List{TypeName: "data.BlockSizes"}.AsFloat() } func (BlockSizes) AsString() (string, error) { - return mixins.List{"data.BlockSizes"}.AsString() + return mixins.List{TypeName: "data.BlockSizes"}.AsString() } func (BlockSizes) AsBytes() ([]byte, error) { - return mixins.List{"data.BlockSizes"}.AsBytes() + return mixins.List{TypeName: "data.BlockSizes"}.AsBytes() } func (BlockSizes) AsLink() (ipld.Link, error) { - return mixins.List{"data.BlockSizes"}.AsLink() + return mixins.List{TypeName: "data.BlockSizes"}.AsLink() } func (BlockSizes) Prototype() ipld.NodePrototype { return _BlockSizes__Prototype{} } + type _BlockSizes__Prototype struct{} func (_BlockSizes__Prototype) NewBuilder() ipld.NodeBuilder { @@ -174,9 +178,11 @@ func (_BlockSizes__Prototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } + type _BlockSizes__Builder struct { _BlockSizes__Assembler } + func (nb *_BlockSizes__Builder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -188,9 +194,10 @@ func (nb *_BlockSizes__Builder) Reset() { var m schema.Maybe *nb = _BlockSizes__Builder{_BlockSizes__Assembler{w: &w, m: &m}} } + type _BlockSizes__Assembler struct { - w *_BlockSizes - m *schema.Maybe + w *_BlockSizes + m *schema.Maybe state laState cm schema.Maybe @@ -202,7 +209,7 @@ func (na *_BlockSizes__Assembler) reset() { na.va.reset() } func (_BlockSizes__Assembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { - return mixins.ListAssembler{"data.BlockSizes"}.BeginMap(0) + return mixins.ListAssembler{TypeName: "data.BlockSizes"}.BeginMap(0) } func (na *_BlockSizes__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { switch *na.m { @@ -215,9 +222,6 @@ func (na *_BlockSizes__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, if sizeHint < 0 { sizeHint = 0 } - if na.w == nil { - na.w = &_BlockSizes{} - } if sizeHint > 0 { na.w.x = make([]_Int, 0, sizeHint) } @@ -229,7 +233,7 @@ func (na *_BlockSizes__Assembler) AssignNull() error { *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.ListAssembler{"data.BlockSizes"}.AssignNull() + return mixins.ListAssembler{TypeName: "data.BlockSizes"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -238,22 +242,22 @@ func (na *_BlockSizes__Assembler) AssignNull() error { panic("unreachable") } func (_BlockSizes__Assembler) AssignBool(bool) error { - return mixins.ListAssembler{"data.BlockSizes"}.AssignBool(false) + return mixins.ListAssembler{TypeName: "data.BlockSizes"}.AssignBool(false) } func (_BlockSizes__Assembler) AssignInt(int64) error { - return mixins.ListAssembler{"data.BlockSizes"}.AssignInt(0) + return mixins.ListAssembler{TypeName: "data.BlockSizes"}.AssignInt(0) } func (_BlockSizes__Assembler) AssignFloat(float64) error { - return mixins.ListAssembler{"data.BlockSizes"}.AssignFloat(0) + return mixins.ListAssembler{TypeName: "data.BlockSizes"}.AssignFloat(0) } func (_BlockSizes__Assembler) AssignString(string) error { - return mixins.ListAssembler{"data.BlockSizes"}.AssignString("") + return mixins.ListAssembler{TypeName: "data.BlockSizes"}.AssignString("") } func (_BlockSizes__Assembler) AssignBytes([]byte) error { - return mixins.ListAssembler{"data.BlockSizes"}.AssignBytes(nil) + return mixins.ListAssembler{TypeName: "data.BlockSizes"}.AssignBytes(nil) } func (_BlockSizes__Assembler) AssignLink(ipld.Link) error { - return mixins.ListAssembler{"data.BlockSizes"}.AssignLink(nil) + return mixins.ListAssembler{TypeName: "data.BlockSizes"}.AssignLink(nil) } func (na *_BlockSizes__Assembler) AssignNode(v ipld.Node) error { if v.IsNull() { @@ -266,11 +270,6 @@ func (na *_BlockSizes__Assembler) AssignNode(v ipld.Node) error { case midvalue: panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") } - if na.w == nil { - na.w = v2 - *na.m = schema.Maybe_Value - return nil - } *na.w = *v2 *na.m = schema.Maybe_Value return nil @@ -347,13 +346,16 @@ func (BlockSizes) Type() schema.Type { func (n BlockSizes) Representation() ipld.Node { return (*_BlockSizes__Repr)(n) } + type _BlockSizes__Repr _BlockSizes + var _ ipld.Node = &_BlockSizes__Repr{} + func (_BlockSizes__Repr) Kind() ipld.Kind { return ipld.Kind_List } func (_BlockSizes__Repr) LookupByString(string) (ipld.Node, error) { - return mixins.List{"data.BlockSizes.Repr"}.LookupByString("") + return mixins.List{TypeName: "data.BlockSizes.Repr"}.LookupByString("") } func (nr *_BlockSizes__Repr) LookupByNode(k ipld.Node) (ipld.Node, error) { v, err := (BlockSizes)(nr).LookupByNode(k) @@ -406,26 +408,27 @@ func (_BlockSizes__Repr) IsNull() bool { return false } func (_BlockSizes__Repr) AsBool() (bool, error) { - return mixins.List{"data.BlockSizes.Repr"}.AsBool() + return mixins.List{TypeName: "data.BlockSizes.Repr"}.AsBool() } func (_BlockSizes__Repr) AsInt() (int64, error) { - return mixins.List{"data.BlockSizes.Repr"}.AsInt() + return mixins.List{TypeName: "data.BlockSizes.Repr"}.AsInt() } func (_BlockSizes__Repr) AsFloat() (float64, error) { - return mixins.List{"data.BlockSizes.Repr"}.AsFloat() + return mixins.List{TypeName: "data.BlockSizes.Repr"}.AsFloat() } func (_BlockSizes__Repr) AsString() (string, error) { - return mixins.List{"data.BlockSizes.Repr"}.AsString() + return mixins.List{TypeName: "data.BlockSizes.Repr"}.AsString() } func (_BlockSizes__Repr) AsBytes() ([]byte, error) { - return mixins.List{"data.BlockSizes.Repr"}.AsBytes() + return mixins.List{TypeName: "data.BlockSizes.Repr"}.AsBytes() } func (_BlockSizes__Repr) AsLink() (ipld.Link, error) { - return mixins.List{"data.BlockSizes.Repr"}.AsLink() + return mixins.List{TypeName: "data.BlockSizes.Repr"}.AsLink() } func (_BlockSizes__Repr) Prototype() ipld.NodePrototype { return _BlockSizes__ReprPrototype{} } + type _BlockSizes__ReprPrototype struct{} func (_BlockSizes__ReprPrototype) NewBuilder() ipld.NodeBuilder { @@ -433,9 +436,11 @@ func (_BlockSizes__ReprPrototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } + type _BlockSizes__ReprBuilder struct { _BlockSizes__ReprAssembler } + func (nb *_BlockSizes__ReprBuilder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -447,9 +452,10 @@ func (nb *_BlockSizes__ReprBuilder) Reset() { var m schema.Maybe *nb = _BlockSizes__ReprBuilder{_BlockSizes__ReprAssembler{w: &w, m: &m}} } + type _BlockSizes__ReprAssembler struct { - w *_BlockSizes - m *schema.Maybe + w *_BlockSizes + m *schema.Maybe state laState cm schema.Maybe @@ -461,7 +467,7 @@ func (na *_BlockSizes__ReprAssembler) reset() { na.va.reset() } func (_BlockSizes__ReprAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { - return mixins.ListAssembler{"data.BlockSizes.Repr"}.BeginMap(0) + return mixins.ListAssembler{TypeName: "data.BlockSizes.Repr"}.BeginMap(0) } func (na *_BlockSizes__ReprAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { switch *na.m { @@ -474,9 +480,6 @@ func (na *_BlockSizes__ReprAssembler) BeginList(sizeHint int64) (ipld.ListAssemb if sizeHint < 0 { sizeHint = 0 } - if na.w == nil { - na.w = &_BlockSizes{} - } if sizeHint > 0 { na.w.x = make([]_Int, 0, sizeHint) } @@ -488,7 +491,7 @@ func (na *_BlockSizes__ReprAssembler) AssignNull() error { *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.ListAssembler{"data.BlockSizes.Repr.Repr"}.AssignNull() + return mixins.ListAssembler{TypeName: "data.BlockSizes.Repr.Repr"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -497,22 +500,22 @@ func (na *_BlockSizes__ReprAssembler) AssignNull() error { panic("unreachable") } func (_BlockSizes__ReprAssembler) AssignBool(bool) error { - return mixins.ListAssembler{"data.BlockSizes.Repr"}.AssignBool(false) + return mixins.ListAssembler{TypeName: "data.BlockSizes.Repr"}.AssignBool(false) } func (_BlockSizes__ReprAssembler) AssignInt(int64) error { - return mixins.ListAssembler{"data.BlockSizes.Repr"}.AssignInt(0) + return mixins.ListAssembler{TypeName: "data.BlockSizes.Repr"}.AssignInt(0) } func (_BlockSizes__ReprAssembler) AssignFloat(float64) error { - return mixins.ListAssembler{"data.BlockSizes.Repr"}.AssignFloat(0) + return mixins.ListAssembler{TypeName: "data.BlockSizes.Repr"}.AssignFloat(0) } func (_BlockSizes__ReprAssembler) AssignString(string) error { - return mixins.ListAssembler{"data.BlockSizes.Repr"}.AssignString("") + return mixins.ListAssembler{TypeName: "data.BlockSizes.Repr"}.AssignString("") } func (_BlockSizes__ReprAssembler) AssignBytes([]byte) error { - return mixins.ListAssembler{"data.BlockSizes.Repr"}.AssignBytes(nil) + return mixins.ListAssembler{TypeName: "data.BlockSizes.Repr"}.AssignBytes(nil) } func (_BlockSizes__ReprAssembler) AssignLink(ipld.Link) error { - return mixins.ListAssembler{"data.BlockSizes.Repr"}.AssignLink(nil) + return mixins.ListAssembler{TypeName: "data.BlockSizes.Repr"}.AssignLink(nil) } func (na *_BlockSizes__ReprAssembler) AssignNode(v ipld.Node) error { if v.IsNull() { @@ -525,11 +528,6 @@ func (na *_BlockSizes__ReprAssembler) AssignNode(v ipld.Node) error { case midvalue: panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") } - if na.w == nil { - na.w = v2 - *na.m = schema.Maybe_Value - return nil - } *na.w = *v2 *na.m = schema.Maybe_Value return nil @@ -608,9 +606,10 @@ func (_Bytes__Prototype) FromBytes(v []byte) (Bytes, error) { n := _Bytes{v} return &n, nil } + type _Bytes__Maybe struct { m schema.Maybe - v Bytes + v _Bytes } type MaybeBytes = *_Bytes__Maybe @@ -625,38 +624,40 @@ func (m MaybeBytes) Exists() bool { } func (m MaybeBytes) AsNode() ipld.Node { switch m.m { - case schema.Maybe_Absent: - return ipld.Absent - case schema.Maybe_Null: - return ipld.Null - case schema.Maybe_Value: - return m.v - default: - panic("unreachable") + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return &m.v + default: + panic("unreachable") } } func (m MaybeBytes) Must() Bytes { if !m.Exists() { panic("unbox of a maybe rejected") } - return m.v + return &m.v } + var _ ipld.Node = (Bytes)(&_Bytes{}) var _ schema.TypedNode = (Bytes)(&_Bytes{}) + func (Bytes) Kind() ipld.Kind { return ipld.Kind_Bytes } func (Bytes) LookupByString(string) (ipld.Node, error) { - return mixins.Bytes{"data.Bytes"}.LookupByString("") + return mixins.Bytes{TypeName: "data.Bytes"}.LookupByString("") } func (Bytes) LookupByNode(ipld.Node) (ipld.Node, error) { - return mixins.Bytes{"data.Bytes"}.LookupByNode(nil) + return mixins.Bytes{TypeName: "data.Bytes"}.LookupByNode(nil) } func (Bytes) LookupByIndex(idx int64) (ipld.Node, error) { - return mixins.Bytes{"data.Bytes"}.LookupByIndex(0) + return mixins.Bytes{TypeName: "data.Bytes"}.LookupByIndex(0) } func (Bytes) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { - return mixins.Bytes{"data.Bytes"}.LookupBySegment(seg) + return mixins.Bytes{TypeName: "data.Bytes"}.LookupBySegment(seg) } func (Bytes) MapIterator() ipld.MapIterator { return nil @@ -674,26 +675,27 @@ func (Bytes) IsNull() bool { return false } func (Bytes) AsBool() (bool, error) { - return mixins.Bytes{"data.Bytes"}.AsBool() + return mixins.Bytes{TypeName: "data.Bytes"}.AsBool() } func (Bytes) AsInt() (int64, error) { - return mixins.Bytes{"data.Bytes"}.AsInt() + return mixins.Bytes{TypeName: "data.Bytes"}.AsInt() } func (Bytes) AsFloat() (float64, error) { - return mixins.Bytes{"data.Bytes"}.AsFloat() + return mixins.Bytes{TypeName: "data.Bytes"}.AsFloat() } func (Bytes) AsString() (string, error) { - return mixins.Bytes{"data.Bytes"}.AsString() + return mixins.Bytes{TypeName: "data.Bytes"}.AsString() } func (n Bytes) AsBytes() ([]byte, error) { return n.x, nil } func (Bytes) AsLink() (ipld.Link, error) { - return mixins.Bytes{"data.Bytes"}.AsLink() + return mixins.Bytes{TypeName: "data.Bytes"}.AsLink() } func (Bytes) Prototype() ipld.NodePrototype { return _Bytes__Prototype{} } + type _Bytes__Prototype struct{} func (_Bytes__Prototype) NewBuilder() ipld.NodeBuilder { @@ -701,9 +703,11 @@ func (_Bytes__Prototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } + type _Bytes__Builder struct { _Bytes__Assembler } + func (nb *_Bytes__Builder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -715,6 +719,7 @@ func (nb *_Bytes__Builder) Reset() { var m schema.Maybe *nb = _Bytes__Builder{_Bytes__Assembler{w: &w, m: &m}} } + type _Bytes__Assembler struct { w *_Bytes m *schema.Maybe @@ -722,10 +727,10 @@ type _Bytes__Assembler struct { func (na *_Bytes__Assembler) reset() {} func (_Bytes__Assembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { - return mixins.BytesAssembler{"data.Bytes"}.BeginMap(0) + return mixins.BytesAssembler{TypeName: "data.Bytes"}.BeginMap(0) } func (_Bytes__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.BytesAssembler{"data.Bytes"}.BeginList(0) + return mixins.BytesAssembler{TypeName: "data.Bytes"}.BeginList(0) } func (na *_Bytes__Assembler) AssignNull() error { switch *na.m { @@ -733,38 +738,35 @@ func (na *_Bytes__Assembler) AssignNull() error { *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.BytesAssembler{"data.Bytes"}.AssignNull() + return mixins.BytesAssembler{TypeName: "data.Bytes"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") } panic("unreachable") } func (_Bytes__Assembler) AssignBool(bool) error { - return mixins.BytesAssembler{"data.Bytes"}.AssignBool(false) + return mixins.BytesAssembler{TypeName: "data.Bytes"}.AssignBool(false) } func (_Bytes__Assembler) AssignInt(int64) error { - return mixins.BytesAssembler{"data.Bytes"}.AssignInt(0) + return mixins.BytesAssembler{TypeName: "data.Bytes"}.AssignInt(0) } func (_Bytes__Assembler) AssignFloat(float64) error { - return mixins.BytesAssembler{"data.Bytes"}.AssignFloat(0) + return mixins.BytesAssembler{TypeName: "data.Bytes"}.AssignFloat(0) } func (_Bytes__Assembler) AssignString(string) error { - return mixins.BytesAssembler{"data.Bytes"}.AssignString("") + return mixins.BytesAssembler{TypeName: "data.Bytes"}.AssignString("") } func (na *_Bytes__Assembler) AssignBytes(v []byte) error { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") } - if na.w == nil { - na.w = &_Bytes{} - } na.w.x = v *na.m = schema.Maybe_Value return nil } func (_Bytes__Assembler) AssignLink(ipld.Link) error { - return mixins.BytesAssembler{"data.Bytes"}.AssignLink(nil) + return mixins.BytesAssembler{TypeName: "data.Bytes"}.AssignLink(nil) } func (na *_Bytes__Assembler) AssignNode(v ipld.Node) error { if v.IsNull() { @@ -775,11 +777,6 @@ func (na *_Bytes__Assembler) AssignNode(v ipld.Node) error { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") } - if na.w == nil { - na.w = v2 - *na.m = schema.Maybe_Value - return nil - } *na.w = *v2 *na.m = schema.Maybe_Value return nil @@ -799,8 +796,11 @@ func (Bytes) Type() schema.Type { func (n Bytes) Representation() ipld.Node { return (*_Bytes__Repr)(n) } + type _Bytes__Repr = _Bytes + var _ ipld.Node = &_Bytes__Repr{} + type _Bytes__ReprPrototype = _Bytes__Prototype type _Bytes__ReprAssembler = _Bytes__Assembler @@ -811,9 +811,10 @@ func (_Int__Prototype) FromInt(v int64) (Int, error) { n := _Int{v} return &n, nil } + type _Int__Maybe struct { m schema.Maybe - v Int + v _Int } type MaybeInt = *_Int__Maybe @@ -828,38 +829,40 @@ func (m MaybeInt) Exists() bool { } func (m MaybeInt) AsNode() ipld.Node { switch m.m { - case schema.Maybe_Absent: - return ipld.Absent - case schema.Maybe_Null: - return ipld.Null - case schema.Maybe_Value: - return m.v - default: - panic("unreachable") + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return &m.v + default: + panic("unreachable") } } func (m MaybeInt) Must() Int { if !m.Exists() { panic("unbox of a maybe rejected") } - return m.v + return &m.v } + var _ ipld.Node = (Int)(&_Int{}) var _ schema.TypedNode = (Int)(&_Int{}) + func (Int) Kind() ipld.Kind { return ipld.Kind_Int } func (Int) LookupByString(string) (ipld.Node, error) { - return mixins.Int{"data.Int"}.LookupByString("") + return mixins.Int{TypeName: "data.Int"}.LookupByString("") } func (Int) LookupByNode(ipld.Node) (ipld.Node, error) { - return mixins.Int{"data.Int"}.LookupByNode(nil) + return mixins.Int{TypeName: "data.Int"}.LookupByNode(nil) } func (Int) LookupByIndex(idx int64) (ipld.Node, error) { - return mixins.Int{"data.Int"}.LookupByIndex(0) + return mixins.Int{TypeName: "data.Int"}.LookupByIndex(0) } func (Int) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { - return mixins.Int{"data.Int"}.LookupBySegment(seg) + return mixins.Int{TypeName: "data.Int"}.LookupBySegment(seg) } func (Int) MapIterator() ipld.MapIterator { return nil @@ -877,26 +880,27 @@ func (Int) IsNull() bool { return false } func (Int) AsBool() (bool, error) { - return mixins.Int{"data.Int"}.AsBool() + return mixins.Int{TypeName: "data.Int"}.AsBool() } func (n Int) AsInt() (int64, error) { return n.x, nil } func (Int) AsFloat() (float64, error) { - return mixins.Int{"data.Int"}.AsFloat() + return mixins.Int{TypeName: "data.Int"}.AsFloat() } func (Int) AsString() (string, error) { - return mixins.Int{"data.Int"}.AsString() + return mixins.Int{TypeName: "data.Int"}.AsString() } func (Int) AsBytes() ([]byte, error) { - return mixins.Int{"data.Int"}.AsBytes() + return mixins.Int{TypeName: "data.Int"}.AsBytes() } func (Int) AsLink() (ipld.Link, error) { - return mixins.Int{"data.Int"}.AsLink() + return mixins.Int{TypeName: "data.Int"}.AsLink() } func (Int) Prototype() ipld.NodePrototype { return _Int__Prototype{} } + type _Int__Prototype struct{} func (_Int__Prototype) NewBuilder() ipld.NodeBuilder { @@ -904,9 +908,11 @@ func (_Int__Prototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } + type _Int__Builder struct { _Int__Assembler } + func (nb *_Int__Builder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -918,6 +924,7 @@ func (nb *_Int__Builder) Reset() { var m schema.Maybe *nb = _Int__Builder{_Int__Assembler{w: &w, m: &m}} } + type _Int__Assembler struct { w *_Int m *schema.Maybe @@ -925,10 +932,10 @@ type _Int__Assembler struct { func (na *_Int__Assembler) reset() {} func (_Int__Assembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { - return mixins.IntAssembler{"data.Int"}.BeginMap(0) + return mixins.IntAssembler{TypeName: "data.Int"}.BeginMap(0) } func (_Int__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.IntAssembler{"data.Int"}.BeginList(0) + return mixins.IntAssembler{TypeName: "data.Int"}.BeginList(0) } func (na *_Int__Assembler) AssignNull() error { switch *na.m { @@ -936,38 +943,35 @@ func (na *_Int__Assembler) AssignNull() error { *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.IntAssembler{"data.Int"}.AssignNull() + return mixins.IntAssembler{TypeName: "data.Int"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") } panic("unreachable") } func (_Int__Assembler) AssignBool(bool) error { - return mixins.IntAssembler{"data.Int"}.AssignBool(false) + return mixins.IntAssembler{TypeName: "data.Int"}.AssignBool(false) } func (na *_Int__Assembler) AssignInt(v int64) error { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") } - if na.w == nil { - na.w = &_Int{} - } na.w.x = v *na.m = schema.Maybe_Value return nil } func (_Int__Assembler) AssignFloat(float64) error { - return mixins.IntAssembler{"data.Int"}.AssignFloat(0) + return mixins.IntAssembler{TypeName: "data.Int"}.AssignFloat(0) } func (_Int__Assembler) AssignString(string) error { - return mixins.IntAssembler{"data.Int"}.AssignString("") + return mixins.IntAssembler{TypeName: "data.Int"}.AssignString("") } func (_Int__Assembler) AssignBytes([]byte) error { - return mixins.IntAssembler{"data.Int"}.AssignBytes(nil) + return mixins.IntAssembler{TypeName: "data.Int"}.AssignBytes(nil) } func (_Int__Assembler) AssignLink(ipld.Link) error { - return mixins.IntAssembler{"data.Int"}.AssignLink(nil) + return mixins.IntAssembler{TypeName: "data.Int"}.AssignLink(nil) } func (na *_Int__Assembler) AssignNode(v ipld.Node) error { if v.IsNull() { @@ -978,11 +982,6 @@ func (na *_Int__Assembler) AssignNode(v ipld.Node) error { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") } - if na.w == nil { - na.w = v2 - *na.m = schema.Maybe_Value - return nil - } *na.w = *v2 *na.m = schema.Maybe_Value return nil @@ -1002,8 +1001,11 @@ func (Int) Type() schema.Type { func (n Int) Representation() ipld.Node { return (*_Int__Repr)(n) } + type _Int__Repr = _Int + var _ ipld.Node = &_Int__Repr{} + type _Int__ReprPrototype = _Int__Prototype type _Int__ReprAssembler = _Int__Assembler @@ -1018,9 +1020,10 @@ func (_String__Prototype) FromString(v string) (String, error) { n := _String{v} return &n, nil } + type _String__Maybe struct { m schema.Maybe - v String + v _String } type MaybeString = *_String__Maybe @@ -1035,38 +1038,40 @@ func (m MaybeString) Exists() bool { } func (m MaybeString) AsNode() ipld.Node { switch m.m { - case schema.Maybe_Absent: - return ipld.Absent - case schema.Maybe_Null: - return ipld.Null - case schema.Maybe_Value: - return m.v - default: - panic("unreachable") + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return &m.v + default: + panic("unreachable") } } func (m MaybeString) Must() String { if !m.Exists() { panic("unbox of a maybe rejected") } - return m.v + return &m.v } + var _ ipld.Node = (String)(&_String{}) var _ schema.TypedNode = (String)(&_String{}) + func (String) Kind() ipld.Kind { return ipld.Kind_String } func (String) LookupByString(string) (ipld.Node, error) { - return mixins.String{"data.String"}.LookupByString("") + return mixins.String{TypeName: "data.String"}.LookupByString("") } func (String) LookupByNode(ipld.Node) (ipld.Node, error) { - return mixins.String{"data.String"}.LookupByNode(nil) + return mixins.String{TypeName: "data.String"}.LookupByNode(nil) } func (String) LookupByIndex(idx int64) (ipld.Node, error) { - return mixins.String{"data.String"}.LookupByIndex(0) + return mixins.String{TypeName: "data.String"}.LookupByIndex(0) } func (String) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { - return mixins.String{"data.String"}.LookupBySegment(seg) + return mixins.String{TypeName: "data.String"}.LookupBySegment(seg) } func (String) MapIterator() ipld.MapIterator { return nil @@ -1084,26 +1089,27 @@ func (String) IsNull() bool { return false } func (String) AsBool() (bool, error) { - return mixins.String{"data.String"}.AsBool() + return mixins.String{TypeName: "data.String"}.AsBool() } func (String) AsInt() (int64, error) { - return mixins.String{"data.String"}.AsInt() + return mixins.String{TypeName: "data.String"}.AsInt() } func (String) AsFloat() (float64, error) { - return mixins.String{"data.String"}.AsFloat() + return mixins.String{TypeName: "data.String"}.AsFloat() } func (n String) AsString() (string, error) { return n.x, nil } func (String) AsBytes() ([]byte, error) { - return mixins.String{"data.String"}.AsBytes() + return mixins.String{TypeName: "data.String"}.AsBytes() } func (String) AsLink() (ipld.Link, error) { - return mixins.String{"data.String"}.AsLink() + return mixins.String{TypeName: "data.String"}.AsLink() } func (String) Prototype() ipld.NodePrototype { return _String__Prototype{} } + type _String__Prototype struct{} func (_String__Prototype) NewBuilder() ipld.NodeBuilder { @@ -1111,9 +1117,11 @@ func (_String__Prototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } + type _String__Builder struct { _String__Assembler } + func (nb *_String__Builder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -1125,6 +1133,7 @@ func (nb *_String__Builder) Reset() { var m schema.Maybe *nb = _String__Builder{_String__Assembler{w: &w, m: &m}} } + type _String__Assembler struct { w *_String m *schema.Maybe @@ -1132,10 +1141,10 @@ type _String__Assembler struct { func (na *_String__Assembler) reset() {} func (_String__Assembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { - return mixins.StringAssembler{"data.String"}.BeginMap(0) + return mixins.StringAssembler{TypeName: "data.String"}.BeginMap(0) } func (_String__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.StringAssembler{"data.String"}.BeginList(0) + return mixins.StringAssembler{TypeName: "data.String"}.BeginList(0) } func (na *_String__Assembler) AssignNull() error { switch *na.m { @@ -1143,38 +1152,35 @@ func (na *_String__Assembler) AssignNull() error { *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.StringAssembler{"data.String"}.AssignNull() + return mixins.StringAssembler{TypeName: "data.String"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") } panic("unreachable") } func (_String__Assembler) AssignBool(bool) error { - return mixins.StringAssembler{"data.String"}.AssignBool(false) + return mixins.StringAssembler{TypeName: "data.String"}.AssignBool(false) } func (_String__Assembler) AssignInt(int64) error { - return mixins.StringAssembler{"data.String"}.AssignInt(0) + return mixins.StringAssembler{TypeName: "data.String"}.AssignInt(0) } func (_String__Assembler) AssignFloat(float64) error { - return mixins.StringAssembler{"data.String"}.AssignFloat(0) + return mixins.StringAssembler{TypeName: "data.String"}.AssignFloat(0) } func (na *_String__Assembler) AssignString(v string) error { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") } - if na.w == nil { - na.w = &_String{} - } na.w.x = v *na.m = schema.Maybe_Value return nil } func (_String__Assembler) AssignBytes([]byte) error { - return mixins.StringAssembler{"data.String"}.AssignBytes(nil) + return mixins.StringAssembler{TypeName: "data.String"}.AssignBytes(nil) } func (_String__Assembler) AssignLink(ipld.Link) error { - return mixins.StringAssembler{"data.String"}.AssignLink(nil) + return mixins.StringAssembler{TypeName: "data.String"}.AssignLink(nil) } func (na *_String__Assembler) AssignNode(v ipld.Node) error { if v.IsNull() { @@ -1185,11 +1191,6 @@ func (na *_String__Assembler) AssignNode(v ipld.Node) error { case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") } - if na.w == nil { - na.w = v2 - *na.m = schema.Maybe_Value - return nil - } *na.w = *v2 *na.m = schema.Maybe_Value return nil @@ -1209,12 +1210,14 @@ func (String) Type() schema.Type { func (n String) Representation() ipld.Node { return (*_String__Repr)(n) } + type _String__Repr = _String + var _ ipld.Node = &_String__Repr{} + type _String__ReprPrototype = _String__Prototype type _String__ReprAssembler = _String__Assembler - func (n _UnixFSData) FieldDataType() Int { return &n.DataType } @@ -1239,6 +1242,7 @@ func (n _UnixFSData) FieldMode() MaybeInt { func (n _UnixFSData) FieldMtime() MaybeUnixTime { return &n.Mtime } + type _UnixFSData__Maybe struct { m schema.Maybe v UnixFSData @@ -1256,14 +1260,14 @@ func (m MaybeUnixFSData) Exists() bool { } func (m MaybeUnixFSData) AsNode() ipld.Node { switch m.m { - case schema.Maybe_Absent: - return ipld.Absent - case schema.Maybe_Null: - return ipld.Null - case schema.Maybe_Value: - return m.v - default: - panic("unreachable") + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") } } func (m MaybeUnixFSData) Must() UnixFSData { @@ -1272,18 +1276,20 @@ func (m MaybeUnixFSData) Must() UnixFSData { } return m.v } + var ( - fieldName__UnixFSData_DataType = _String{"DataType"} - fieldName__UnixFSData_Data = _String{"Data"} - fieldName__UnixFSData_FileSize = _String{"FileSize"} + fieldName__UnixFSData_DataType = _String{"DataType"} + fieldName__UnixFSData_Data = _String{"Data"} + fieldName__UnixFSData_FileSize = _String{"FileSize"} fieldName__UnixFSData_BlockSizes = _String{"BlockSizes"} - fieldName__UnixFSData_HashType = _String{"HashType"} - fieldName__UnixFSData_Fanout = _String{"Fanout"} - fieldName__UnixFSData_Mode = _String{"Mode"} - fieldName__UnixFSData_Mtime = _String{"Mtime"} + fieldName__UnixFSData_HashType = _String{"HashType"} + fieldName__UnixFSData_Fanout = _String{"Fanout"} + fieldName__UnixFSData_Mode = _String{"Mode"} + fieldName__UnixFSData_Mtime = _String{"Mtime"} ) var _ ipld.Node = (UnixFSData)(&_UnixFSData{}) var _ schema.TypedNode = (UnixFSData)(&_UnixFSData{}) + func (UnixFSData) Kind() ipld.Kind { return ipld.Kind_Map } @@ -1295,29 +1301,29 @@ func (n UnixFSData) LookupByString(key string) (ipld.Node, error) { if n.Data.m == schema.Maybe_Absent { return ipld.Absent, nil } - return n.Data.v, nil + return &n.Data.v, nil case "FileSize": if n.FileSize.m == schema.Maybe_Absent { return ipld.Absent, nil } - return n.FileSize.v, nil + return &n.FileSize.v, nil case "BlockSizes": return &n.BlockSizes, nil case "HashType": if n.HashType.m == schema.Maybe_Absent { return ipld.Absent, nil } - return n.HashType.v, nil + return &n.HashType.v, nil case "Fanout": if n.Fanout.m == schema.Maybe_Absent { return ipld.Absent, nil } - return n.Fanout.v, nil + return &n.Fanout.v, nil case "Mode": if n.Mode.m == schema.Maybe_Absent { return ipld.Absent, nil } - return n.Mode.v, nil + return &n.Mode.v, nil case "Mtime": if n.Mtime.m == schema.Maybe_Absent { return ipld.Absent, nil @@ -1335,7 +1341,7 @@ func (n UnixFSData) LookupByNode(key ipld.Node) (ipld.Node, error) { return n.LookupByString(ks) } func (UnixFSData) LookupByIndex(idx int64) (ipld.Node, error) { - return mixins.Map{"data.UnixFSData"}.LookupByIndex(0) + return mixins.Map{TypeName: "data.UnixFSData"}.LookupByIndex(0) } func (n UnixFSData) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { return n.LookupByString(seg.String()) @@ -1345,11 +1351,12 @@ func (n UnixFSData) MapIterator() ipld.MapIterator { } type _UnixFSData__MapItr struct { - n UnixFSData - idx int + n UnixFSData + idx int } -func (itr *_UnixFSData__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) {if itr.idx >= 8 { +func (itr *_UnixFSData__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) { + if itr.idx >= 8 { return nil, nil, ipld.ErrIteratorOverread{} } switch itr.idx { @@ -1362,14 +1369,14 @@ func (itr *_UnixFSData__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) {if i v = ipld.Absent break } - v = itr.n.Data.v + v = &itr.n.Data.v case 2: k = &fieldName__UnixFSData_FileSize if itr.n.FileSize.m == schema.Maybe_Absent { v = ipld.Absent break } - v = itr.n.FileSize.v + v = &itr.n.FileSize.v case 3: k = &fieldName__UnixFSData_BlockSizes v = &itr.n.BlockSizes @@ -1379,21 +1386,21 @@ func (itr *_UnixFSData__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) {if i v = ipld.Absent break } - v = itr.n.HashType.v + v = &itr.n.HashType.v case 5: k = &fieldName__UnixFSData_Fanout if itr.n.Fanout.m == schema.Maybe_Absent { v = ipld.Absent break } - v = itr.n.Fanout.v + v = &itr.n.Fanout.v case 6: k = &fieldName__UnixFSData_Mode if itr.n.Mode.m == schema.Maybe_Absent { v = ipld.Absent break } - v = itr.n.Mode.v + v = &itr.n.Mode.v case 7: k = &fieldName__UnixFSData_Mtime if itr.n.Mtime.m == schema.Maybe_Absent { @@ -1424,26 +1431,27 @@ func (UnixFSData) IsNull() bool { return false } func (UnixFSData) AsBool() (bool, error) { - return mixins.Map{"data.UnixFSData"}.AsBool() + return mixins.Map{TypeName: "data.UnixFSData"}.AsBool() } func (UnixFSData) AsInt() (int64, error) { - return mixins.Map{"data.UnixFSData"}.AsInt() + return mixins.Map{TypeName: "data.UnixFSData"}.AsInt() } func (UnixFSData) AsFloat() (float64, error) { - return mixins.Map{"data.UnixFSData"}.AsFloat() + return mixins.Map{TypeName: "data.UnixFSData"}.AsFloat() } func (UnixFSData) AsString() (string, error) { - return mixins.Map{"data.UnixFSData"}.AsString() + return mixins.Map{TypeName: "data.UnixFSData"}.AsString() } func (UnixFSData) AsBytes() ([]byte, error) { - return mixins.Map{"data.UnixFSData"}.AsBytes() + return mixins.Map{TypeName: "data.UnixFSData"}.AsBytes() } func (UnixFSData) AsLink() (ipld.Link, error) { - return mixins.Map{"data.UnixFSData"}.AsLink() + return mixins.Map{TypeName: "data.UnixFSData"}.AsLink() } func (UnixFSData) Prototype() ipld.NodePrototype { return _UnixFSData__Prototype{} } + type _UnixFSData__Prototype struct{} func (_UnixFSData__Prototype) NewBuilder() ipld.NodeBuilder { @@ -1451,9 +1459,11 @@ func (_UnixFSData__Prototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } + type _UnixFSData__Builder struct { _UnixFSData__Assembler } + func (nb *_UnixFSData__Builder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -1465,23 +1475,24 @@ func (nb *_UnixFSData__Builder) Reset() { var m schema.Maybe *nb = _UnixFSData__Builder{_UnixFSData__Assembler{w: &w, m: &m}} } + type _UnixFSData__Assembler struct { - w *_UnixFSData - m *schema.Maybe + w *_UnixFSData + m *schema.Maybe state maState - s int - f int + s int + f int - cm schema.Maybe - ca_DataType _Int__Assembler - ca_Data _Bytes__Assembler - ca_FileSize _Int__Assembler + cm schema.Maybe + ca_DataType _Int__Assembler + ca_Data _Bytes__Assembler + ca_FileSize _Int__Assembler ca_BlockSizes _BlockSizes__Assembler - ca_HashType _Int__Assembler - ca_Fanout _Int__Assembler - ca_Mode _Int__Assembler - ca_Mtime _UnixTime__Assembler - } + ca_HashType _Int__Assembler + ca_Fanout _Int__Assembler + ca_Mode _Int__Assembler + ca_Mtime _UnixTime__Assembler +} func (na *_UnixFSData__Assembler) reset() { na.state = maState_initial @@ -1497,16 +1508,17 @@ func (na *_UnixFSData__Assembler) reset() { } var ( - fieldBit__UnixFSData_DataType = 1 << 0 - fieldBit__UnixFSData_Data = 1 << 1 - fieldBit__UnixFSData_FileSize = 1 << 2 - fieldBit__UnixFSData_BlockSizes = 1 << 3 - fieldBit__UnixFSData_HashType = 1 << 4 - fieldBit__UnixFSData_Fanout = 1 << 5 - fieldBit__UnixFSData_Mode = 1 << 6 - fieldBit__UnixFSData_Mtime = 1 << 7 - fieldBits__UnixFSData_sufficient = 0 + 1 << 0 + 1 << 3 + fieldBit__UnixFSData_DataType = 1 << 0 + fieldBit__UnixFSData_Data = 1 << 1 + fieldBit__UnixFSData_FileSize = 1 << 2 + fieldBit__UnixFSData_BlockSizes = 1 << 3 + fieldBit__UnixFSData_HashType = 1 << 4 + fieldBit__UnixFSData_Fanout = 1 << 5 + fieldBit__UnixFSData_Mode = 1 << 6 + fieldBit__UnixFSData_Mtime = 1 << 7 + fieldBits__UnixFSData_sufficient = 0 + 1<<0 + 1<<3 ) + func (na *_UnixFSData__Assembler) BeginMap(int64) (ipld.MapAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: @@ -1521,7 +1533,7 @@ func (na *_UnixFSData__Assembler) BeginMap(int64) (ipld.MapAssembler, error) { return na, nil } func (_UnixFSData__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.MapAssembler{"data.UnixFSData"}.BeginList(0) + return mixins.MapAssembler{TypeName: "data.UnixFSData"}.BeginList(0) } func (na *_UnixFSData__Assembler) AssignNull() error { switch *na.m { @@ -1529,7 +1541,7 @@ func (na *_UnixFSData__Assembler) AssignNull() error { *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.MapAssembler{"data.UnixFSData"}.AssignNull() + return mixins.MapAssembler{TypeName: "data.UnixFSData"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -1538,22 +1550,22 @@ func (na *_UnixFSData__Assembler) AssignNull() error { panic("unreachable") } func (_UnixFSData__Assembler) AssignBool(bool) error { - return mixins.MapAssembler{"data.UnixFSData"}.AssignBool(false) + return mixins.MapAssembler{TypeName: "data.UnixFSData"}.AssignBool(false) } func (_UnixFSData__Assembler) AssignInt(int64) error { - return mixins.MapAssembler{"data.UnixFSData"}.AssignInt(0) + return mixins.MapAssembler{TypeName: "data.UnixFSData"}.AssignInt(0) } func (_UnixFSData__Assembler) AssignFloat(float64) error { - return mixins.MapAssembler{"data.UnixFSData"}.AssignFloat(0) + return mixins.MapAssembler{TypeName: "data.UnixFSData"}.AssignFloat(0) } func (_UnixFSData__Assembler) AssignString(string) error { - return mixins.MapAssembler{"data.UnixFSData"}.AssignString("") + return mixins.MapAssembler{TypeName: "data.UnixFSData"}.AssignString("") } func (_UnixFSData__Assembler) AssignBytes([]byte) error { - return mixins.MapAssembler{"data.UnixFSData"}.AssignBytes(nil) + return mixins.MapAssembler{TypeName: "data.UnixFSData"}.AssignBytes(nil) } func (_UnixFSData__Assembler) AssignLink(ipld.Link) error { - return mixins.MapAssembler{"data.UnixFSData"}.AssignLink(nil) + return mixins.MapAssembler{TypeName: "data.UnixFSData"}.AssignLink(nil) } func (na *_UnixFSData__Assembler) AssignNode(v ipld.Node) error { if v.IsNull() { @@ -1611,7 +1623,6 @@ func (ma *_UnixFSData__Assembler) valueFinishTidy() bool { case 1: switch ma.w.Data.m { case schema.Maybe_Value: - ma.w.Data.v = ma.ca_Data.w ma.state = maState_initial return true default: @@ -1620,7 +1631,6 @@ func (ma *_UnixFSData__Assembler) valueFinishTidy() bool { case 2: switch ma.w.FileSize.m { case schema.Maybe_Value: - ma.w.FileSize.v = ma.ca_FileSize.w ma.state = maState_initial return true default: @@ -1639,7 +1649,6 @@ func (ma *_UnixFSData__Assembler) valueFinishTidy() bool { case 4: switch ma.w.HashType.m { case schema.Maybe_Value: - ma.w.HashType.v = ma.ca_HashType.w ma.state = maState_initial return true default: @@ -1648,7 +1657,6 @@ func (ma *_UnixFSData__Assembler) valueFinishTidy() bool { case 5: switch ma.w.Fanout.m { case schema.Maybe_Value: - ma.w.Fanout.v = ma.ca_Fanout.w ma.state = maState_initial return true default: @@ -1657,7 +1665,6 @@ func (ma *_UnixFSData__Assembler) valueFinishTidy() bool { case 6: switch ma.w.Mode.m { case schema.Maybe_Value: - ma.w.Mode.v = ma.ca_Mode.w ma.state = maState_initial return true default: @@ -1693,7 +1700,7 @@ func (ma *_UnixFSData__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, e } switch k { case "DataType": - if ma.s & fieldBit__UnixFSData_DataType != 0 { + if ma.s&fieldBit__UnixFSData_DataType != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_DataType} } ma.s += fieldBit__UnixFSData_DataType @@ -1703,27 +1710,27 @@ func (ma *_UnixFSData__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, e ma.ca_DataType.m = &ma.cm return &ma.ca_DataType, nil case "Data": - if ma.s & fieldBit__UnixFSData_Data != 0 { + if ma.s&fieldBit__UnixFSData_Data != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Data} } ma.s += fieldBit__UnixFSData_Data ma.state = maState_midValue ma.f = 1 - ma.ca_Data.w = ma.w.Data.v + ma.ca_Data.w = &ma.w.Data.v ma.ca_Data.m = &ma.w.Data.m return &ma.ca_Data, nil case "FileSize": - if ma.s & fieldBit__UnixFSData_FileSize != 0 { + if ma.s&fieldBit__UnixFSData_FileSize != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_FileSize} } ma.s += fieldBit__UnixFSData_FileSize ma.state = maState_midValue ma.f = 2 - ma.ca_FileSize.w = ma.w.FileSize.v + ma.ca_FileSize.w = &ma.w.FileSize.v ma.ca_FileSize.m = &ma.w.FileSize.m return &ma.ca_FileSize, nil case "BlockSizes": - if ma.s & fieldBit__UnixFSData_BlockSizes != 0 { + if ma.s&fieldBit__UnixFSData_BlockSizes != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_BlockSizes} } ma.s += fieldBit__UnixFSData_BlockSizes @@ -1733,37 +1740,37 @@ func (ma *_UnixFSData__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, e ma.ca_BlockSizes.m = &ma.cm return &ma.ca_BlockSizes, nil case "HashType": - if ma.s & fieldBit__UnixFSData_HashType != 0 { + if ma.s&fieldBit__UnixFSData_HashType != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_HashType} } ma.s += fieldBit__UnixFSData_HashType ma.state = maState_midValue ma.f = 4 - ma.ca_HashType.w = ma.w.HashType.v + ma.ca_HashType.w = &ma.w.HashType.v ma.ca_HashType.m = &ma.w.HashType.m return &ma.ca_HashType, nil case "Fanout": - if ma.s & fieldBit__UnixFSData_Fanout != 0 { + if ma.s&fieldBit__UnixFSData_Fanout != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Fanout} } ma.s += fieldBit__UnixFSData_Fanout ma.state = maState_midValue ma.f = 5 - ma.ca_Fanout.w = ma.w.Fanout.v + ma.ca_Fanout.w = &ma.w.Fanout.v ma.ca_Fanout.m = &ma.w.Fanout.m return &ma.ca_Fanout, nil case "Mode": - if ma.s & fieldBit__UnixFSData_Mode != 0 { + if ma.s&fieldBit__UnixFSData_Mode != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mode} } ma.s += fieldBit__UnixFSData_Mode ma.state = maState_midValue ma.f = 6 - ma.ca_Mode.w = ma.w.Mode.v + ma.ca_Mode.w = &ma.w.Mode.v ma.ca_Mode.m = &ma.w.Mode.m return &ma.ca_Mode, nil case "Mtime": - if ma.s & fieldBit__UnixFSData_Mtime != 0 { + if ma.s&fieldBit__UnixFSData_Mtime != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mtime} } ma.s += fieldBit__UnixFSData_Mtime @@ -1773,7 +1780,7 @@ func (ma *_UnixFSData__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, e ma.ca_Mtime.m = &ma.w.Mtime.m return &ma.ca_Mtime, nil } - return nil, ipld.ErrInvalidKey{TypeName:"data.UnixFSData", Key:&_String{k}} + return nil, ipld.ErrInvalidKey{TypeName: "data.UnixFSData", Key: &_String{k}} } func (ma *_UnixFSData__Assembler) AssembleKey() ipld.NodeAssembler { switch ma.state { @@ -1813,11 +1820,11 @@ func (ma *_UnixFSData__Assembler) AssembleValue() ipld.NodeAssembler { ma.ca_DataType.m = &ma.cm return &ma.ca_DataType case 1: - ma.ca_Data.w = ma.w.Data.v + ma.ca_Data.w = &ma.w.Data.v ma.ca_Data.m = &ma.w.Data.m return &ma.ca_Data case 2: - ma.ca_FileSize.w = ma.w.FileSize.v + ma.ca_FileSize.w = &ma.w.FileSize.v ma.ca_FileSize.m = &ma.w.FileSize.m return &ma.ca_FileSize case 3: @@ -1825,15 +1832,15 @@ func (ma *_UnixFSData__Assembler) AssembleValue() ipld.NodeAssembler { ma.ca_BlockSizes.m = &ma.cm return &ma.ca_BlockSizes case 4: - ma.ca_HashType.w = ma.w.HashType.v + ma.ca_HashType.w = &ma.w.HashType.v ma.ca_HashType.m = &ma.w.HashType.m return &ma.ca_HashType case 5: - ma.ca_Fanout.w = ma.w.Fanout.v + ma.ca_Fanout.w = &ma.w.Fanout.v ma.ca_Fanout.m = &ma.w.Fanout.m return &ma.ca_Fanout case 6: - ma.ca_Mode.w = ma.w.Mode.v + ma.ca_Mode.w = &ma.w.Mode.v ma.ca_Mode.m = &ma.w.Mode.m return &ma.ca_Mode case 7: @@ -1859,12 +1866,12 @@ func (ma *_UnixFSData__Assembler) Finish() error { case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } - if ma.s & fieldBits__UnixFSData_sufficient != fieldBits__UnixFSData_sufficient { + if ma.s&fieldBits__UnixFSData_sufficient != fieldBits__UnixFSData_sufficient { err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} - if ma.s & fieldBit__UnixFSData_DataType == 0 { + if ma.s&fieldBit__UnixFSData_DataType == 0 { err.Missing = append(err.Missing, "DataType") } - if ma.s & fieldBit__UnixFSData_BlockSizes == 0 { + if ma.s&fieldBit__UnixFSData_BlockSizes == 0 { err.Missing = append(err.Missing, "BlockSizes") } return err @@ -1879,24 +1886,26 @@ func (ma *_UnixFSData__Assembler) KeyPrototype() ipld.NodePrototype { func (ma *_UnixFSData__Assembler) ValuePrototype(k string) ipld.NodePrototype { panic("todo structbuilder mapassembler valueprototype") } + type _UnixFSData__KeyAssembler _UnixFSData__Assembler + func (_UnixFSData__KeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { - return mixins.StringAssembler{"data.UnixFSData.KeyAssembler"}.BeginMap(0) + return mixins.StringAssembler{TypeName: "data.UnixFSData.KeyAssembler"}.BeginMap(0) } func (_UnixFSData__KeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.StringAssembler{"data.UnixFSData.KeyAssembler"}.BeginList(0) + return mixins.StringAssembler{TypeName: "data.UnixFSData.KeyAssembler"}.BeginList(0) } func (na *_UnixFSData__KeyAssembler) AssignNull() error { - return mixins.StringAssembler{"data.UnixFSData.KeyAssembler"}.AssignNull() + return mixins.StringAssembler{TypeName: "data.UnixFSData.KeyAssembler"}.AssignNull() } func (_UnixFSData__KeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{"data.UnixFSData.KeyAssembler"}.AssignBool(false) + return mixins.StringAssembler{TypeName: "data.UnixFSData.KeyAssembler"}.AssignBool(false) } func (_UnixFSData__KeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{"data.UnixFSData.KeyAssembler"}.AssignInt(0) + return mixins.StringAssembler{TypeName: "data.UnixFSData.KeyAssembler"}.AssignInt(0) } func (_UnixFSData__KeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{"data.UnixFSData.KeyAssembler"}.AssignFloat(0) + return mixins.StringAssembler{TypeName: "data.UnixFSData.KeyAssembler"}.AssignFloat(0) } func (ka *_UnixFSData__KeyAssembler) AssignString(k string) error { if ka.state != maState_midKey { @@ -1904,71 +1913,71 @@ func (ka *_UnixFSData__KeyAssembler) AssignString(k string) error { } switch k { case "DataType": - if ka.s & fieldBit__UnixFSData_DataType != 0 { + if ka.s&fieldBit__UnixFSData_DataType != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_DataType} } ka.s += fieldBit__UnixFSData_DataType ka.state = maState_expectValue ka.f = 0 case "Data": - if ka.s & fieldBit__UnixFSData_Data != 0 { + if ka.s&fieldBit__UnixFSData_Data != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Data} } ka.s += fieldBit__UnixFSData_Data ka.state = maState_expectValue ka.f = 1 case "FileSize": - if ka.s & fieldBit__UnixFSData_FileSize != 0 { + if ka.s&fieldBit__UnixFSData_FileSize != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_FileSize} } ka.s += fieldBit__UnixFSData_FileSize ka.state = maState_expectValue ka.f = 2 case "BlockSizes": - if ka.s & fieldBit__UnixFSData_BlockSizes != 0 { + if ka.s&fieldBit__UnixFSData_BlockSizes != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_BlockSizes} } ka.s += fieldBit__UnixFSData_BlockSizes ka.state = maState_expectValue ka.f = 3 case "HashType": - if ka.s & fieldBit__UnixFSData_HashType != 0 { + if ka.s&fieldBit__UnixFSData_HashType != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_HashType} } ka.s += fieldBit__UnixFSData_HashType ka.state = maState_expectValue ka.f = 4 case "Fanout": - if ka.s & fieldBit__UnixFSData_Fanout != 0 { + if ka.s&fieldBit__UnixFSData_Fanout != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Fanout} } ka.s += fieldBit__UnixFSData_Fanout ka.state = maState_expectValue ka.f = 5 case "Mode": - if ka.s & fieldBit__UnixFSData_Mode != 0 { + if ka.s&fieldBit__UnixFSData_Mode != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mode} } ka.s += fieldBit__UnixFSData_Mode ka.state = maState_expectValue ka.f = 6 case "Mtime": - if ka.s & fieldBit__UnixFSData_Mtime != 0 { + if ka.s&fieldBit__UnixFSData_Mtime != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mtime} } ka.s += fieldBit__UnixFSData_Mtime ka.state = maState_expectValue ka.f = 7 default: - return ipld.ErrInvalidKey{TypeName:"data.UnixFSData", Key:&_String{k}} + return ipld.ErrInvalidKey{TypeName: "data.UnixFSData", Key: &_String{k}} } return nil } func (_UnixFSData__KeyAssembler) AssignBytes([]byte) error { - return mixins.StringAssembler{"data.UnixFSData.KeyAssembler"}.AssignBytes(nil) + return mixins.StringAssembler{TypeName: "data.UnixFSData.KeyAssembler"}.AssignBytes(nil) } func (_UnixFSData__KeyAssembler) AssignLink(ipld.Link) error { - return mixins.StringAssembler{"data.UnixFSData.KeyAssembler"}.AssignLink(nil) + return mixins.StringAssembler{TypeName: "data.UnixFSData.KeyAssembler"}.AssignLink(nil) } func (ka *_UnixFSData__KeyAssembler) AssignNode(v ipld.Node) error { if v2, err := v.AsString(); err != nil { @@ -1986,18 +1995,21 @@ func (UnixFSData) Type() schema.Type { func (n UnixFSData) Representation() ipld.Node { return (*_UnixFSData__Repr)(n) } + type _UnixFSData__Repr _UnixFSData + var ( - fieldName__UnixFSData_DataType_serial = _String{"DataType"} - fieldName__UnixFSData_Data_serial = _String{"Data"} - fieldName__UnixFSData_FileSize_serial = _String{"FileSize"} + fieldName__UnixFSData_DataType_serial = _String{"DataType"} + fieldName__UnixFSData_Data_serial = _String{"Data"} + fieldName__UnixFSData_FileSize_serial = _String{"FileSize"} fieldName__UnixFSData_BlockSizes_serial = _String{"BlockSizes"} - fieldName__UnixFSData_HashType_serial = _String{"HashType"} - fieldName__UnixFSData_Fanout_serial = _String{"Fanout"} - fieldName__UnixFSData_Mode_serial = _String{"Mode"} - fieldName__UnixFSData_Mtime_serial = _String{"Mtime"} + fieldName__UnixFSData_HashType_serial = _String{"HashType"} + fieldName__UnixFSData_Fanout_serial = _String{"Fanout"} + fieldName__UnixFSData_Mode_serial = _String{"Mode"} + fieldName__UnixFSData_Mtime_serial = _String{"Mtime"} ) var _ ipld.Node = &_UnixFSData__Repr{} + func (_UnixFSData__Repr) Kind() ipld.Kind { return ipld.Kind_Map } @@ -2049,7 +2061,7 @@ func (n *_UnixFSData__Repr) LookupByNode(key ipld.Node) (ipld.Node, error) { return n.LookupByString(ks) } func (_UnixFSData__Repr) LookupByIndex(idx int64) (ipld.Node, error) { - return mixins.Map{"data.UnixFSData.Repr"}.LookupByIndex(0) + return mixins.Map{TypeName: "data.UnixFSData.Repr"}.LookupByIndex(0) } func (n _UnixFSData__Repr) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { return n.LookupByString(seg.String()) @@ -2086,7 +2098,9 @@ type _UnixFSData__ReprMapItr struct { end int } -func (itr *_UnixFSData__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) {advance:if itr.idx >= 8 { +func (itr *_UnixFSData__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) { +advance: + if itr.idx >= 8 { return nil, nil, ipld.ErrIteratorOverread{} } switch itr.idx { @@ -2179,26 +2193,27 @@ func (_UnixFSData__Repr) IsNull() bool { return false } func (_UnixFSData__Repr) AsBool() (bool, error) { - return mixins.Map{"data.UnixFSData.Repr"}.AsBool() + return mixins.Map{TypeName: "data.UnixFSData.Repr"}.AsBool() } func (_UnixFSData__Repr) AsInt() (int64, error) { - return mixins.Map{"data.UnixFSData.Repr"}.AsInt() + return mixins.Map{TypeName: "data.UnixFSData.Repr"}.AsInt() } func (_UnixFSData__Repr) AsFloat() (float64, error) { - return mixins.Map{"data.UnixFSData.Repr"}.AsFloat() + return mixins.Map{TypeName: "data.UnixFSData.Repr"}.AsFloat() } func (_UnixFSData__Repr) AsString() (string, error) { - return mixins.Map{"data.UnixFSData.Repr"}.AsString() + return mixins.Map{TypeName: "data.UnixFSData.Repr"}.AsString() } func (_UnixFSData__Repr) AsBytes() ([]byte, error) { - return mixins.Map{"data.UnixFSData.Repr"}.AsBytes() + return mixins.Map{TypeName: "data.UnixFSData.Repr"}.AsBytes() } func (_UnixFSData__Repr) AsLink() (ipld.Link, error) { - return mixins.Map{"data.UnixFSData.Repr"}.AsLink() + return mixins.Map{TypeName: "data.UnixFSData.Repr"}.AsLink() } func (_UnixFSData__Repr) Prototype() ipld.NodePrototype { return _UnixFSData__ReprPrototype{} } + type _UnixFSData__ReprPrototype struct{} func (_UnixFSData__ReprPrototype) NewBuilder() ipld.NodeBuilder { @@ -2206,9 +2221,11 @@ func (_UnixFSData__ReprPrototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } + type _UnixFSData__ReprBuilder struct { _UnixFSData__ReprAssembler } + func (nb *_UnixFSData__ReprBuilder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -2220,23 +2237,24 @@ func (nb *_UnixFSData__ReprBuilder) Reset() { var m schema.Maybe *nb = _UnixFSData__ReprBuilder{_UnixFSData__ReprAssembler{w: &w, m: &m}} } + type _UnixFSData__ReprAssembler struct { - w *_UnixFSData - m *schema.Maybe + w *_UnixFSData + m *schema.Maybe state maState - s int - f int + s int + f int - cm schema.Maybe - ca_DataType _Int__ReprAssembler - ca_Data _Bytes__ReprAssembler - ca_FileSize _Int__ReprAssembler + cm schema.Maybe + ca_DataType _Int__ReprAssembler + ca_Data _Bytes__ReprAssembler + ca_FileSize _Int__ReprAssembler ca_BlockSizes _BlockSizes__ReprAssembler - ca_HashType _Int__ReprAssembler - ca_Fanout _Int__ReprAssembler - ca_Mode _Int__ReprAssembler - ca_Mtime _UnixTime__ReprAssembler - } + ca_HashType _Int__ReprAssembler + ca_Fanout _Int__ReprAssembler + ca_Mode _Int__ReprAssembler + ca_Mtime _UnixTime__ReprAssembler +} func (na *_UnixFSData__ReprAssembler) reset() { na.state = maState_initial @@ -2264,7 +2282,7 @@ func (na *_UnixFSData__ReprAssembler) BeginMap(int64) (ipld.MapAssembler, error) return na, nil } func (_UnixFSData__ReprAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.MapAssembler{"data.UnixFSData.Repr"}.BeginList(0) + return mixins.MapAssembler{TypeName: "data.UnixFSData.Repr"}.BeginList(0) } func (na *_UnixFSData__ReprAssembler) AssignNull() error { switch *na.m { @@ -2272,7 +2290,7 @@ func (na *_UnixFSData__ReprAssembler) AssignNull() error { *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.MapAssembler{"data.UnixFSData.Repr.Repr"}.AssignNull() + return mixins.MapAssembler{TypeName: "data.UnixFSData.Repr.Repr"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -2281,22 +2299,22 @@ func (na *_UnixFSData__ReprAssembler) AssignNull() error { panic("unreachable") } func (_UnixFSData__ReprAssembler) AssignBool(bool) error { - return mixins.MapAssembler{"data.UnixFSData.Repr"}.AssignBool(false) + return mixins.MapAssembler{TypeName: "data.UnixFSData.Repr"}.AssignBool(false) } func (_UnixFSData__ReprAssembler) AssignInt(int64) error { - return mixins.MapAssembler{"data.UnixFSData.Repr"}.AssignInt(0) + return mixins.MapAssembler{TypeName: "data.UnixFSData.Repr"}.AssignInt(0) } func (_UnixFSData__ReprAssembler) AssignFloat(float64) error { - return mixins.MapAssembler{"data.UnixFSData.Repr"}.AssignFloat(0) + return mixins.MapAssembler{TypeName: "data.UnixFSData.Repr"}.AssignFloat(0) } func (_UnixFSData__ReprAssembler) AssignString(string) error { - return mixins.MapAssembler{"data.UnixFSData.Repr"}.AssignString("") + return mixins.MapAssembler{TypeName: "data.UnixFSData.Repr"}.AssignString("") } func (_UnixFSData__ReprAssembler) AssignBytes([]byte) error { - return mixins.MapAssembler{"data.UnixFSData.Repr"}.AssignBytes(nil) + return mixins.MapAssembler{TypeName: "data.UnixFSData.Repr"}.AssignBytes(nil) } func (_UnixFSData__ReprAssembler) AssignLink(ipld.Link) error { - return mixins.MapAssembler{"data.UnixFSData.Repr"}.AssignLink(nil) + return mixins.MapAssembler{TypeName: "data.UnixFSData.Repr"}.AssignLink(nil) } func (na *_UnixFSData__ReprAssembler) AssignNode(v ipld.Node) error { if v.IsNull() { @@ -2343,7 +2361,8 @@ func (ma *_UnixFSData__ReprAssembler) valueFinishTidy() bool { switch ma.f { case 0: switch ma.cm { - case schema.Maybe_Value:ma.cm = schema.Maybe_Absent + case schema.Maybe_Value: + ma.cm = schema.Maybe_Absent ma.state = maState_initial return true default: @@ -2352,7 +2371,6 @@ func (ma *_UnixFSData__ReprAssembler) valueFinishTidy() bool { case 1: switch ma.w.Data.m { case schema.Maybe_Value: - ma.w.Data.v = ma.ca_Data.w ma.state = maState_initial return true default: @@ -2361,7 +2379,6 @@ func (ma *_UnixFSData__ReprAssembler) valueFinishTidy() bool { case 2: switch ma.w.FileSize.m { case schema.Maybe_Value: - ma.w.FileSize.v = ma.ca_FileSize.w ma.state = maState_initial return true default: @@ -2369,7 +2386,8 @@ func (ma *_UnixFSData__ReprAssembler) valueFinishTidy() bool { } case 3: switch ma.cm { - case schema.Maybe_Value:ma.cm = schema.Maybe_Absent + case schema.Maybe_Value: + ma.cm = schema.Maybe_Absent ma.state = maState_initial return true default: @@ -2378,7 +2396,6 @@ func (ma *_UnixFSData__ReprAssembler) valueFinishTidy() bool { case 4: switch ma.w.HashType.m { case schema.Maybe_Value: - ma.w.HashType.v = ma.ca_HashType.w ma.state = maState_initial return true default: @@ -2387,7 +2404,6 @@ func (ma *_UnixFSData__ReprAssembler) valueFinishTidy() bool { case 5: switch ma.w.Fanout.m { case schema.Maybe_Value: - ma.w.Fanout.v = ma.ca_Fanout.w ma.state = maState_initial return true default: @@ -2396,7 +2412,6 @@ func (ma *_UnixFSData__ReprAssembler) valueFinishTidy() bool { case 6: switch ma.w.Mode.m { case schema.Maybe_Value: - ma.w.Mode.v = ma.ca_Mode.w ma.state = maState_initial return true default: @@ -2432,7 +2447,7 @@ func (ma *_UnixFSData__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssemble } switch k { case "DataType": - if ma.s & fieldBit__UnixFSData_DataType != 0 { + if ma.s&fieldBit__UnixFSData_DataType != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_DataType_serial} } ma.s += fieldBit__UnixFSData_DataType @@ -2442,29 +2457,29 @@ func (ma *_UnixFSData__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssemble ma.ca_DataType.m = &ma.cm return &ma.ca_DataType, nil case "Data": - if ma.s & fieldBit__UnixFSData_Data != 0 { + if ma.s&fieldBit__UnixFSData_Data != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Data_serial} } ma.s += fieldBit__UnixFSData_Data ma.state = maState_midValue ma.f = 1 - ma.ca_Data.w = ma.w.Data.v + ma.ca_Data.w = &ma.w.Data.v ma.ca_Data.m = &ma.w.Data.m - + return &ma.ca_Data, nil case "FileSize": - if ma.s & fieldBit__UnixFSData_FileSize != 0 { + if ma.s&fieldBit__UnixFSData_FileSize != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_FileSize_serial} } ma.s += fieldBit__UnixFSData_FileSize ma.state = maState_midValue ma.f = 2 - ma.ca_FileSize.w = ma.w.FileSize.v + ma.ca_FileSize.w = &ma.w.FileSize.v ma.ca_FileSize.m = &ma.w.FileSize.m - + return &ma.ca_FileSize, nil case "BlockSizes": - if ma.s & fieldBit__UnixFSData_BlockSizes != 0 { + if ma.s&fieldBit__UnixFSData_BlockSizes != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_BlockSizes_serial} } ma.s += fieldBit__UnixFSData_BlockSizes @@ -2474,40 +2489,40 @@ func (ma *_UnixFSData__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssemble ma.ca_BlockSizes.m = &ma.cm return &ma.ca_BlockSizes, nil case "HashType": - if ma.s & fieldBit__UnixFSData_HashType != 0 { + if ma.s&fieldBit__UnixFSData_HashType != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_HashType_serial} } ma.s += fieldBit__UnixFSData_HashType ma.state = maState_midValue ma.f = 4 - ma.ca_HashType.w = ma.w.HashType.v + ma.ca_HashType.w = &ma.w.HashType.v ma.ca_HashType.m = &ma.w.HashType.m - + return &ma.ca_HashType, nil case "Fanout": - if ma.s & fieldBit__UnixFSData_Fanout != 0 { + if ma.s&fieldBit__UnixFSData_Fanout != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Fanout_serial} } ma.s += fieldBit__UnixFSData_Fanout ma.state = maState_midValue ma.f = 5 - ma.ca_Fanout.w = ma.w.Fanout.v + ma.ca_Fanout.w = &ma.w.Fanout.v ma.ca_Fanout.m = &ma.w.Fanout.m - + return &ma.ca_Fanout, nil case "Mode": - if ma.s & fieldBit__UnixFSData_Mode != 0 { + if ma.s&fieldBit__UnixFSData_Mode != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mode_serial} } ma.s += fieldBit__UnixFSData_Mode ma.state = maState_midValue ma.f = 6 - ma.ca_Mode.w = ma.w.Mode.v + ma.ca_Mode.w = &ma.w.Mode.v ma.ca_Mode.m = &ma.w.Mode.m - + return &ma.ca_Mode, nil case "Mtime": - if ma.s & fieldBit__UnixFSData_Mtime != 0 { + if ma.s&fieldBit__UnixFSData_Mtime != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mtime_serial} } ma.s += fieldBit__UnixFSData_Mtime @@ -2515,11 +2530,11 @@ func (ma *_UnixFSData__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssemble ma.f = 7 ma.ca_Mtime.w = ma.w.Mtime.v ma.ca_Mtime.m = &ma.w.Mtime.m - + return &ma.ca_Mtime, nil default: } - return nil, ipld.ErrInvalidKey{TypeName:"data.UnixFSData.Repr", Key:&_String{k}} + return nil, ipld.ErrInvalidKey{TypeName: "data.UnixFSData.Repr", Key: &_String{k}} } func (ma *_UnixFSData__ReprAssembler) AssembleKey() ipld.NodeAssembler { switch ma.state { @@ -2559,38 +2574,38 @@ func (ma *_UnixFSData__ReprAssembler) AssembleValue() ipld.NodeAssembler { ma.ca_DataType.m = &ma.cm return &ma.ca_DataType case 1: - ma.ca_Data.w = ma.w.Data.v + ma.ca_Data.w = &ma.w.Data.v ma.ca_Data.m = &ma.w.Data.m - + return &ma.ca_Data case 2: - ma.ca_FileSize.w = ma.w.FileSize.v + ma.ca_FileSize.w = &ma.w.FileSize.v ma.ca_FileSize.m = &ma.w.FileSize.m - + return &ma.ca_FileSize case 3: ma.ca_BlockSizes.w = &ma.w.BlockSizes ma.ca_BlockSizes.m = &ma.cm return &ma.ca_BlockSizes case 4: - ma.ca_HashType.w = ma.w.HashType.v + ma.ca_HashType.w = &ma.w.HashType.v ma.ca_HashType.m = &ma.w.HashType.m - + return &ma.ca_HashType case 5: - ma.ca_Fanout.w = ma.w.Fanout.v + ma.ca_Fanout.w = &ma.w.Fanout.v ma.ca_Fanout.m = &ma.w.Fanout.m - + return &ma.ca_Fanout case 6: - ma.ca_Mode.w = ma.w.Mode.v + ma.ca_Mode.w = &ma.w.Mode.v ma.ca_Mode.m = &ma.w.Mode.m - + return &ma.ca_Mode case 7: ma.ca_Mtime.w = ma.w.Mtime.v ma.ca_Mtime.m = &ma.w.Mtime.m - + return &ma.ca_Mtime default: panic("unreachable") @@ -2611,12 +2626,12 @@ func (ma *_UnixFSData__ReprAssembler) Finish() error { case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } - if ma.s & fieldBits__UnixFSData_sufficient != fieldBits__UnixFSData_sufficient { + if ma.s&fieldBits__UnixFSData_sufficient != fieldBits__UnixFSData_sufficient { err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} - if ma.s & fieldBit__UnixFSData_DataType == 0 { + if ma.s&fieldBit__UnixFSData_DataType == 0 { err.Missing = append(err.Missing, "DataType") } - if ma.s & fieldBit__UnixFSData_BlockSizes == 0 { + if ma.s&fieldBit__UnixFSData_BlockSizes == 0 { err.Missing = append(err.Missing, "BlockSizes") } return err @@ -2631,24 +2646,26 @@ func (ma *_UnixFSData__ReprAssembler) KeyPrototype() ipld.NodePrototype { func (ma *_UnixFSData__ReprAssembler) ValuePrototype(k string) ipld.NodePrototype { panic("todo structbuilder mapassembler repr valueprototype") } + type _UnixFSData__ReprKeyAssembler _UnixFSData__ReprAssembler + func (_UnixFSData__ReprKeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { - return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.BeginMap(0) + return mixins.StringAssembler{TypeName: "data.UnixFSData.Repr.KeyAssembler"}.BeginMap(0) } func (_UnixFSData__ReprKeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.BeginList(0) + return mixins.StringAssembler{TypeName: "data.UnixFSData.Repr.KeyAssembler"}.BeginList(0) } func (na *_UnixFSData__ReprKeyAssembler) AssignNull() error { - return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.AssignNull() + return mixins.StringAssembler{TypeName: "data.UnixFSData.Repr.KeyAssembler"}.AssignNull() } func (_UnixFSData__ReprKeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.AssignBool(false) + return mixins.StringAssembler{TypeName: "data.UnixFSData.Repr.KeyAssembler"}.AssignBool(false) } func (_UnixFSData__ReprKeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.AssignInt(0) + return mixins.StringAssembler{TypeName: "data.UnixFSData.Repr.KeyAssembler"}.AssignInt(0) } func (_UnixFSData__ReprKeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.AssignFloat(0) + return mixins.StringAssembler{TypeName: "data.UnixFSData.Repr.KeyAssembler"}.AssignFloat(0) } func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { if ka.state != maState_midKey { @@ -2656,7 +2673,7 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { } switch k { case "DataType": - if ka.s & fieldBit__UnixFSData_DataType != 0 { + if ka.s&fieldBit__UnixFSData_DataType != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_DataType_serial} } ka.s += fieldBit__UnixFSData_DataType @@ -2664,7 +2681,7 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { ka.f = 0 return nil case "Data": - if ka.s & fieldBit__UnixFSData_Data != 0 { + if ka.s&fieldBit__UnixFSData_Data != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Data_serial} } ka.s += fieldBit__UnixFSData_Data @@ -2672,7 +2689,7 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { ka.f = 1 return nil case "FileSize": - if ka.s & fieldBit__UnixFSData_FileSize != 0 { + if ka.s&fieldBit__UnixFSData_FileSize != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_FileSize_serial} } ka.s += fieldBit__UnixFSData_FileSize @@ -2680,7 +2697,7 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { ka.f = 2 return nil case "BlockSizes": - if ka.s & fieldBit__UnixFSData_BlockSizes != 0 { + if ka.s&fieldBit__UnixFSData_BlockSizes != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_BlockSizes_serial} } ka.s += fieldBit__UnixFSData_BlockSizes @@ -2688,7 +2705,7 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { ka.f = 3 return nil case "HashType": - if ka.s & fieldBit__UnixFSData_HashType != 0 { + if ka.s&fieldBit__UnixFSData_HashType != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_HashType_serial} } ka.s += fieldBit__UnixFSData_HashType @@ -2696,7 +2713,7 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { ka.f = 4 return nil case "Fanout": - if ka.s & fieldBit__UnixFSData_Fanout != 0 { + if ka.s&fieldBit__UnixFSData_Fanout != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Fanout_serial} } ka.s += fieldBit__UnixFSData_Fanout @@ -2704,7 +2721,7 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { ka.f = 5 return nil case "Mode": - if ka.s & fieldBit__UnixFSData_Mode != 0 { + if ka.s&fieldBit__UnixFSData_Mode != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mode_serial} } ka.s += fieldBit__UnixFSData_Mode @@ -2712,7 +2729,7 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { ka.f = 6 return nil case "Mtime": - if ka.s & fieldBit__UnixFSData_Mtime != 0 { + if ka.s&fieldBit__UnixFSData_Mtime != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSData_Mtime_serial} } ka.s += fieldBit__UnixFSData_Mtime @@ -2720,13 +2737,13 @@ func (ka *_UnixFSData__ReprKeyAssembler) AssignString(k string) error { ka.f = 7 return nil } - return ipld.ErrInvalidKey{TypeName:"data.UnixFSData.Repr", Key:&_String{k}} + return ipld.ErrInvalidKey{TypeName: "data.UnixFSData.Repr", Key: &_String{k}} } func (_UnixFSData__ReprKeyAssembler) AssignBytes([]byte) error { - return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.AssignBytes(nil) + return mixins.StringAssembler{TypeName: "data.UnixFSData.Repr.KeyAssembler"}.AssignBytes(nil) } func (_UnixFSData__ReprKeyAssembler) AssignLink(ipld.Link) error { - return mixins.StringAssembler{"data.UnixFSData.Repr.KeyAssembler"}.AssignLink(nil) + return mixins.StringAssembler{TypeName: "data.UnixFSData.Repr.KeyAssembler"}.AssignLink(nil) } func (ka *_UnixFSData__ReprKeyAssembler) AssignNode(v ipld.Node) error { if v2, err := v.AsString(); err != nil { @@ -2739,10 +2756,10 @@ func (_UnixFSData__ReprKeyAssembler) Prototype() ipld.NodePrototype { return _String__Prototype{} } - func (n _UnixFSMetadata) FieldMimeType() MaybeString { return &n.MimeType } + type _UnixFSMetadata__Maybe struct { m schema.Maybe v UnixFSMetadata @@ -2760,14 +2777,14 @@ func (m MaybeUnixFSMetadata) Exists() bool { } func (m MaybeUnixFSMetadata) AsNode() ipld.Node { switch m.m { - case schema.Maybe_Absent: - return ipld.Absent - case schema.Maybe_Null: - return ipld.Null - case schema.Maybe_Value: - return m.v - default: - panic("unreachable") + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") } } func (m MaybeUnixFSMetadata) Must() UnixFSMetadata { @@ -2776,11 +2793,13 @@ func (m MaybeUnixFSMetadata) Must() UnixFSMetadata { } return m.v } + var ( fieldName__UnixFSMetadata_MimeType = _String{"MimeType"} ) var _ ipld.Node = (UnixFSMetadata)(&_UnixFSMetadata{}) var _ schema.TypedNode = (UnixFSMetadata)(&_UnixFSMetadata{}) + func (UnixFSMetadata) Kind() ipld.Kind { return ipld.Kind_Map } @@ -2790,7 +2809,7 @@ func (n UnixFSMetadata) LookupByString(key string) (ipld.Node, error) { if n.MimeType.m == schema.Maybe_Absent { return ipld.Absent, nil } - return n.MimeType.v, nil + return &n.MimeType.v, nil default: return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} } @@ -2803,7 +2822,7 @@ func (n UnixFSMetadata) LookupByNode(key ipld.Node) (ipld.Node, error) { return n.LookupByString(ks) } func (UnixFSMetadata) LookupByIndex(idx int64) (ipld.Node, error) { - return mixins.Map{"data.UnixFSMetadata"}.LookupByIndex(0) + return mixins.Map{TypeName: "data.UnixFSMetadata"}.LookupByIndex(0) } func (n UnixFSMetadata) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { return n.LookupByString(seg.String()) @@ -2813,11 +2832,12 @@ func (n UnixFSMetadata) MapIterator() ipld.MapIterator { } type _UnixFSMetadata__MapItr struct { - n UnixFSMetadata - idx int + n UnixFSMetadata + idx int } -func (itr *_UnixFSMetadata__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) {if itr.idx >= 1 { +func (itr *_UnixFSMetadata__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) { + if itr.idx >= 1 { return nil, nil, ipld.ErrIteratorOverread{} } switch itr.idx { @@ -2827,7 +2847,7 @@ func (itr *_UnixFSMetadata__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) { v = ipld.Absent break } - v = itr.n.MimeType.v + v = &itr.n.MimeType.v default: panic("unreachable") } @@ -2851,26 +2871,27 @@ func (UnixFSMetadata) IsNull() bool { return false } func (UnixFSMetadata) AsBool() (bool, error) { - return mixins.Map{"data.UnixFSMetadata"}.AsBool() + return mixins.Map{TypeName: "data.UnixFSMetadata"}.AsBool() } func (UnixFSMetadata) AsInt() (int64, error) { - return mixins.Map{"data.UnixFSMetadata"}.AsInt() + return mixins.Map{TypeName: "data.UnixFSMetadata"}.AsInt() } func (UnixFSMetadata) AsFloat() (float64, error) { - return mixins.Map{"data.UnixFSMetadata"}.AsFloat() + return mixins.Map{TypeName: "data.UnixFSMetadata"}.AsFloat() } func (UnixFSMetadata) AsString() (string, error) { - return mixins.Map{"data.UnixFSMetadata"}.AsString() + return mixins.Map{TypeName: "data.UnixFSMetadata"}.AsString() } func (UnixFSMetadata) AsBytes() ([]byte, error) { - return mixins.Map{"data.UnixFSMetadata"}.AsBytes() + return mixins.Map{TypeName: "data.UnixFSMetadata"}.AsBytes() } func (UnixFSMetadata) AsLink() (ipld.Link, error) { - return mixins.Map{"data.UnixFSMetadata"}.AsLink() + return mixins.Map{TypeName: "data.UnixFSMetadata"}.AsLink() } func (UnixFSMetadata) Prototype() ipld.NodePrototype { return _UnixFSMetadata__Prototype{} } + type _UnixFSMetadata__Prototype struct{} func (_UnixFSMetadata__Prototype) NewBuilder() ipld.NodeBuilder { @@ -2878,9 +2899,11 @@ func (_UnixFSMetadata__Prototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } + type _UnixFSMetadata__Builder struct { _UnixFSMetadata__Assembler } + func (nb *_UnixFSMetadata__Builder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -2892,16 +2915,17 @@ func (nb *_UnixFSMetadata__Builder) Reset() { var m schema.Maybe *nb = _UnixFSMetadata__Builder{_UnixFSMetadata__Assembler{w: &w, m: &m}} } + type _UnixFSMetadata__Assembler struct { - w *_UnixFSMetadata - m *schema.Maybe + w *_UnixFSMetadata + m *schema.Maybe state maState - s int - f int + s int + f int - cm schema.Maybe + cm schema.Maybe ca_MimeType _String__Assembler - } +} func (na *_UnixFSMetadata__Assembler) reset() { na.state = maState_initial @@ -2910,9 +2934,10 @@ func (na *_UnixFSMetadata__Assembler) reset() { } var ( - fieldBit__UnixFSMetadata_MimeType = 1 << 0 + fieldBit__UnixFSMetadata_MimeType = 1 << 0 fieldBits__UnixFSMetadata_sufficient = 0 ) + func (na *_UnixFSMetadata__Assembler) BeginMap(int64) (ipld.MapAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: @@ -2927,7 +2952,7 @@ func (na *_UnixFSMetadata__Assembler) BeginMap(int64) (ipld.MapAssembler, error) return na, nil } func (_UnixFSMetadata__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.MapAssembler{"data.UnixFSMetadata"}.BeginList(0) + return mixins.MapAssembler{TypeName: "data.UnixFSMetadata"}.BeginList(0) } func (na *_UnixFSMetadata__Assembler) AssignNull() error { switch *na.m { @@ -2935,7 +2960,7 @@ func (na *_UnixFSMetadata__Assembler) AssignNull() error { *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.MapAssembler{"data.UnixFSMetadata"}.AssignNull() + return mixins.MapAssembler{TypeName: "data.UnixFSMetadata"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -2944,22 +2969,22 @@ func (na *_UnixFSMetadata__Assembler) AssignNull() error { panic("unreachable") } func (_UnixFSMetadata__Assembler) AssignBool(bool) error { - return mixins.MapAssembler{"data.UnixFSMetadata"}.AssignBool(false) + return mixins.MapAssembler{TypeName: "data.UnixFSMetadata"}.AssignBool(false) } func (_UnixFSMetadata__Assembler) AssignInt(int64) error { - return mixins.MapAssembler{"data.UnixFSMetadata"}.AssignInt(0) + return mixins.MapAssembler{TypeName: "data.UnixFSMetadata"}.AssignInt(0) } func (_UnixFSMetadata__Assembler) AssignFloat(float64) error { - return mixins.MapAssembler{"data.UnixFSMetadata"}.AssignFloat(0) + return mixins.MapAssembler{TypeName: "data.UnixFSMetadata"}.AssignFloat(0) } func (_UnixFSMetadata__Assembler) AssignString(string) error { - return mixins.MapAssembler{"data.UnixFSMetadata"}.AssignString("") + return mixins.MapAssembler{TypeName: "data.UnixFSMetadata"}.AssignString("") } func (_UnixFSMetadata__Assembler) AssignBytes([]byte) error { - return mixins.MapAssembler{"data.UnixFSMetadata"}.AssignBytes(nil) + return mixins.MapAssembler{TypeName: "data.UnixFSMetadata"}.AssignBytes(nil) } func (_UnixFSMetadata__Assembler) AssignLink(ipld.Link) error { - return mixins.MapAssembler{"data.UnixFSMetadata"}.AssignLink(nil) + return mixins.MapAssembler{TypeName: "data.UnixFSMetadata"}.AssignLink(nil) } func (na *_UnixFSMetadata__Assembler) AssignNode(v ipld.Node) error { if v.IsNull() { @@ -3007,7 +3032,6 @@ func (ma *_UnixFSMetadata__Assembler) valueFinishTidy() bool { case 0: switch ma.w.MimeType.m { case schema.Maybe_Value: - ma.w.MimeType.v = ma.ca_MimeType.w ma.state = maState_initial return true default: @@ -3034,17 +3058,17 @@ func (ma *_UnixFSMetadata__Assembler) AssembleEntry(k string) (ipld.NodeAssemble } switch k { case "MimeType": - if ma.s & fieldBit__UnixFSMetadata_MimeType != 0 { + if ma.s&fieldBit__UnixFSMetadata_MimeType != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSMetadata_MimeType} } ma.s += fieldBit__UnixFSMetadata_MimeType ma.state = maState_midValue ma.f = 0 - ma.ca_MimeType.w = ma.w.MimeType.v + ma.ca_MimeType.w = &ma.w.MimeType.v ma.ca_MimeType.m = &ma.w.MimeType.m return &ma.ca_MimeType, nil } - return nil, ipld.ErrInvalidKey{TypeName:"data.UnixFSMetadata", Key:&_String{k}} + return nil, ipld.ErrInvalidKey{TypeName: "data.UnixFSMetadata", Key: &_String{k}} } func (ma *_UnixFSMetadata__Assembler) AssembleKey() ipld.NodeAssembler { switch ma.state { @@ -3080,7 +3104,7 @@ func (ma *_UnixFSMetadata__Assembler) AssembleValue() ipld.NodeAssembler { ma.state = maState_midValue switch ma.f { case 0: - ma.ca_MimeType.w = ma.w.MimeType.v + ma.ca_MimeType.w = &ma.w.MimeType.v ma.ca_MimeType.m = &ma.w.MimeType.m return &ma.ca_MimeType default: @@ -3102,7 +3126,7 @@ func (ma *_UnixFSMetadata__Assembler) Finish() error { case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } - if ma.s & fieldBits__UnixFSMetadata_sufficient != fieldBits__UnixFSMetadata_sufficient { + if ma.s&fieldBits__UnixFSMetadata_sufficient != fieldBits__UnixFSMetadata_sufficient { err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} return err } @@ -3116,24 +3140,26 @@ func (ma *_UnixFSMetadata__Assembler) KeyPrototype() ipld.NodePrototype { func (ma *_UnixFSMetadata__Assembler) ValuePrototype(k string) ipld.NodePrototype { panic("todo structbuilder mapassembler valueprototype") } + type _UnixFSMetadata__KeyAssembler _UnixFSMetadata__Assembler + func (_UnixFSMetadata__KeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { - return mixins.StringAssembler{"data.UnixFSMetadata.KeyAssembler"}.BeginMap(0) + return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.KeyAssembler"}.BeginMap(0) } func (_UnixFSMetadata__KeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.StringAssembler{"data.UnixFSMetadata.KeyAssembler"}.BeginList(0) + return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.KeyAssembler"}.BeginList(0) } func (na *_UnixFSMetadata__KeyAssembler) AssignNull() error { - return mixins.StringAssembler{"data.UnixFSMetadata.KeyAssembler"}.AssignNull() + return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.KeyAssembler"}.AssignNull() } func (_UnixFSMetadata__KeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{"data.UnixFSMetadata.KeyAssembler"}.AssignBool(false) + return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.KeyAssembler"}.AssignBool(false) } func (_UnixFSMetadata__KeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{"data.UnixFSMetadata.KeyAssembler"}.AssignInt(0) + return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.KeyAssembler"}.AssignInt(0) } func (_UnixFSMetadata__KeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{"data.UnixFSMetadata.KeyAssembler"}.AssignFloat(0) + return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.KeyAssembler"}.AssignFloat(0) } func (ka *_UnixFSMetadata__KeyAssembler) AssignString(k string) error { if ka.state != maState_midKey { @@ -3141,22 +3167,22 @@ func (ka *_UnixFSMetadata__KeyAssembler) AssignString(k string) error { } switch k { case "MimeType": - if ka.s & fieldBit__UnixFSMetadata_MimeType != 0 { + if ka.s&fieldBit__UnixFSMetadata_MimeType != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSMetadata_MimeType} } ka.s += fieldBit__UnixFSMetadata_MimeType ka.state = maState_expectValue ka.f = 0 default: - return ipld.ErrInvalidKey{TypeName:"data.UnixFSMetadata", Key:&_String{k}} + return ipld.ErrInvalidKey{TypeName: "data.UnixFSMetadata", Key: &_String{k}} } return nil } func (_UnixFSMetadata__KeyAssembler) AssignBytes([]byte) error { - return mixins.StringAssembler{"data.UnixFSMetadata.KeyAssembler"}.AssignBytes(nil) + return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.KeyAssembler"}.AssignBytes(nil) } func (_UnixFSMetadata__KeyAssembler) AssignLink(ipld.Link) error { - return mixins.StringAssembler{"data.UnixFSMetadata.KeyAssembler"}.AssignLink(nil) + return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.KeyAssembler"}.AssignLink(nil) } func (ka *_UnixFSMetadata__KeyAssembler) AssignNode(v ipld.Node) error { if v2, err := v.AsString(); err != nil { @@ -3174,11 +3200,14 @@ func (UnixFSMetadata) Type() schema.Type { func (n UnixFSMetadata) Representation() ipld.Node { return (*_UnixFSMetadata__Repr)(n) } + type _UnixFSMetadata__Repr _UnixFSMetadata + var ( fieldName__UnixFSMetadata_MimeType_serial = _String{"MimeType"} ) var _ ipld.Node = &_UnixFSMetadata__Repr{} + func (_UnixFSMetadata__Repr) Kind() ipld.Kind { return ipld.Kind_Map } @@ -3201,7 +3230,7 @@ func (n *_UnixFSMetadata__Repr) LookupByNode(key ipld.Node) (ipld.Node, error) { return n.LookupByString(ks) } func (_UnixFSMetadata__Repr) LookupByIndex(idx int64) (ipld.Node, error) { - return mixins.Map{"data.UnixFSMetadata.Repr"}.LookupByIndex(0) + return mixins.Map{TypeName: "data.UnixFSMetadata.Repr"}.LookupByIndex(0) } func (n _UnixFSMetadata__Repr) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { return n.LookupByString(seg.String()) @@ -3223,7 +3252,9 @@ type _UnixFSMetadata__ReprMapItr struct { end int } -func (itr *_UnixFSMetadata__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) {advance:if itr.idx >= 1 { +func (itr *_UnixFSMetadata__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) { +advance: + if itr.idx >= 1 { return nil, nil, ipld.ErrIteratorOverread{} } switch itr.idx { @@ -3260,26 +3291,27 @@ func (_UnixFSMetadata__Repr) IsNull() bool { return false } func (_UnixFSMetadata__Repr) AsBool() (bool, error) { - return mixins.Map{"data.UnixFSMetadata.Repr"}.AsBool() + return mixins.Map{TypeName: "data.UnixFSMetadata.Repr"}.AsBool() } func (_UnixFSMetadata__Repr) AsInt() (int64, error) { - return mixins.Map{"data.UnixFSMetadata.Repr"}.AsInt() + return mixins.Map{TypeName: "data.UnixFSMetadata.Repr"}.AsInt() } func (_UnixFSMetadata__Repr) AsFloat() (float64, error) { - return mixins.Map{"data.UnixFSMetadata.Repr"}.AsFloat() + return mixins.Map{TypeName: "data.UnixFSMetadata.Repr"}.AsFloat() } func (_UnixFSMetadata__Repr) AsString() (string, error) { - return mixins.Map{"data.UnixFSMetadata.Repr"}.AsString() + return mixins.Map{TypeName: "data.UnixFSMetadata.Repr"}.AsString() } func (_UnixFSMetadata__Repr) AsBytes() ([]byte, error) { - return mixins.Map{"data.UnixFSMetadata.Repr"}.AsBytes() + return mixins.Map{TypeName: "data.UnixFSMetadata.Repr"}.AsBytes() } func (_UnixFSMetadata__Repr) AsLink() (ipld.Link, error) { - return mixins.Map{"data.UnixFSMetadata.Repr"}.AsLink() + return mixins.Map{TypeName: "data.UnixFSMetadata.Repr"}.AsLink() } func (_UnixFSMetadata__Repr) Prototype() ipld.NodePrototype { return _UnixFSMetadata__ReprPrototype{} } + type _UnixFSMetadata__ReprPrototype struct{} func (_UnixFSMetadata__ReprPrototype) NewBuilder() ipld.NodeBuilder { @@ -3287,9 +3319,11 @@ func (_UnixFSMetadata__ReprPrototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } + type _UnixFSMetadata__ReprBuilder struct { _UnixFSMetadata__ReprAssembler } + func (nb *_UnixFSMetadata__ReprBuilder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -3301,16 +3335,17 @@ func (nb *_UnixFSMetadata__ReprBuilder) Reset() { var m schema.Maybe *nb = _UnixFSMetadata__ReprBuilder{_UnixFSMetadata__ReprAssembler{w: &w, m: &m}} } + type _UnixFSMetadata__ReprAssembler struct { - w *_UnixFSMetadata - m *schema.Maybe + w *_UnixFSMetadata + m *schema.Maybe state maState - s int - f int + s int + f int - cm schema.Maybe + cm schema.Maybe ca_MimeType _String__ReprAssembler - } +} func (na *_UnixFSMetadata__ReprAssembler) reset() { na.state = maState_initial @@ -3331,7 +3366,7 @@ func (na *_UnixFSMetadata__ReprAssembler) BeginMap(int64) (ipld.MapAssembler, er return na, nil } func (_UnixFSMetadata__ReprAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.MapAssembler{"data.UnixFSMetadata.Repr"}.BeginList(0) + return mixins.MapAssembler{TypeName: "data.UnixFSMetadata.Repr"}.BeginList(0) } func (na *_UnixFSMetadata__ReprAssembler) AssignNull() error { switch *na.m { @@ -3339,7 +3374,7 @@ func (na *_UnixFSMetadata__ReprAssembler) AssignNull() error { *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.MapAssembler{"data.UnixFSMetadata.Repr.Repr"}.AssignNull() + return mixins.MapAssembler{TypeName: "data.UnixFSMetadata.Repr.Repr"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -3348,22 +3383,22 @@ func (na *_UnixFSMetadata__ReprAssembler) AssignNull() error { panic("unreachable") } func (_UnixFSMetadata__ReprAssembler) AssignBool(bool) error { - return mixins.MapAssembler{"data.UnixFSMetadata.Repr"}.AssignBool(false) + return mixins.MapAssembler{TypeName: "data.UnixFSMetadata.Repr"}.AssignBool(false) } func (_UnixFSMetadata__ReprAssembler) AssignInt(int64) error { - return mixins.MapAssembler{"data.UnixFSMetadata.Repr"}.AssignInt(0) + return mixins.MapAssembler{TypeName: "data.UnixFSMetadata.Repr"}.AssignInt(0) } func (_UnixFSMetadata__ReprAssembler) AssignFloat(float64) error { - return mixins.MapAssembler{"data.UnixFSMetadata.Repr"}.AssignFloat(0) + return mixins.MapAssembler{TypeName: "data.UnixFSMetadata.Repr"}.AssignFloat(0) } func (_UnixFSMetadata__ReprAssembler) AssignString(string) error { - return mixins.MapAssembler{"data.UnixFSMetadata.Repr"}.AssignString("") + return mixins.MapAssembler{TypeName: "data.UnixFSMetadata.Repr"}.AssignString("") } func (_UnixFSMetadata__ReprAssembler) AssignBytes([]byte) error { - return mixins.MapAssembler{"data.UnixFSMetadata.Repr"}.AssignBytes(nil) + return mixins.MapAssembler{TypeName: "data.UnixFSMetadata.Repr"}.AssignBytes(nil) } func (_UnixFSMetadata__ReprAssembler) AssignLink(ipld.Link) error { - return mixins.MapAssembler{"data.UnixFSMetadata.Repr"}.AssignLink(nil) + return mixins.MapAssembler{TypeName: "data.UnixFSMetadata.Repr"}.AssignLink(nil) } func (na *_UnixFSMetadata__ReprAssembler) AssignNode(v ipld.Node) error { if v.IsNull() { @@ -3411,7 +3446,6 @@ func (ma *_UnixFSMetadata__ReprAssembler) valueFinishTidy() bool { case 0: switch ma.w.MimeType.m { case schema.Maybe_Value: - ma.w.MimeType.v = ma.ca_MimeType.w ma.state = maState_initial return true default: @@ -3438,19 +3472,19 @@ func (ma *_UnixFSMetadata__ReprAssembler) AssembleEntry(k string) (ipld.NodeAsse } switch k { case "MimeType": - if ma.s & fieldBit__UnixFSMetadata_MimeType != 0 { + if ma.s&fieldBit__UnixFSMetadata_MimeType != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSMetadata_MimeType_serial} } ma.s += fieldBit__UnixFSMetadata_MimeType ma.state = maState_midValue ma.f = 0 - ma.ca_MimeType.w = ma.w.MimeType.v + ma.ca_MimeType.w = &ma.w.MimeType.v ma.ca_MimeType.m = &ma.w.MimeType.m - + return &ma.ca_MimeType, nil default: } - return nil, ipld.ErrInvalidKey{TypeName:"data.UnixFSMetadata.Repr", Key:&_String{k}} + return nil, ipld.ErrInvalidKey{TypeName: "data.UnixFSMetadata.Repr", Key: &_String{k}} } func (ma *_UnixFSMetadata__ReprAssembler) AssembleKey() ipld.NodeAssembler { switch ma.state { @@ -3486,9 +3520,9 @@ func (ma *_UnixFSMetadata__ReprAssembler) AssembleValue() ipld.NodeAssembler { ma.state = maState_midValue switch ma.f { case 0: - ma.ca_MimeType.w = ma.w.MimeType.v + ma.ca_MimeType.w = &ma.w.MimeType.v ma.ca_MimeType.m = &ma.w.MimeType.m - + return &ma.ca_MimeType default: panic("unreachable") @@ -3509,7 +3543,7 @@ func (ma *_UnixFSMetadata__ReprAssembler) Finish() error { case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } - if ma.s & fieldBits__UnixFSMetadata_sufficient != fieldBits__UnixFSMetadata_sufficient { + if ma.s&fieldBits__UnixFSMetadata_sufficient != fieldBits__UnixFSMetadata_sufficient { err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} return err } @@ -3523,24 +3557,26 @@ func (ma *_UnixFSMetadata__ReprAssembler) KeyPrototype() ipld.NodePrototype { func (ma *_UnixFSMetadata__ReprAssembler) ValuePrototype(k string) ipld.NodePrototype { panic("todo structbuilder mapassembler repr valueprototype") } + type _UnixFSMetadata__ReprKeyAssembler _UnixFSMetadata__ReprAssembler + func (_UnixFSMetadata__ReprKeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { - return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.BeginMap(0) + return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.Repr.KeyAssembler"}.BeginMap(0) } func (_UnixFSMetadata__ReprKeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.BeginList(0) + return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.Repr.KeyAssembler"}.BeginList(0) } func (na *_UnixFSMetadata__ReprKeyAssembler) AssignNull() error { - return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.AssignNull() + return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.Repr.KeyAssembler"}.AssignNull() } func (_UnixFSMetadata__ReprKeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.AssignBool(false) + return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.Repr.KeyAssembler"}.AssignBool(false) } func (_UnixFSMetadata__ReprKeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.AssignInt(0) + return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.Repr.KeyAssembler"}.AssignInt(0) } func (_UnixFSMetadata__ReprKeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.AssignFloat(0) + return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.Repr.KeyAssembler"}.AssignFloat(0) } func (ka *_UnixFSMetadata__ReprKeyAssembler) AssignString(k string) error { if ka.state != maState_midKey { @@ -3548,7 +3584,7 @@ func (ka *_UnixFSMetadata__ReprKeyAssembler) AssignString(k string) error { } switch k { case "MimeType": - if ka.s & fieldBit__UnixFSMetadata_MimeType != 0 { + if ka.s&fieldBit__UnixFSMetadata_MimeType != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixFSMetadata_MimeType_serial} } ka.s += fieldBit__UnixFSMetadata_MimeType @@ -3556,13 +3592,13 @@ func (ka *_UnixFSMetadata__ReprKeyAssembler) AssignString(k string) error { ka.f = 0 return nil } - return ipld.ErrInvalidKey{TypeName:"data.UnixFSMetadata.Repr", Key:&_String{k}} + return ipld.ErrInvalidKey{TypeName: "data.UnixFSMetadata.Repr", Key: &_String{k}} } func (_UnixFSMetadata__ReprKeyAssembler) AssignBytes([]byte) error { - return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.AssignBytes(nil) + return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.Repr.KeyAssembler"}.AssignBytes(nil) } func (_UnixFSMetadata__ReprKeyAssembler) AssignLink(ipld.Link) error { - return mixins.StringAssembler{"data.UnixFSMetadata.Repr.KeyAssembler"}.AssignLink(nil) + return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.Repr.KeyAssembler"}.AssignLink(nil) } func (ka *_UnixFSMetadata__ReprKeyAssembler) AssignNode(v ipld.Node) error { if v2, err := v.AsString(); err != nil { @@ -3575,13 +3611,13 @@ func (_UnixFSMetadata__ReprKeyAssembler) Prototype() ipld.NodePrototype { return _String__Prototype{} } - func (n _UnixTime) FieldSeconds() Int { return &n.Seconds } func (n _UnixTime) FieldFractionalNanoseconds() MaybeInt { return &n.FractionalNanoseconds } + type _UnixTime__Maybe struct { m schema.Maybe v UnixTime @@ -3599,14 +3635,14 @@ func (m MaybeUnixTime) Exists() bool { } func (m MaybeUnixTime) AsNode() ipld.Node { switch m.m { - case schema.Maybe_Absent: - return ipld.Absent - case schema.Maybe_Null: - return ipld.Null - case schema.Maybe_Value: - return m.v - default: - panic("unreachable") + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") } } func (m MaybeUnixTime) Must() UnixTime { @@ -3615,12 +3651,14 @@ func (m MaybeUnixTime) Must() UnixTime { } return m.v } + var ( - fieldName__UnixTime_Seconds = _String{"Seconds"} + fieldName__UnixTime_Seconds = _String{"Seconds"} fieldName__UnixTime_FractionalNanoseconds = _String{"FractionalNanoseconds"} ) var _ ipld.Node = (UnixTime)(&_UnixTime{}) var _ schema.TypedNode = (UnixTime)(&_UnixTime{}) + func (UnixTime) Kind() ipld.Kind { return ipld.Kind_Map } @@ -3632,7 +3670,7 @@ func (n UnixTime) LookupByString(key string) (ipld.Node, error) { if n.FractionalNanoseconds.m == schema.Maybe_Absent { return ipld.Absent, nil } - return n.FractionalNanoseconds.v, nil + return &n.FractionalNanoseconds.v, nil default: return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} } @@ -3645,7 +3683,7 @@ func (n UnixTime) LookupByNode(key ipld.Node) (ipld.Node, error) { return n.LookupByString(ks) } func (UnixTime) LookupByIndex(idx int64) (ipld.Node, error) { - return mixins.Map{"data.UnixTime"}.LookupByIndex(0) + return mixins.Map{TypeName: "data.UnixTime"}.LookupByIndex(0) } func (n UnixTime) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { return n.LookupByString(seg.String()) @@ -3655,11 +3693,12 @@ func (n UnixTime) MapIterator() ipld.MapIterator { } type _UnixTime__MapItr struct { - n UnixTime - idx int + n UnixTime + idx int } -func (itr *_UnixTime__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) {if itr.idx >= 2 { +func (itr *_UnixTime__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) { + if itr.idx >= 2 { return nil, nil, ipld.ErrIteratorOverread{} } switch itr.idx { @@ -3672,7 +3711,7 @@ func (itr *_UnixTime__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) {if itr v = ipld.Absent break } - v = itr.n.FractionalNanoseconds.v + v = &itr.n.FractionalNanoseconds.v default: panic("unreachable") } @@ -3696,26 +3735,27 @@ func (UnixTime) IsNull() bool { return false } func (UnixTime) AsBool() (bool, error) { - return mixins.Map{"data.UnixTime"}.AsBool() + return mixins.Map{TypeName: "data.UnixTime"}.AsBool() } func (UnixTime) AsInt() (int64, error) { - return mixins.Map{"data.UnixTime"}.AsInt() + return mixins.Map{TypeName: "data.UnixTime"}.AsInt() } func (UnixTime) AsFloat() (float64, error) { - return mixins.Map{"data.UnixTime"}.AsFloat() + return mixins.Map{TypeName: "data.UnixTime"}.AsFloat() } func (UnixTime) AsString() (string, error) { - return mixins.Map{"data.UnixTime"}.AsString() + return mixins.Map{TypeName: "data.UnixTime"}.AsString() } func (UnixTime) AsBytes() ([]byte, error) { - return mixins.Map{"data.UnixTime"}.AsBytes() + return mixins.Map{TypeName: "data.UnixTime"}.AsBytes() } func (UnixTime) AsLink() (ipld.Link, error) { - return mixins.Map{"data.UnixTime"}.AsLink() + return mixins.Map{TypeName: "data.UnixTime"}.AsLink() } func (UnixTime) Prototype() ipld.NodePrototype { return _UnixTime__Prototype{} } + type _UnixTime__Prototype struct{} func (_UnixTime__Prototype) NewBuilder() ipld.NodeBuilder { @@ -3723,9 +3763,11 @@ func (_UnixTime__Prototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } + type _UnixTime__Builder struct { _UnixTime__Assembler } + func (nb *_UnixTime__Builder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -3737,17 +3779,18 @@ func (nb *_UnixTime__Builder) Reset() { var m schema.Maybe *nb = _UnixTime__Builder{_UnixTime__Assembler{w: &w, m: &m}} } + type _UnixTime__Assembler struct { - w *_UnixTime - m *schema.Maybe + w *_UnixTime + m *schema.Maybe state maState - s int - f int + s int + f int - cm schema.Maybe - ca_Seconds _Int__Assembler + cm schema.Maybe + ca_Seconds _Int__Assembler ca_FractionalNanoseconds _Int__Assembler - } +} func (na *_UnixTime__Assembler) reset() { na.state = maState_initial @@ -3757,10 +3800,11 @@ func (na *_UnixTime__Assembler) reset() { } var ( - fieldBit__UnixTime_Seconds = 1 << 0 + fieldBit__UnixTime_Seconds = 1 << 0 fieldBit__UnixTime_FractionalNanoseconds = 1 << 1 - fieldBits__UnixTime_sufficient = 0 + 1 << 0 + fieldBits__UnixTime_sufficient = 0 + 1<<0 ) + func (na *_UnixTime__Assembler) BeginMap(int64) (ipld.MapAssembler, error) { switch *na.m { case schema.Maybe_Value, schema.Maybe_Null: @@ -3775,7 +3819,7 @@ func (na *_UnixTime__Assembler) BeginMap(int64) (ipld.MapAssembler, error) { return na, nil } func (_UnixTime__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.MapAssembler{"data.UnixTime"}.BeginList(0) + return mixins.MapAssembler{TypeName: "data.UnixTime"}.BeginList(0) } func (na *_UnixTime__Assembler) AssignNull() error { switch *na.m { @@ -3783,7 +3827,7 @@ func (na *_UnixTime__Assembler) AssignNull() error { *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.MapAssembler{"data.UnixTime"}.AssignNull() + return mixins.MapAssembler{TypeName: "data.UnixTime"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -3792,22 +3836,22 @@ func (na *_UnixTime__Assembler) AssignNull() error { panic("unreachable") } func (_UnixTime__Assembler) AssignBool(bool) error { - return mixins.MapAssembler{"data.UnixTime"}.AssignBool(false) + return mixins.MapAssembler{TypeName: "data.UnixTime"}.AssignBool(false) } func (_UnixTime__Assembler) AssignInt(int64) error { - return mixins.MapAssembler{"data.UnixTime"}.AssignInt(0) + return mixins.MapAssembler{TypeName: "data.UnixTime"}.AssignInt(0) } func (_UnixTime__Assembler) AssignFloat(float64) error { - return mixins.MapAssembler{"data.UnixTime"}.AssignFloat(0) + return mixins.MapAssembler{TypeName: "data.UnixTime"}.AssignFloat(0) } func (_UnixTime__Assembler) AssignString(string) error { - return mixins.MapAssembler{"data.UnixTime"}.AssignString("") + return mixins.MapAssembler{TypeName: "data.UnixTime"}.AssignString("") } func (_UnixTime__Assembler) AssignBytes([]byte) error { - return mixins.MapAssembler{"data.UnixTime"}.AssignBytes(nil) + return mixins.MapAssembler{TypeName: "data.UnixTime"}.AssignBytes(nil) } func (_UnixTime__Assembler) AssignLink(ipld.Link) error { - return mixins.MapAssembler{"data.UnixTime"}.AssignLink(nil) + return mixins.MapAssembler{TypeName: "data.UnixTime"}.AssignLink(nil) } func (na *_UnixTime__Assembler) AssignNode(v ipld.Node) error { if v.IsNull() { @@ -3865,7 +3909,6 @@ func (ma *_UnixTime__Assembler) valueFinishTidy() bool { case 1: switch ma.w.FractionalNanoseconds.m { case schema.Maybe_Value: - ma.w.FractionalNanoseconds.v = ma.ca_FractionalNanoseconds.w ma.state = maState_initial return true default: @@ -3892,7 +3935,7 @@ func (ma *_UnixTime__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, err } switch k { case "Seconds": - if ma.s & fieldBit__UnixTime_Seconds != 0 { + if ma.s&fieldBit__UnixTime_Seconds != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_Seconds} } ma.s += fieldBit__UnixTime_Seconds @@ -3902,17 +3945,17 @@ func (ma *_UnixTime__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, err ma.ca_Seconds.m = &ma.cm return &ma.ca_Seconds, nil case "FractionalNanoseconds": - if ma.s & fieldBit__UnixTime_FractionalNanoseconds != 0 { + if ma.s&fieldBit__UnixTime_FractionalNanoseconds != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_FractionalNanoseconds} } ma.s += fieldBit__UnixTime_FractionalNanoseconds ma.state = maState_midValue ma.f = 1 - ma.ca_FractionalNanoseconds.w = ma.w.FractionalNanoseconds.v + ma.ca_FractionalNanoseconds.w = &ma.w.FractionalNanoseconds.v ma.ca_FractionalNanoseconds.m = &ma.w.FractionalNanoseconds.m return &ma.ca_FractionalNanoseconds, nil } - return nil, ipld.ErrInvalidKey{TypeName:"data.UnixTime", Key:&_String{k}} + return nil, ipld.ErrInvalidKey{TypeName: "data.UnixTime", Key: &_String{k}} } func (ma *_UnixTime__Assembler) AssembleKey() ipld.NodeAssembler { switch ma.state { @@ -3952,7 +3995,7 @@ func (ma *_UnixTime__Assembler) AssembleValue() ipld.NodeAssembler { ma.ca_Seconds.m = &ma.cm return &ma.ca_Seconds case 1: - ma.ca_FractionalNanoseconds.w = ma.w.FractionalNanoseconds.v + ma.ca_FractionalNanoseconds.w = &ma.w.FractionalNanoseconds.v ma.ca_FractionalNanoseconds.m = &ma.w.FractionalNanoseconds.m return &ma.ca_FractionalNanoseconds default: @@ -3974,9 +4017,9 @@ func (ma *_UnixTime__Assembler) Finish() error { case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } - if ma.s & fieldBits__UnixTime_sufficient != fieldBits__UnixTime_sufficient { + if ma.s&fieldBits__UnixTime_sufficient != fieldBits__UnixTime_sufficient { err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} - if ma.s & fieldBit__UnixTime_Seconds == 0 { + if ma.s&fieldBit__UnixTime_Seconds == 0 { err.Missing = append(err.Missing, "Seconds") } return err @@ -3991,24 +4034,26 @@ func (ma *_UnixTime__Assembler) KeyPrototype() ipld.NodePrototype { func (ma *_UnixTime__Assembler) ValuePrototype(k string) ipld.NodePrototype { panic("todo structbuilder mapassembler valueprototype") } + type _UnixTime__KeyAssembler _UnixTime__Assembler + func (_UnixTime__KeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { - return mixins.StringAssembler{"data.UnixTime.KeyAssembler"}.BeginMap(0) + return mixins.StringAssembler{TypeName: "data.UnixTime.KeyAssembler"}.BeginMap(0) } func (_UnixTime__KeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.StringAssembler{"data.UnixTime.KeyAssembler"}.BeginList(0) + return mixins.StringAssembler{TypeName: "data.UnixTime.KeyAssembler"}.BeginList(0) } func (na *_UnixTime__KeyAssembler) AssignNull() error { - return mixins.StringAssembler{"data.UnixTime.KeyAssembler"}.AssignNull() + return mixins.StringAssembler{TypeName: "data.UnixTime.KeyAssembler"}.AssignNull() } func (_UnixTime__KeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{"data.UnixTime.KeyAssembler"}.AssignBool(false) + return mixins.StringAssembler{TypeName: "data.UnixTime.KeyAssembler"}.AssignBool(false) } func (_UnixTime__KeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{"data.UnixTime.KeyAssembler"}.AssignInt(0) + return mixins.StringAssembler{TypeName: "data.UnixTime.KeyAssembler"}.AssignInt(0) } func (_UnixTime__KeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{"data.UnixTime.KeyAssembler"}.AssignFloat(0) + return mixins.StringAssembler{TypeName: "data.UnixTime.KeyAssembler"}.AssignFloat(0) } func (ka *_UnixTime__KeyAssembler) AssignString(k string) error { if ka.state != maState_midKey { @@ -4016,29 +4061,29 @@ func (ka *_UnixTime__KeyAssembler) AssignString(k string) error { } switch k { case "Seconds": - if ka.s & fieldBit__UnixTime_Seconds != 0 { + if ka.s&fieldBit__UnixTime_Seconds != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_Seconds} } ka.s += fieldBit__UnixTime_Seconds ka.state = maState_expectValue ka.f = 0 case "FractionalNanoseconds": - if ka.s & fieldBit__UnixTime_FractionalNanoseconds != 0 { + if ka.s&fieldBit__UnixTime_FractionalNanoseconds != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_FractionalNanoseconds} } ka.s += fieldBit__UnixTime_FractionalNanoseconds ka.state = maState_expectValue ka.f = 1 default: - return ipld.ErrInvalidKey{TypeName:"data.UnixTime", Key:&_String{k}} + return ipld.ErrInvalidKey{TypeName: "data.UnixTime", Key: &_String{k}} } return nil } func (_UnixTime__KeyAssembler) AssignBytes([]byte) error { - return mixins.StringAssembler{"data.UnixTime.KeyAssembler"}.AssignBytes(nil) + return mixins.StringAssembler{TypeName: "data.UnixTime.KeyAssembler"}.AssignBytes(nil) } func (_UnixTime__KeyAssembler) AssignLink(ipld.Link) error { - return mixins.StringAssembler{"data.UnixTime.KeyAssembler"}.AssignLink(nil) + return mixins.StringAssembler{TypeName: "data.UnixTime.KeyAssembler"}.AssignLink(nil) } func (ka *_UnixTime__KeyAssembler) AssignNode(v ipld.Node) error { if v2, err := v.AsString(); err != nil { @@ -4056,12 +4101,15 @@ func (UnixTime) Type() schema.Type { func (n UnixTime) Representation() ipld.Node { return (*_UnixTime__Repr)(n) } + type _UnixTime__Repr _UnixTime + var ( - fieldName__UnixTime_Seconds_serial = _String{"Seconds"} + fieldName__UnixTime_Seconds_serial = _String{"Seconds"} fieldName__UnixTime_FractionalNanoseconds_serial = _String{"FractionalNanoseconds"} ) var _ ipld.Node = &_UnixTime__Repr{} + func (_UnixTime__Repr) Kind() ipld.Kind { return ipld.Kind_Map } @@ -4086,7 +4134,7 @@ func (n *_UnixTime__Repr) LookupByNode(key ipld.Node) (ipld.Node, error) { return n.LookupByString(ks) } func (_UnixTime__Repr) LookupByIndex(idx int64) (ipld.Node, error) { - return mixins.Map{"data.UnixTime.Repr"}.LookupByIndex(0) + return mixins.Map{TypeName: "data.UnixTime.Repr"}.LookupByIndex(0) } func (n _UnixTime__Repr) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { return n.LookupByString(seg.String()) @@ -4108,7 +4156,9 @@ type _UnixTime__ReprMapItr struct { end int } -func (itr *_UnixTime__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) {advance:if itr.idx >= 2 { +func (itr *_UnixTime__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) { +advance: + if itr.idx >= 2 { return nil, nil, ipld.ErrIteratorOverread{} } switch itr.idx { @@ -4148,26 +4198,27 @@ func (_UnixTime__Repr) IsNull() bool { return false } func (_UnixTime__Repr) AsBool() (bool, error) { - return mixins.Map{"data.UnixTime.Repr"}.AsBool() + return mixins.Map{TypeName: "data.UnixTime.Repr"}.AsBool() } func (_UnixTime__Repr) AsInt() (int64, error) { - return mixins.Map{"data.UnixTime.Repr"}.AsInt() + return mixins.Map{TypeName: "data.UnixTime.Repr"}.AsInt() } func (_UnixTime__Repr) AsFloat() (float64, error) { - return mixins.Map{"data.UnixTime.Repr"}.AsFloat() + return mixins.Map{TypeName: "data.UnixTime.Repr"}.AsFloat() } func (_UnixTime__Repr) AsString() (string, error) { - return mixins.Map{"data.UnixTime.Repr"}.AsString() + return mixins.Map{TypeName: "data.UnixTime.Repr"}.AsString() } func (_UnixTime__Repr) AsBytes() ([]byte, error) { - return mixins.Map{"data.UnixTime.Repr"}.AsBytes() + return mixins.Map{TypeName: "data.UnixTime.Repr"}.AsBytes() } func (_UnixTime__Repr) AsLink() (ipld.Link, error) { - return mixins.Map{"data.UnixTime.Repr"}.AsLink() + return mixins.Map{TypeName: "data.UnixTime.Repr"}.AsLink() } func (_UnixTime__Repr) Prototype() ipld.NodePrototype { return _UnixTime__ReprPrototype{} } + type _UnixTime__ReprPrototype struct{} func (_UnixTime__ReprPrototype) NewBuilder() ipld.NodeBuilder { @@ -4175,9 +4226,11 @@ func (_UnixTime__ReprPrototype) NewBuilder() ipld.NodeBuilder { nb.Reset() return &nb } + type _UnixTime__ReprBuilder struct { _UnixTime__ReprAssembler } + func (nb *_UnixTime__ReprBuilder) Build() ipld.Node { if *nb.m != schema.Maybe_Value { panic("invalid state: cannot call Build on an assembler that's not finished") @@ -4189,17 +4242,18 @@ func (nb *_UnixTime__ReprBuilder) Reset() { var m schema.Maybe *nb = _UnixTime__ReprBuilder{_UnixTime__ReprAssembler{w: &w, m: &m}} } + type _UnixTime__ReprAssembler struct { - w *_UnixTime - m *schema.Maybe + w *_UnixTime + m *schema.Maybe state maState - s int - f int + s int + f int - cm schema.Maybe - ca_Seconds _Int__ReprAssembler + cm schema.Maybe + ca_Seconds _Int__ReprAssembler ca_FractionalNanoseconds _Int__ReprAssembler - } +} func (na *_UnixTime__ReprAssembler) reset() { na.state = maState_initial @@ -4221,7 +4275,7 @@ func (na *_UnixTime__ReprAssembler) BeginMap(int64) (ipld.MapAssembler, error) { return na, nil } func (_UnixTime__ReprAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.MapAssembler{"data.UnixTime.Repr"}.BeginList(0) + return mixins.MapAssembler{TypeName: "data.UnixTime.Repr"}.BeginList(0) } func (na *_UnixTime__ReprAssembler) AssignNull() error { switch *na.m { @@ -4229,7 +4283,7 @@ func (na *_UnixTime__ReprAssembler) AssignNull() error { *na.m = schema.Maybe_Null return nil case schema.Maybe_Absent: - return mixins.MapAssembler{"data.UnixTime.Repr.Repr"}.AssignNull() + return mixins.MapAssembler{TypeName: "data.UnixTime.Repr.Repr"}.AssignNull() case schema.Maybe_Value, schema.Maybe_Null: panic("invalid state: cannot assign into assembler that's already finished") case midvalue: @@ -4238,22 +4292,22 @@ func (na *_UnixTime__ReprAssembler) AssignNull() error { panic("unreachable") } func (_UnixTime__ReprAssembler) AssignBool(bool) error { - return mixins.MapAssembler{"data.UnixTime.Repr"}.AssignBool(false) + return mixins.MapAssembler{TypeName: "data.UnixTime.Repr"}.AssignBool(false) } func (_UnixTime__ReprAssembler) AssignInt(int64) error { - return mixins.MapAssembler{"data.UnixTime.Repr"}.AssignInt(0) + return mixins.MapAssembler{TypeName: "data.UnixTime.Repr"}.AssignInt(0) } func (_UnixTime__ReprAssembler) AssignFloat(float64) error { - return mixins.MapAssembler{"data.UnixTime.Repr"}.AssignFloat(0) + return mixins.MapAssembler{TypeName: "data.UnixTime.Repr"}.AssignFloat(0) } func (_UnixTime__ReprAssembler) AssignString(string) error { - return mixins.MapAssembler{"data.UnixTime.Repr"}.AssignString("") + return mixins.MapAssembler{TypeName: "data.UnixTime.Repr"}.AssignString("") } func (_UnixTime__ReprAssembler) AssignBytes([]byte) error { - return mixins.MapAssembler{"data.UnixTime.Repr"}.AssignBytes(nil) + return mixins.MapAssembler{TypeName: "data.UnixTime.Repr"}.AssignBytes(nil) } func (_UnixTime__ReprAssembler) AssignLink(ipld.Link) error { - return mixins.MapAssembler{"data.UnixTime.Repr"}.AssignLink(nil) + return mixins.MapAssembler{TypeName: "data.UnixTime.Repr"}.AssignLink(nil) } func (na *_UnixTime__ReprAssembler) AssignNode(v ipld.Node) error { if v.IsNull() { @@ -4300,7 +4354,8 @@ func (ma *_UnixTime__ReprAssembler) valueFinishTidy() bool { switch ma.f { case 0: switch ma.cm { - case schema.Maybe_Value:ma.cm = schema.Maybe_Absent + case schema.Maybe_Value: + ma.cm = schema.Maybe_Absent ma.state = maState_initial return true default: @@ -4309,7 +4364,6 @@ func (ma *_UnixTime__ReprAssembler) valueFinishTidy() bool { case 1: switch ma.w.FractionalNanoseconds.m { case schema.Maybe_Value: - ma.w.FractionalNanoseconds.v = ma.ca_FractionalNanoseconds.w ma.state = maState_initial return true default: @@ -4336,7 +4390,7 @@ func (ma *_UnixTime__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssembler, } switch k { case "Seconds": - if ma.s & fieldBit__UnixTime_Seconds != 0 { + if ma.s&fieldBit__UnixTime_Seconds != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_Seconds_serial} } ma.s += fieldBit__UnixTime_Seconds @@ -4346,19 +4400,19 @@ func (ma *_UnixTime__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssembler, ma.ca_Seconds.m = &ma.cm return &ma.ca_Seconds, nil case "FractionalNanoseconds": - if ma.s & fieldBit__UnixTime_FractionalNanoseconds != 0 { + if ma.s&fieldBit__UnixTime_FractionalNanoseconds != 0 { return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_FractionalNanoseconds_serial} } ma.s += fieldBit__UnixTime_FractionalNanoseconds ma.state = maState_midValue ma.f = 1 - ma.ca_FractionalNanoseconds.w = ma.w.FractionalNanoseconds.v + ma.ca_FractionalNanoseconds.w = &ma.w.FractionalNanoseconds.v ma.ca_FractionalNanoseconds.m = &ma.w.FractionalNanoseconds.m - + return &ma.ca_FractionalNanoseconds, nil default: } - return nil, ipld.ErrInvalidKey{TypeName:"data.UnixTime.Repr", Key:&_String{k}} + return nil, ipld.ErrInvalidKey{TypeName: "data.UnixTime.Repr", Key: &_String{k}} } func (ma *_UnixTime__ReprAssembler) AssembleKey() ipld.NodeAssembler { switch ma.state { @@ -4398,9 +4452,9 @@ func (ma *_UnixTime__ReprAssembler) AssembleValue() ipld.NodeAssembler { ma.ca_Seconds.m = &ma.cm return &ma.ca_Seconds case 1: - ma.ca_FractionalNanoseconds.w = ma.w.FractionalNanoseconds.v + ma.ca_FractionalNanoseconds.w = &ma.w.FractionalNanoseconds.v ma.ca_FractionalNanoseconds.m = &ma.w.FractionalNanoseconds.m - + return &ma.ca_FractionalNanoseconds default: panic("unreachable") @@ -4421,9 +4475,9 @@ func (ma *_UnixTime__ReprAssembler) Finish() error { case maState_finished: panic("invalid state: Finish cannot be called on an assembler that's already finished") } - if ma.s & fieldBits__UnixTime_sufficient != fieldBits__UnixTime_sufficient { + if ma.s&fieldBits__UnixTime_sufficient != fieldBits__UnixTime_sufficient { err := ipld.ErrMissingRequiredField{Missing: make([]string, 0)} - if ma.s & fieldBit__UnixTime_Seconds == 0 { + if ma.s&fieldBit__UnixTime_Seconds == 0 { err.Missing = append(err.Missing, "Seconds") } return err @@ -4438,24 +4492,26 @@ func (ma *_UnixTime__ReprAssembler) KeyPrototype() ipld.NodePrototype { func (ma *_UnixTime__ReprAssembler) ValuePrototype(k string) ipld.NodePrototype { panic("todo structbuilder mapassembler repr valueprototype") } + type _UnixTime__ReprKeyAssembler _UnixTime__ReprAssembler + func (_UnixTime__ReprKeyAssembler) BeginMap(sizeHint int64) (ipld.MapAssembler, error) { - return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.BeginMap(0) + return mixins.StringAssembler{TypeName: "data.UnixTime.Repr.KeyAssembler"}.BeginMap(0) } func (_UnixTime__ReprKeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.BeginList(0) + return mixins.StringAssembler{TypeName: "data.UnixTime.Repr.KeyAssembler"}.BeginList(0) } func (na *_UnixTime__ReprKeyAssembler) AssignNull() error { - return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.AssignNull() + return mixins.StringAssembler{TypeName: "data.UnixTime.Repr.KeyAssembler"}.AssignNull() } func (_UnixTime__ReprKeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.AssignBool(false) + return mixins.StringAssembler{TypeName: "data.UnixTime.Repr.KeyAssembler"}.AssignBool(false) } func (_UnixTime__ReprKeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.AssignInt(0) + return mixins.StringAssembler{TypeName: "data.UnixTime.Repr.KeyAssembler"}.AssignInt(0) } func (_UnixTime__ReprKeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.AssignFloat(0) + return mixins.StringAssembler{TypeName: "data.UnixTime.Repr.KeyAssembler"}.AssignFloat(0) } func (ka *_UnixTime__ReprKeyAssembler) AssignString(k string) error { if ka.state != maState_midKey { @@ -4463,7 +4519,7 @@ func (ka *_UnixTime__ReprKeyAssembler) AssignString(k string) error { } switch k { case "Seconds": - if ka.s & fieldBit__UnixTime_Seconds != 0 { + if ka.s&fieldBit__UnixTime_Seconds != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_Seconds_serial} } ka.s += fieldBit__UnixTime_Seconds @@ -4471,7 +4527,7 @@ func (ka *_UnixTime__ReprKeyAssembler) AssignString(k string) error { ka.f = 0 return nil case "FractionalNanoseconds": - if ka.s & fieldBit__UnixTime_FractionalNanoseconds != 0 { + if ka.s&fieldBit__UnixTime_FractionalNanoseconds != 0 { return ipld.ErrRepeatedMapKey{Key: &fieldName__UnixTime_FractionalNanoseconds_serial} } ka.s += fieldBit__UnixTime_FractionalNanoseconds @@ -4479,13 +4535,13 @@ func (ka *_UnixTime__ReprKeyAssembler) AssignString(k string) error { ka.f = 1 return nil } - return ipld.ErrInvalidKey{TypeName:"data.UnixTime.Repr", Key:&_String{k}} + return ipld.ErrInvalidKey{TypeName: "data.UnixTime.Repr", Key: &_String{k}} } func (_UnixTime__ReprKeyAssembler) AssignBytes([]byte) error { - return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.AssignBytes(nil) + return mixins.StringAssembler{TypeName: "data.UnixTime.Repr.KeyAssembler"}.AssignBytes(nil) } func (_UnixTime__ReprKeyAssembler) AssignLink(ipld.Link) error { - return mixins.StringAssembler{"data.UnixTime.Repr.KeyAssembler"}.AssignLink(nil) + return mixins.StringAssembler{TypeName: "data.UnixTime.Repr.KeyAssembler"}.AssignLink(nil) } func (ka *_UnixTime__ReprKeyAssembler) AssignNode(v ipld.Node) error { if v2, err := v.AsString(); err != nil { @@ -4497,4 +4553,3 @@ func (ka *_UnixTime__ReprKeyAssembler) AssignNode(v ipld.Node) error { func (_UnixTime__ReprKeyAssembler) Prototype() ipld.NodePrototype { return _String__Prototype{} } - diff --git a/unixfs/node/data/ipldsch_types.go b/unixfs/node/data/ipldsch_types.go index 5fc6ae08a..6b4a65114 100644 --- a/unixfs/node/data/ipldsch_types.go +++ b/unixfs/node/data/ipldsch_types.go @@ -5,6 +5,7 @@ package data import ( ipld "github.com/ipld/go-ipld-prime" ) + var _ ipld.Node = nil // suppress errors when this dependency is not referenced // Type is a struct embeding a NodePrototype/Type for every Node implementation in this package. // One of its major uses is to start the construction of a value. @@ -19,20 +20,20 @@ var _ ipld.Node = nil // suppress errors when this dependency is not referenced var Type typeSlab type typeSlab struct { - BlockSizes _BlockSizes__Prototype - BlockSizes__Repr _BlockSizes__ReprPrototype - Bytes _Bytes__Prototype - Bytes__Repr _Bytes__ReprPrototype - Int _Int__Prototype - Int__Repr _Int__ReprPrototype - String _String__Prototype - String__Repr _String__ReprPrototype - UnixFSData _UnixFSData__Prototype - UnixFSData__Repr _UnixFSData__ReprPrototype + BlockSizes _BlockSizes__Prototype + BlockSizes__Repr _BlockSizes__ReprPrototype + Bytes _Bytes__Prototype + Bytes__Repr _Bytes__ReprPrototype + Int _Int__Prototype + Int__Repr _Int__ReprPrototype + String _String__Prototype + String__Repr _String__ReprPrototype + UnixFSData _UnixFSData__Prototype + UnixFSData__Repr _UnixFSData__ReprPrototype UnixFSMetadata _UnixFSMetadata__Prototype UnixFSMetadata__Repr _UnixFSMetadata__ReprPrototype - UnixTime _UnixTime__Prototype - UnixTime__Repr _UnixTime__ReprPrototype + UnixTime _UnixTime__Prototype + UnixTime__Repr _UnixTime__ReprPrototype } // --- type definitions follow --- @@ -58,14 +59,14 @@ type _String struct{ x string } // UnixFSData matches the IPLD Schema type "UnixFSData". It has Struct type-kind, and may be interrogated like map kind. type UnixFSData = *_UnixFSData type _UnixFSData struct { - DataType _Int - Data _Bytes__Maybe - FileSize _Int__Maybe + DataType _Int + Data _Bytes__Maybe + FileSize _Int__Maybe BlockSizes _BlockSizes - HashType _Int__Maybe - Fanout _Int__Maybe - Mode _Int__Maybe - Mtime _UnixTime__Maybe + HashType _Int__Maybe + Fanout _Int__Maybe + Mode _Int__Maybe + Mtime _UnixTime__Maybe } // UnixFSMetadata matches the IPLD Schema type "UnixFSMetadata". It has Struct type-kind, and may be interrogated like map kind. @@ -77,7 +78,6 @@ type _UnixFSMetadata struct { // UnixTime matches the IPLD Schema type "UnixTime". It has Struct type-kind, and may be interrogated like map kind. type UnixTime = *_UnixTime type _UnixTime struct { - Seconds _Int + Seconds _Int FractionalNanoseconds _Int__Maybe } - From 497695c69aef20013aa71bc1348df5ab0170f5d3 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sat, 19 Jun 2021 11:21:02 -0700 Subject: [PATCH 12/43] fix staticcheck This commit was moved from ipfs/go-unixfsnode@8c33d567626585fd9efdeb88323815943ce66cf2 --- unixfs/node/data/format_test.go | 7 +++---- unixfs/node/hamt/shardeddir_test.go | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/unixfs/node/data/format_test.go b/unixfs/node/data/format_test.go index 776bca3e9..8c53ad917 100644 --- a/unixfs/node/data/format_test.go +++ b/unixfs/node/data/format_test.go @@ -11,7 +11,6 @@ import ( "testing" "time" - "github.com/ipfs/go-unixfsnode/data" . "github.com/ipfs/go-unixfsnode/data" "github.com/ipfs/go-unixfsnode/data/builder" "github.com/ipld/go-ipld-prime" @@ -254,9 +253,9 @@ func TestUnixfsFormat(t *testing.T) { t.Run("respects high bits in mode read from buffer", func(t *testing.T) { mode := 0o0100644 // similar to output from fs.stat nd, err := qp.BuildMap(Type.UnixFSData, -1, func(ma ipld.MapAssembler) { - qp.MapEntry(ma, data.Field__DataType, qp.Int(Data_File)) - qp.MapEntry(ma, data.Field__BlockSizes, qp.List(0, func(ipld.ListAssembler) {})) - qp.MapEntry(ma, data.Field__Mode, qp.Int(int64(mode))) + qp.MapEntry(ma, Field__DataType, qp.Int(Data_File)) + qp.MapEntry(ma, Field__BlockSizes, qp.List(0, func(ipld.ListAssembler) {})) + qp.MapEntry(ma, Field__Mode, qp.Int(int64(mode))) }) require.NoError(t, err) und, ok := nd.(UnixFSData) diff --git a/unixfs/node/hamt/shardeddir_test.go b/unixfs/node/hamt/shardeddir_test.go index c4f2ec915..4b76be249 100644 --- a/unixfs/node/hamt/shardeddir_test.go +++ b/unixfs/node/hamt/shardeddir_test.go @@ -11,7 +11,6 @@ import ( "time" format "github.com/ipfs/go-ipld-format" - "github.com/ipfs/go-merkledag" dag "github.com/ipfs/go-merkledag" mdtest "github.com/ipfs/go-merkledag/test" ft "github.com/ipfs/go-unixfs" @@ -88,7 +87,7 @@ func assertLinksEqual(linksA []*format.Link, linksB []*format.Link) error { func mockDag() (format.DAGService, *ipld.LinkSystem) { bsrv := mdtest.Bserv() - dsrv := merkledag.NewDAGService(bsrv) + dsrv := dag.NewDAGService(bsrv) lsys := cidlink.DefaultLinkSystem() lsys.StorageReadOpener = func(lnkCtx ipld.LinkContext, lnk ipld.Link) (io.Reader, error) { cidLink, ok := lnk.(cidlink.Link) From 4516ade2bdc2484c4ddf43a528c3e608d1889b48 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sat, 19 Jun 2021 12:21:24 -0700 Subject: [PATCH 13/43] fix go vet This commit was moved from ipfs/go-unixfsnode@afd127394bdb845391379c237a6881981883b6c2 --- unixfs/node/data/builder/builder.go | 2 +- unixfs/node/directory/basicdir.go | 2 +- unixfs/node/hamt/util.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/unixfs/node/data/builder/builder.go b/unixfs/node/data/builder/builder.go index 212653dc7..a2641096f 100644 --- a/unixfs/node/data/builder/builder.go +++ b/unixfs/node/data/builder/builder.go @@ -49,7 +49,7 @@ type Builder struct { func DataType(b *Builder, dataType int64) { _, ok := data.DataTypeNames[dataType] if !ok { - panic(data.ErrInvalidDataType{dataType}) + panic(data.ErrInvalidDataType{DataType: dataType}) } qp.MapEntry(b.MapAssembler, data.Field__DataType, qp.Int(dataType)) b.hasDataType = true diff --git a/unixfs/node/directory/basicdir.go b/unixfs/node/directory/basicdir.go index efa7c5652..0bd9ef3d0 100644 --- a/unixfs/node/directory/basicdir.go +++ b/unixfs/node/directory/basicdir.go @@ -22,7 +22,7 @@ type _UnixFSBasicDir struct { func NewUnixFSBasicDir(ctx context.Context, substrate dagpb.PBNode, nddata data.UnixFSData, _ *ipld.LinkSystem) (ipld.Node, error) { if nddata.FieldDataType().Int() != data.Data_Directory { - return nil, data.ErrWrongNodeType{data.Data_Directory, nddata.FieldDataType().Int()} + return nil, data.ErrWrongNodeType{Expected: data.Data_Directory, Actual: nddata.FieldDataType().Int()} } return &_UnixFSBasicDir{_substrate: substrate}, nil } diff --git a/unixfs/node/hamt/util.go b/unixfs/node/hamt/util.go index 7d412fd0e..54291e457 100644 --- a/unixfs/node/hamt/util.go +++ b/unixfs/node/hamt/util.go @@ -59,7 +59,7 @@ func (hb *hashBits) next(i int) int { func validateHAMTData(nd data.UnixFSData) error { if nd.FieldDataType().Int() != data.Data_HAMTShard { - return data.ErrWrongNodeType{data.Data_HAMTShard, nd.FieldDataType().Int()} + return data.ErrWrongNodeType{Expected: data.Data_HAMTShard, Actual: nd.FieldDataType().Int()} } if !nd.FieldHashType().Exists() || uint64(nd.FieldHashType().Must().Int()) != HashMurmur3 { From e2fc731346bdacb7c886cd8fe4aa4bc36830e471 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Mon, 27 Sep 2021 17:32:29 -0400 Subject: [PATCH 14/43] make UnixFSHAMTShard implement the ADL interface (#11) * make UnixFSHAMTShard implement the ADL interface * add checks that UnixFSBasicDir and PathedPBNode implement the ADL interface This commit was moved from ipfs/go-unixfsnode@c7f1fe6ecd168c22f77386a71e8f7eaa647e81fb --- unixfs/node/directory/basicdir.go | 1 + unixfs/node/hamt/shardeddir.go | 5 +++++ unixfs/node/pathpbnode.go | 1 + 3 files changed, 7 insertions(+) diff --git a/unixfs/node/directory/basicdir.go b/unixfs/node/directory/basicdir.go index 0bd9ef3d0..a41a8f05b 100644 --- a/unixfs/node/directory/basicdir.go +++ b/unixfs/node/directory/basicdir.go @@ -13,6 +13,7 @@ import ( var _ ipld.Node = UnixFSBasicDir(nil) var _ schema.TypedNode = UnixFSBasicDir(nil) +var _ ipld.ADL = UnixFSBasicDir(nil) type UnixFSBasicDir = *_UnixFSBasicDir diff --git a/unixfs/node/hamt/shardeddir.go b/unixfs/node/hamt/shardeddir.go index 553baea6e..aa219b3c8 100644 --- a/unixfs/node/hamt/shardeddir.go +++ b/unixfs/node/hamt/shardeddir.go @@ -19,6 +19,7 @@ const ( var _ ipld.Node = UnixFSHAMTShard(nil) var _ schema.TypedNode = UnixFSHAMTShard(nil) +var _ ipld.ADL = UnixFSHAMTShard(nil) // UnixFSHAMTShared is an IPLD Prime Node that provides a read interface // to a UnixFS HAMT @@ -53,6 +54,10 @@ func NewUnixFSHAMTShard(ctx context.Context, substrate dagpb.PBNode, data data.U }, nil } +func (n UnixFSHAMTShard) Substrate() ipld.Node { + return n._substrate +} + func (n UnixFSHAMTShard) Kind() ipld.Kind { return n._substrate.Kind() } diff --git a/unixfs/node/pathpbnode.go b/unixfs/node/pathpbnode.go index 969c53c3a..2dc2b088b 100644 --- a/unixfs/node/pathpbnode.go +++ b/unixfs/node/pathpbnode.go @@ -10,6 +10,7 @@ import ( var _ ipld.Node = PathedPBNode(nil) var _ schema.TypedNode = PathedPBNode(nil) +var _ ipld.ADL = PathedPBNode(nil) type PathedPBNode = *_PathedPBNode From 1fbc9e65ac4b86fd12abe5f1171edf38506a59ec Mon Sep 17 00:00:00 2001 From: Will Date: Mon, 18 Oct 2021 13:54:08 -0700 Subject: [PATCH 15/43] Add builder for unixfs dags (#12) * Add builder for unixfs chunked files and directories This commit was moved from ipfs/go-unixfsnode@e0bbe4aca062fba67db8bc82be9aa05c7eb501c5 --- unixfs/node/data/builder/dir_test.go | 72 +++++++ unixfs/node/data/builder/directory.go | 130 +++++++++++ unixfs/node/data/builder/dirshard.go | 204 ++++++++++++++++++ unixfs/node/data/builder/file.go | 298 ++++++++++++++++++++++++++ unixfs/node/data/builder/file_test.go | 41 ++++ unixfs/node/data/builder/util.go | 56 +++++ 6 files changed, 801 insertions(+) create mode 100644 unixfs/node/data/builder/dir_test.go create mode 100644 unixfs/node/data/builder/directory.go create mode 100644 unixfs/node/data/builder/dirshard.go create mode 100644 unixfs/node/data/builder/file.go create mode 100644 unixfs/node/data/builder/file_test.go create mode 100644 unixfs/node/data/builder/util.go diff --git a/unixfs/node/data/builder/dir_test.go b/unixfs/node/data/builder/dir_test.go new file mode 100644 index 000000000..954d2dd17 --- /dev/null +++ b/unixfs/node/data/builder/dir_test.go @@ -0,0 +1,72 @@ +package builder + +import ( + "bytes" + "fmt" + "testing" + + "github.com/ipfs/go-unixfsnode" + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" + cidlink "github.com/ipld/go-ipld-prime/linking/cid" +) + +func mkEntries(cnt int, ls *ipld.LinkSystem) ([]dagpb.PBLink, error) { + entries := make([]dagpb.PBLink, 0, cnt) + for i := 0; i < cnt; i++ { + r := bytes.NewBufferString(fmt.Sprintf("%d", i)) + f, s, err := BuildUnixFSFile(r, "", ls) + if err != nil { + return nil, err + } + e, err := BuildUnixFSDirectoryEntry(fmt.Sprintf("file %d", i), int64(s), f) + if err != nil { + return nil, err + } + entries = append(entries, e) + } + return entries, nil +} + +func TestBuildUnixFSDirectory(t *testing.T) { + ls := cidlink.DefaultLinkSystem() + storage := cidlink.Memory{} + ls.StorageReadOpener = storage.OpenRead + ls.StorageWriteOpener = storage.OpenWrite + + testSizes := []int{100, 1000, 50000} + for _, cnt := range testSizes { + entries, err := mkEntries(cnt, &ls) + if err != nil { + t.Fatal(err) + } + + dl, err := BuildUnixFSDirectory(entries, &ls) + if err != nil { + t.Fatal(err) + } + + pbn, err := ls.Load(ipld.LinkContext{}, dl, dagpb.Type.PBNode) + if err != nil { + t.Fatal(err) + } + ufd, err := unixfsnode.Reify(ipld.LinkContext{}, pbn, &ls) + if err != nil { + t.Fatal(err) + } + observedCnt := 0 + + li := ufd.MapIterator() + for !li.Done() { + _, _, err := li.Next() + if err != nil { + t.Fatal(err) + } + observedCnt++ + } + if observedCnt != cnt { + fmt.Printf("%+v\n", ufd) + t.Fatalf("unexpected number of dir entries %d vs %d", observedCnt, cnt) + } + } +} diff --git a/unixfs/node/data/builder/directory.go b/unixfs/node/data/builder/directory.go new file mode 100644 index 000000000..c6b054939 --- /dev/null +++ b/unixfs/node/data/builder/directory.go @@ -0,0 +1,130 @@ +package builder + +import ( + "fmt" + "io/fs" + "os" + "path" + + "github.com/ipfs/go-unixfsnode/data" + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" + cidlink "github.com/ipld/go-ipld-prime/linking/cid" + "github.com/multiformats/go-multihash" +) + +// https://github.com/ipfs/go-ipfs/pull/8114/files#diff-eec963b47a6e1080d9d8023b4e438e6e3591b4154f7379a7e728401d2055374aR319 +const shardSplitThreshold = 262144 + +// https://github.com/ipfs/go-unixfs/blob/ec6bb5a4c5efdc3a5bce99151b294f663ee9c08d/io/directory.go#L29 +const defaultShardWidth = 256 + +// BuildUnixFSRecursive returns a link pointing to the UnixFS node representing +// the file or directory tree pointed to by `root` +func BuildUnixFSRecursive(root string, ls *ipld.LinkSystem) (ipld.Link, uint64, error) { + info, err := os.Lstat(root) + if err != nil { + return nil, 0, err + } + + m := info.Mode() + switch { + case m.IsDir(): + entries, err := os.ReadDir(root) + if err != nil { + return nil, 0, err + } + lnks := make([]dagpb.PBLink, 0, len(entries)) + for _, e := range entries { + lnk, sz, err := BuildUnixFSRecursive(path.Join(root, e.Name()), ls) + if err != nil { + return nil, 0, err + } + entry, err := BuildUnixFSDirectoryEntry(e.Name(), int64(sz), lnk) + if err != nil { + return nil, 0, err + } + lnks = append(lnks, entry) + } + outLnk, err := BuildUnixFSDirectory(lnks, ls) + return outLnk, 0, err + case m.Type() == fs.ModeSymlink: + content, err := os.Readlink(root) + if err != nil { + return nil, 0, err + } + return BuildUnixFSSymlink(content, ls) + case m.IsRegular(): + fp, err := os.Open(root) + if err != nil { + return nil, 0, err + } + defer fp.Close() + return BuildUnixFSFile(fp, "", ls) + default: + return nil, 0, fmt.Errorf("cannot encode non regular file: %s", root) + } +} + +// estimateDirSize estimates if a directory is big enough that it warrents sharding. +// The estimate is the sum over the len(linkName) + bytelen(linkHash) +// https://github.com/ipfs/go-unixfs/blob/master/io/directory.go#L152-L162 +func estimateDirSize(entries []dagpb.PBLink) int { + s := 0 + for _, e := range entries { + s += len(e.Name.Must().String()) + lnk := e.Hash.Link() + cl, ok := lnk.(cidlink.Link) + if ok { + s += cl.ByteLen() + } else { + s += len(lnk.Binary()) + } + } + return s +} + +// BuildUnixFSDirectory creates a directory link over a collection of entries. +func BuildUnixFSDirectory(entries []dagpb.PBLink, ls *ipld.LinkSystem) (ipld.Link, error) { + if estimateDirSize(entries) > shardSplitThreshold { + return BuildUnixFSShardedDirectory(defaultShardWidth, multihash.MURMUR3_128, entries, ls) + } + ufd, err := BuildUnixFS(func(b *Builder) { + DataType(b, data.Data_Directory) + }) + if err != nil { + return nil, err + } + pbb := dagpb.Type.PBNode.NewBuilder() + pbm, err := pbb.BeginMap(2) + if err != nil { + return nil, err + } + if err = pbm.AssembleKey().AssignString("Data"); err != nil { + return nil, err + } + if err = pbm.AssembleValue().AssignBytes(data.EncodeUnixFSData(ufd)); err != nil { + return nil, err + } + if err = pbm.AssembleKey().AssignString("Links"); err != nil { + return nil, err + } + lnks, err := pbm.AssembleValue().BeginList(int64(len(entries))) + if err != nil { + return nil, err + } + // sorting happens in codec-dagpb + for _, e := range entries { + if err := lnks.AssembleValue().AssignNode(e); err != nil { + return nil, err + } + } + if err := lnks.Finish(); err != nil { + return nil, err + } + if err := pbm.Finish(); err != nil { + return nil, err + } + node := pbb.Build() + return ls.Store(ipld.LinkContext{}, fileLinkProto, node) +} diff --git a/unixfs/node/data/builder/dirshard.go b/unixfs/node/data/builder/dirshard.go new file mode 100644 index 000000000..a25aa66ce --- /dev/null +++ b/unixfs/node/data/builder/dirshard.go @@ -0,0 +1,204 @@ +package builder + +import ( + "fmt" + "hash" + + bitfield "github.com/ipfs/go-bitfield" + "github.com/ipfs/go-unixfsnode/data" + "github.com/ipfs/go-unixfsnode/hamt" + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" + "github.com/multiformats/go-multihash" + "github.com/spaolacci/murmur3" +) + +type shard struct { + // metadata about the shard + hasher uint64 + size int + sizeLg2 int + width int + depth int + + children map[int]entry +} + +// a shard entry is either another shard, or a direct link. +type entry struct { + *shard + *hamtLink +} + +// a hamtLink is a member of the hamt - the file/directory pointed to, but +// stored with it's hashed key used for addressing. +type hamtLink struct { + hash hashBits + dagpb.PBLink +} + +// BuildUnixFSShardedDirectory will build a hamt of unixfs hamt shards encoing a directory with more entries +// than is typically allowed to fit in a standard IPFS single-block unixFS directory. +func BuildUnixFSShardedDirectory(size int, hasher uint64, entries []dagpb.PBLink, ls *ipld.LinkSystem) (ipld.Link, error) { + // hash the entries + var h hash.Hash + var err error + // TODO: use the multihash registry once murmur3 behavior is encoded there. + // https://github.com/multiformats/go-multihash/pull/150 + if hasher == hamt.HashMurmur3 { + h = murmur3.New64() + } else { + h, err = multihash.GetHasher(hasher) + if err != nil { + return nil, err + } + } + hamtEntries := make([]hamtLink, 0, len(entries)) + for _, e := range entries { + name := e.Name.Must().String() + sum := h.Sum([]byte(name)) + hamtEntries = append(hamtEntries, hamtLink{ + sum, + e, + }) + } + + sizeLg2, err := logtwo(size) + if err != nil { + return nil, err + } + + sharder := shard{ + hasher: hasher, + size: size, + sizeLg2: sizeLg2, + width: len(fmt.Sprintf("%X", size-1)), + depth: 0, + + children: make(map[int]entry), + } + + for _, entry := range hamtEntries { + err := sharder.add(entry) + if err != nil { + return nil, err + } + } + + return sharder.serialize(ls) +} + +func (s *shard) add(lnk hamtLink) error { + // get the bucket for lnk + bucket, err := lnk.hash.Slice(s.depth*s.sizeLg2, s.sizeLg2) + if err != nil { + return err + } + + current, ok := s.children[bucket] + if !ok { + s.children[bucket] = entry{nil, &lnk} + return nil + } else if current.shard != nil { + return current.shard.add(lnk) + } + // make a shard for current and lnk + newShard := entry{ + &shard{ + hasher: s.hasher, + size: s.size, + sizeLg2: s.sizeLg2, + width: s.width, + depth: s.depth + 1, + children: make(map[int]entry), + }, + nil, + } + if err := newShard.add(*current.hamtLink); err != nil { + return err + } + s.children[bucket] = newShard + return newShard.add(lnk) +} + +func (s *shard) formatLinkName(name string, idx int) string { + return fmt.Sprintf("%*X%s", s.width, idx, name) +} + +// bitmap calculates the bitmap of which links in the shard are set. +func (s *shard) bitmap() []byte { + bm := bitfield.NewBitfield(s.size) + for i := 0; i < s.size; i++ { + if _, ok := s.children[i]; ok { + bm.SetBit(i) + } + } + return bm.Bytes() +} + +// serialize stores the concrete representation of this shard in the link system and +// returns a link to it. +func (s *shard) serialize(ls *ipld.LinkSystem) (ipld.Link, error) { + ufd, err := BuildUnixFS(func(b *Builder) { + DataType(b, data.Data_HAMTShard) + HashType(b, s.hasher) + Data(b, s.bitmap()) + Fanout(b, uint64(s.size)) + }) + if err != nil { + return nil, err + } + pbb := dagpb.Type.PBNode.NewBuilder() + pbm, err := pbb.BeginMap(2) + if err != nil { + return nil, err + } + if err = pbm.AssembleKey().AssignString("Data"); err != nil { + return nil, err + } + if err = pbm.AssembleValue().AssignBytes(data.EncodeUnixFSData(ufd)); err != nil { + return nil, err + } + if err = pbm.AssembleKey().AssignString("Links"); err != nil { + return nil, err + } + + lnkBuilder := dagpb.Type.PBLinks.NewBuilder() + lnks, err := lnkBuilder.BeginList(int64(len(s.children))) + if err != nil { + return nil, err + } + // sorting happens in codec-dagpb + for idx, e := range s.children { + var lnk dagpb.PBLink + if e.shard != nil { + ipldLnk, err := e.shard.serialize(ls) + if err != nil { + return nil, err + } + fullName := s.formatLinkName("", idx) + lnk, err = BuildUnixFSDirectoryEntry(fullName, 0, ipldLnk) + if err != nil { + return nil, err + } + } else { + fullName := s.formatLinkName(e.Name.Must().String(), idx) + lnk, err = BuildUnixFSDirectoryEntry(fullName, e.Tsize.Must().Int(), e.Hash.Link()) + } + if err != nil { + return nil, err + } + if err := lnks.AssembleValue().AssignNode(lnk); err != nil { + return nil, err + } + } + if err := lnks.Finish(); err != nil { + return nil, err + } + pbm.AssembleValue().AssignNode(lnkBuilder.Build()) + if err := pbm.Finish(); err != nil { + return nil, err + } + node := pbb.Build() + return ls.Store(ipld.LinkContext{}, fileLinkProto, node) +} diff --git a/unixfs/node/data/builder/file.go b/unixfs/node/data/builder/file.go new file mode 100644 index 000000000..dcf3b810e --- /dev/null +++ b/unixfs/node/data/builder/file.go @@ -0,0 +1,298 @@ +package builder + +import ( + "fmt" + "io" + + "github.com/ipfs/go-cid" + chunk "github.com/ipfs/go-ipfs-chunker" + "github.com/ipfs/go-unixfsnode/data" + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" + cidlink "github.com/ipld/go-ipld-prime/linking/cid" + basicnode "github.com/ipld/go-ipld-prime/node/basic" + "github.com/multiformats/go-multicodec" + multihash "github.com/multiformats/go-multihash/core" + + // raw needed for opening as bytes + _ "github.com/ipld/go-ipld-prime/codec/raw" +) + +// BuildUnixFSFile creates a dag of ipld Nodes representing file data. +// This recreates the functionality previously found in +// github.com/ipfs/go-unixfs/importer/balanced, but tailored to the +// go-unixfsnode & ipld-prime data layout of nodes. +// We make some assumptions in building files with this builder to reduce +// complexity, namely: +// * we assume we are using CIDv1, which has implied that the leaf +// data nodes are stored as raw bytes. +// ref: https://github.com/ipfs/go-mfs/blob/1b1fd06cff048caabeddb02d4dbf22d2274c7971/file.go#L50 +func BuildUnixFSFile(r io.Reader, chunker string, ls *ipld.LinkSystem) (ipld.Link, uint64, error) { + s, err := chunk.FromString(r, chunker) + if err != nil { + return nil, 0, err + } + + var prev []ipld.Link + var prevLen []uint64 + depth := 1 + for { + root, size, err := fileTreeRecursive(depth, prev, prevLen, s, ls) + if err != nil { + return nil, 0, err + } + + if prev != nil && prev[0] == root { + return root, size, nil + } + + prev = []ipld.Link{root} + prevLen = []uint64{size} + depth++ + } +} + +var fileLinkProto = cidlink.LinkPrototype{ + Prefix: cid.Prefix{ + Version: 1, + Codec: uint64(multicodec.DagPb), + MhType: multihash.SHA2_256, + MhLength: 32, + }, +} + +var leafLinkProto = cidlink.LinkPrototype{ + Prefix: cid.Prefix{ + Version: 1, + Codec: uint64(multicodec.Raw), + MhType: multihash.SHA2_256, + MhLength: 32, + }, +} + +func fileTreeRecursive(depth int, children []ipld.Link, childLen []uint64, src chunk.Splitter, ls *ipld.LinkSystem) (ipld.Link, uint64, error) { + if depth == 1 && len(children) > 0 { + return nil, 0, fmt.Errorf("leaf nodes cannot have children") + } else if depth == 1 { + leaf, err := src.NextBytes() + if err == io.EOF { + return nil, 0, nil + } else if err != nil { + return nil, 0, err + } + node := basicnode.NewBytes(leaf) + link, err := ls.Store(ipld.LinkContext{}, leafLinkProto, node) + return link, uint64(len(leaf)), err + } + // depth > 1. + totalSize := uint64(0) + blksizes := make([]uint64, 0, DefaultLinksPerBlock) + if children == nil { + children = make([]ipld.Link, 0) + } else { + for i := range children { + blksizes = append(blksizes, childLen[i]) + totalSize += childLen[i] + } + } + for len(children) < DefaultLinksPerBlock { + nxt, sz, err := fileTreeRecursive(depth-1, nil, nil, src, ls) + if err != nil { + return nil, 0, err + } else if nxt == nil { + // eof + break + } + totalSize += sz + children = append(children, nxt) + blksizes = append(blksizes, sz) + } + if len(children) == 0 { + // empty case. + return nil, 0, nil + } else if len(children) == 1 { + // degenerate case + return children[0], childLen[0], nil + } + + // make the unixfs node. + node, err := BuildUnixFS(func(b *Builder) { + FileSize(b, totalSize) + BlockSizes(b, blksizes) + }) + if err != nil { + return nil, 0, err + } + + // Pack into the dagpb node. + dpbb := dagpb.Type.PBNode.NewBuilder() + pbm, err := dpbb.BeginMap(2) + if err != nil { + return nil, 0, err + } + pblb, err := pbm.AssembleEntry("Links") + if err != nil { + return nil, 0, err + } + pbl, err := pblb.BeginList(int64(len(children))) + if err != nil { + return nil, 0, err + } + for i, c := range children { + pbln, err := BuildUnixFSDirectoryEntry("", int64(blksizes[i]), c) + if err != nil { + return nil, 0, err + } + if err = pbl.AssembleValue().AssignNode(pbln); err != nil { + return nil, 0, err + } + } + if err = pbl.Finish(); err != nil { + return nil, 0, err + } + if err = pbm.AssembleKey().AssignString("Data"); err != nil { + return nil, 0, err + } + if err = pbm.AssembleValue().AssignBytes(data.EncodeUnixFSData(node)); err != nil { + return nil, 0, err + } + if err = pbm.Finish(); err != nil { + return nil, 0, err + } + pbn := dpbb.Build() + + link, err := ls.Store(ipld.LinkContext{}, fileLinkProto, pbn) + if err != nil { + return nil, 0, err + } + // calculate the dagpb node's size and add as overhead. + cl, ok := link.(cidlink.Link) + if !ok { + return nil, 0, fmt.Errorf("unexpected non-cid linksystem") + } + rawlnk := cid.NewCidV1(uint64(multicodec.Raw), cl.Cid.Hash()) + rn, err := ls.Load(ipld.LinkContext{}, cidlink.Link{Cid: rawlnk}, basicnode.Prototype__Bytes{}) + if err != nil { + return nil, 0, fmt.Errorf("could not re-interpret dagpb node as bytes: %w", err) + } + rnb, err := rn.AsBytes() + if err != nil { + return nil, 0, fmt.Errorf("could not parse dagpb node as bytes: %w", err) + } + return link, totalSize + uint64(len(rnb)), nil +} + +// BuildUnixFSDirectoryEntry creates the link to a file or directory as it appears within a unixfs directory. +func BuildUnixFSDirectoryEntry(name string, size int64, hash ipld.Link) (dagpb.PBLink, error) { + dpbl := dagpb.Type.PBLink.NewBuilder() + lma, err := dpbl.BeginMap(3) + if err != nil { + return nil, err + } + if err = lma.AssembleKey().AssignString("Hash"); err != nil { + return nil, err + } + if err = lma.AssembleValue().AssignLink(hash); err != nil { + return nil, err + } + if err = lma.AssembleKey().AssignString("Name"); err != nil { + return nil, err + } + if err = lma.AssembleValue().AssignString(name); err != nil { + return nil, err + } + if err = lma.AssembleKey().AssignString("Tsize"); err != nil { + return nil, err + } + if err = lma.AssembleValue().AssignInt(size); err != nil { + return nil, err + } + if err = lma.Finish(); err != nil { + return nil, err + } + return dpbl.Build().(dagpb.PBLink), nil +} + +// BuildUnixFSSymlink builds a symlink entry in a unixfs tree +func BuildUnixFSSymlink(content string, ls *ipld.LinkSystem) (ipld.Link, uint64, error) { + // make the unixfs node. + node, err := BuildUnixFS(func(b *Builder) { + DataType(b, data.Data_Symlink) + Data(b, []byte(content)) + }) + if err != nil { + return nil, 0, err + } + + dpbb := dagpb.Type.PBNode.NewBuilder() + pbm, err := dpbb.BeginMap(2) + if err != nil { + return nil, 0, err + } + pblb, err := pbm.AssembleEntry("Links") + if err != nil { + return nil, 0, err + } + pbl, err := pblb.BeginList(0) + if err != nil { + return nil, 0, err + } + if err = pbl.Finish(); err != nil { + return nil, 0, err + } + if err = pbm.AssembleKey().AssignString("Data"); err != nil { + return nil, 0, err + } + if err = pbm.AssembleValue().AssignBytes(data.EncodeUnixFSData(node)); err != nil { + return nil, 0, err + } + if err = pbm.Finish(); err != nil { + return nil, 0, err + } + pbn := dpbb.Build() + + link, err := ls.Store(ipld.LinkContext{}, fileLinkProto, pbn) + if err != nil { + return nil, 0, err + } + // calculate the size and add as overhead. + cl, ok := link.(cidlink.Link) + if !ok { + return nil, 0, fmt.Errorf("unexpected non-cid linksystem") + } + rawlnk := cid.NewCidV1(uint64(multicodec.Raw), cl.Cid.Hash()) + rn, err := ls.Load(ipld.LinkContext{}, cidlink.Link{Cid: rawlnk}, basicnode.Prototype__Bytes{}) + if err != nil { + return nil, 0, fmt.Errorf("could not re-interpret dagpb node as bytes: %w", err) + } + rnb, err := rn.AsBytes() + if err != nil { + return nil, 0, fmt.Errorf("could not re-interpret dagpb node as bytes: %w", err) + } + return link, uint64(len(rnb)), nil +} + +// Constants below are from +// https://github.com/ipfs/go-unixfs/blob/ec6bb5a4c5efdc3a5bce99151b294f663ee9c08d/importer/helpers/helpers.go + +// BlockSizeLimit specifies the maximum size an imported block can have. +var BlockSizeLimit = 1048576 // 1 MB + +// rough estimates on expected sizes +var roughLinkBlockSize = 1 << 13 // 8KB +var roughLinkSize = 34 + 8 + 5 // sha256 multihash + size + no name + protobuf framing + +// DefaultLinksPerBlock governs how the importer decides how many links there +// will be per block. This calculation is based on expected distributions of: +// * the expected distribution of block sizes +// * the expected distribution of link sizes +// * desired access speed +// For now, we use: +// +// var roughLinkBlockSize = 1 << 13 // 8KB +// var roughLinkSize = 34 + 8 + 5 // sha256 multihash + size + no name +// // + protobuf framing +// var DefaultLinksPerBlock = (roughLinkBlockSize / roughLinkSize) +// = ( 8192 / 47 ) +// = (approximately) 174 +var DefaultLinksPerBlock = roughLinkBlockSize / roughLinkSize diff --git a/unixfs/node/data/builder/file_test.go b/unixfs/node/data/builder/file_test.go new file mode 100644 index 000000000..9fbe8e012 --- /dev/null +++ b/unixfs/node/data/builder/file_test.go @@ -0,0 +1,41 @@ +package builder + +import ( + "bytes" + "testing" + + "github.com/ipfs/go-cid" + u "github.com/ipfs/go-ipfs-util" + "github.com/ipld/go-ipld-prime" + cidlink "github.com/ipld/go-ipld-prime/linking/cid" +) + +func TestBuildUnixFSFile(t *testing.T) { + buf := make([]byte, 10*1024*1024) + u.NewSeededRand(0xdeadbeef).Read(buf) + r := bytes.NewReader(buf) + + ls := cidlink.DefaultLinkSystem() + storage := cidlink.Memory{} + ls.StorageReadOpener = storage.OpenRead + ls.StorageWriteOpener = storage.OpenWrite + + f, _, err := BuildUnixFSFile(r, "", &ls) + if err != nil { + t.Fatal(err) + } + + // Note: this differs from the previous + // go-unixfs version of this test (https://github.com/ipfs/go-unixfs/blob/master/importer/importer_test.go#L50) + // because this library enforces CidV1 encoding. + expected, err := cid.Decode("bafybeieyxejezqto5xwcxtvh5tskowwxrn3hmbk3hcgredji3g7abtnfkq") + if err != nil { + t.Fatal(err) + } + if !expected.Equals(f.(cidlink.Link).Cid) { + t.Fatalf("expected CID %s, got CID %s", expected, f) + } + if _, err := storage.OpenRead(ipld.LinkContext{}, f); err != nil { + t.Fatal("expected top of file to be in store.") + } +} diff --git a/unixfs/node/data/builder/util.go b/unixfs/node/data/builder/util.go new file mode 100644 index 000000000..8e5c0fbe2 --- /dev/null +++ b/unixfs/node/data/builder/util.go @@ -0,0 +1,56 @@ +package builder + +import ( + "fmt" + "math/bits" +) + +// Common code from go-unixfs/hamt/util.go + +// hashBits is a helper for pulling out sections of a hash +type hashBits []byte + +func mkmask(n int) byte { + return (1 << uint(n)) - 1 +} + +// Slice returns the 'width' bits of the hashBits value as an integer, or an +// error if there aren't enough bits. +func (hb hashBits) Slice(offset, width int) (int, error) { + if offset+width > len(hb)*8 { + return 0, fmt.Errorf("sharded directory too deep") + } + return hb.slice(offset, width), nil +} + +func (hb hashBits) slice(offset, width int) int { + curbi := offset / 8 + leftb := 8 - (offset % 8) + + curb := hb[curbi] + if width == leftb { + out := int(mkmask(width) & curb) + return out + } else if width < leftb { + a := curb & mkmask(leftb) // mask out the high bits we don't want + b := a & ^mkmask(leftb-width) // mask out the low bits we don't want + c := b >> uint(leftb-width) // shift whats left down + return int(c) + } else { + out := int(mkmask(leftb) & curb) + out <<= uint(width - leftb) + out += hb.slice(offset+leftb, width-leftb) + return out + } +} + +func logtwo(v int) (int, error) { + if v <= 0 { + return 0, fmt.Errorf("hamt size should be a power of two") + } + lg2 := bits.TrailingZeros(uint(v)) + if 1< Date: Thu, 4 Nov 2021 11:49:09 -0700 Subject: [PATCH 16/43] Add ADL/single-node-view of a full unixFS file. (#14) * Add ADL/single-node-view for unixFS files. This commit was moved from ipfs/go-unixfsnode@ef86491c66a75bd3bc10f1c71be2c99a2afc5944 --- unixfs/node/data/builder/file_test.go | 39 +++++ unixfs/node/file/file.go | 59 +++++++ unixfs/node/file/file_test.go | 90 ++++++++++ ...BmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o.car | Bin 0 -> 112 bytes ...Jq63SkDZ1mWLbWWyVV66PuqyHWpKkH4pcVyY4H.car | Bin 0 -> 198 bytes unixfs/node/file/shard.go | 154 ++++++++++++++++++ unixfs/node/file/wrapped.go | 34 ++++ unixfs/node/reification.go | 9 +- 8 files changed, 383 insertions(+), 2 deletions(-) create mode 100644 unixfs/node/file/file.go create mode 100644 unixfs/node/file/file_test.go create mode 100644 unixfs/node/file/fixtures/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o.car create mode 100644 unixfs/node/file/fixtures/QmT8EC9sJq63SkDZ1mWLbWWyVV66PuqyHWpKkH4pcVyY4H.car create mode 100644 unixfs/node/file/shard.go create mode 100644 unixfs/node/file/wrapped.go diff --git a/unixfs/node/data/builder/file_test.go b/unixfs/node/data/builder/file_test.go index 9fbe8e012..58619794d 100644 --- a/unixfs/node/data/builder/file_test.go +++ b/unixfs/node/data/builder/file_test.go @@ -2,10 +2,14 @@ package builder import ( "bytes" + "context" + "io" "testing" "github.com/ipfs/go-cid" u "github.com/ipfs/go-ipfs-util" + "github.com/ipfs/go-unixfsnode/file" + dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" ) @@ -39,3 +43,38 @@ func TestBuildUnixFSFile(t *testing.T) { t.Fatal("expected top of file to be in store.") } } + +func TestUnixFSFileRoundtrip(t *testing.T) { + buf := make([]byte, 10*1024*1024) + u.NewSeededRand(0xdeadbeef).Read(buf) + r := bytes.NewReader(buf) + + ls := cidlink.DefaultLinkSystem() + storage := cidlink.Memory{} + ls.StorageReadOpener = storage.OpenRead + ls.StorageWriteOpener = storage.OpenWrite + + f, _, err := BuildUnixFSFile(r, "", &ls) + if err != nil { + t.Fatal(err) + } + + // get back the root node substrate from the link at the top of the builder. + fr, err := ls.Load(ipld.LinkContext{}, f, dagpb.Type.PBNode) + if err != nil { + t.Fatal(err) + } + + ufn, err := file.NewUnixFSFile(context.Background(), fr, &ls) + if err != nil { + t.Fatal(err) + } + // read back out the file. + out, err := io.ReadAll(ufn) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(out, buf) { + t.Fatal("Not equal") + } +} diff --git a/unixfs/node/file/file.go b/unixfs/node/file/file.go new file mode 100644 index 000000000..bda6f9ef8 --- /dev/null +++ b/unixfs/node/file/file.go @@ -0,0 +1,59 @@ +package file + +import ( + "context" + "io" + + "github.com/ipld/go-ipld-prime" +) + +// NewUnixFSFile attempts to construct an ipld node from the base protobuf node representing the +// root of a unixfs File. +// It provides a `bytes` view over the file, along with access to io.Reader streaming access +// to file data. +func NewUnixFSFile(ctx context.Context, substrate ipld.Node, lsys *ipld.LinkSystem) (StreamableByteNode, error) { + if substrate.Kind() == ipld.Kind_Bytes { + // A raw / single-node file. + return &singleNodeFile{substrate, 0}, nil + } + // see if it's got children. + links, err := substrate.LookupByString("Links") + if err != nil { + return nil, err + } + if links.Length() == 0 { + // no children. + return newWrappedNode(substrate) + } + + return &shardNodeFile{ + ctx: ctx, + lsys: lsys, + substrate: substrate, + done: false, + rdr: nil}, nil +} + +// A StreamableByteNode is an ipld.Node that can be streamed over. It is guaranteed to have a Bytes type. +type StreamableByteNode interface { + ipld.Node + io.Reader +} + +type singleNodeFile struct { + ipld.Node + offset int +} + +func (f *singleNodeFile) Read(p []byte) (int, error) { + buf, err := f.Node.AsBytes() + if err != nil { + return 0, err + } + if f.offset >= len(buf) { + return 0, io.EOF + } + n := copy(p, buf[f.offset:]) + f.offset += n + return n, nil +} diff --git a/unixfs/node/file/file_test.go b/unixfs/node/file/file_test.go new file mode 100644 index 000000000..17d221fe4 --- /dev/null +++ b/unixfs/node/file/file_test.go @@ -0,0 +1,90 @@ +package file_test + +import ( + "bytes" + "context" + "fmt" + "io" + "testing" + + "github.com/ipfs/go-unixfsnode" + "github.com/ipfs/go-unixfsnode/directory" + "github.com/ipfs/go-unixfsnode/file" + "github.com/ipld/go-car/v2/blockstore" + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" + cidlink "github.com/ipld/go-ipld-prime/linking/cid" +) + +func TestRootV0File(t *testing.T) { + baseFile := "./fixtures/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o.car" + root, ls := open(baseFile, t) + file, err := file.NewUnixFSFile(context.Background(), root, ls) + if err != nil { + t.Fatal(err) + } + fc, err := file.AsBytes() + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(fc, []byte("hello world\n")) { + t.Errorf("file content does not match: %s", string(fc)) + } +} + +func TestNamedV0File(t *testing.T) { + baseFile := "./fixtures/QmT8EC9sJq63SkDZ1mWLbWWyVV66PuqyHWpKkH4pcVyY4H.car" + root, ls := open(baseFile, t) + dir, err := unixfsnode.Reify(ipld.LinkContext{}, root, ls) + if err != nil { + t.Fatal(err) + } + dpbn := dir.(directory.UnixFSBasicDir) + name, link := dpbn.Iterator().Next() + if name.String() != "b.txt" { + t.Fatal("unexpected filename") + } + fileNode, err := ls.Load(ipld.LinkContext{}, link.Link(), dagpb.Type.PBNode) + if err != nil { + t.Fatal(err) + } + file, err := file.NewUnixFSFile(context.Background(), fileNode, ls) + if err != nil { + t.Fatal(err) + } + fc, err := file.AsBytes() + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(fc, []byte("hello world\n")) { + t.Errorf("file content does not match: %s", string(fc)) + } +} + +func open(car string, t *testing.T) (ipld.Node, *ipld.LinkSystem) { + baseStore, err := blockstore.OpenReadOnly(car) + if err != nil { + t.Fatal(err) + } + ls := cidlink.DefaultLinkSystem() + ls.StorageReadOpener = func(_ ipld.LinkContext, l ipld.Link) (io.Reader, error) { + cl, ok := l.(cidlink.Link) + if !ok { + return nil, fmt.Errorf("couldn't load link") + } + blk, err := baseStore.Get(cl.Cid) + if err != nil { + return nil, err + } + return bytes.NewBuffer(blk.RawData()), nil + } + carRoots, err := baseStore.Roots() + if err != nil { + t.Fatal(err) + } + root, err := ls.Load(ipld.LinkContext{}, cidlink.Link{Cid: carRoots[0]}, dagpb.Type.PBNode) + if err != nil { + t.Fatal(err) + } + return root, &ls +} diff --git a/unixfs/node/file/fixtures/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o.car b/unixfs/node/file/fixtures/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o.car new file mode 100644 index 0000000000000000000000000000000000000000..7ec9782d889283aaa9fc83e6584aa1abee5e6788 GIT binary patch literal 112 zcmcCmlvF`5xp%O%9YB*c@Env;{SP@Z3ulfosz0{~YCEGYm0 literal 0 HcmV?d00001 diff --git a/unixfs/node/file/fixtures/QmT8EC9sJq63SkDZ1mWLbWWyVV66PuqyHWpKkH4pcVyY4H.car b/unixfs/node/file/fixtures/QmT8EC9sJq63SkDZ1mWLbWWyVV66PuqyHWpKkH4pcVyY4H.car new file mode 100644 index 0000000000000000000000000000000000000000..88b4a08ebe13cf9f5c9c8d688789945a36c6f313 GIT binary patch literal 198 zcmcCmlv(-Hr6pN0Ch zUFl`1Ma7xbZnCn1pyTQgd?h70UCAa#FY?cmOuMRj~j7 literal 0 HcmV?d00001 diff --git a/unixfs/node/file/shard.go b/unixfs/node/file/shard.go new file mode 100644 index 000000000..303054f5f --- /dev/null +++ b/unixfs/node/file/shard.go @@ -0,0 +1,154 @@ +package file + +import ( + "context" + "io" + + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" + cidlink "github.com/ipld/go-ipld-prime/linking/cid" + "github.com/ipld/go-ipld-prime/node/basicnode" + "github.com/multiformats/go-multicodec" +) + +type shardNodeFile struct { + ctx context.Context + lsys *ipld.LinkSystem + substrate ipld.Node + done bool + rdr io.Reader +} + +var _ ipld.Node = (*shardNodeFile)(nil) + +func (s *shardNodeFile) Read(p []byte) (int, error) { + if s.done { + return 0, io.EOF + } + // collect the sub-nodes on first use + if s.rdr == nil { + links, err := s.substrate.LookupByString("Links") + if err != nil { + return 0, err + } + readers := make([]io.Reader, 0) + lnki := links.ListIterator() + for !lnki.Done() { + _, lnk, err := lnki.Next() + if err != nil { + return 0, err + } + lnkhash, err := lnk.LookupByString("Hash") + if err != nil { + return 0, err + } + lnklnk, err := lnkhash.AsLink() + if err != nil { + return 0, err + } + target, err := s.lsys.Load(ipld.LinkContext{Ctx: s.ctx}, lnklnk, protoFor(lnklnk)) + if err != nil { + return 0, err + } + + asFSNode, err := NewUnixFSFile(s.ctx, target, s.lsys) + if err != nil { + return 0, err + } + readers = append(readers, asFSNode) + } + s.rdr = io.MultiReader(readers...) + } + n, err := s.rdr.Read(p) + if err == io.EOF { + s.rdr = nil + s.done = true + } + return n, err +} + +func protoFor(link ipld.Link) ipld.NodePrototype { + if lc, ok := link.(cidlink.Link); ok { + if lc.Cid.Prefix().Codec == uint64(multicodec.DagPb) { + return dagpb.Type.PBNode + } + } + return basicnode.Prototype.Any +} + +func (s *shardNodeFile) Kind() ipld.Kind { + return ipld.Kind_Bytes +} + +func (s *shardNodeFile) AsBytes() ([]byte, error) { + return io.ReadAll(s) +} + +func (s *shardNodeFile) AsBool() (bool, error) { + return false, ipld.ErrWrongKind{TypeName: "bool", MethodName: "AsBool", AppropriateKind: ipld.KindSet_JustBytes} +} + +func (s *shardNodeFile) AsInt() (int64, error) { + return 0, ipld.ErrWrongKind{TypeName: "int", MethodName: "AsInt", AppropriateKind: ipld.KindSet_JustBytes} +} + +func (s *shardNodeFile) AsFloat() (float64, error) { + return 0, ipld.ErrWrongKind{TypeName: "float", MethodName: "AsFloat", AppropriateKind: ipld.KindSet_JustBytes} +} + +func (s *shardNodeFile) AsString() (string, error) { + return "", ipld.ErrWrongKind{TypeName: "string", MethodName: "AsString", AppropriateKind: ipld.KindSet_JustBytes} +} + +func (s *shardNodeFile) AsLink() (ipld.Link, error) { + return nil, ipld.ErrWrongKind{TypeName: "link", MethodName: "AsLink", AppropriateKind: ipld.KindSet_JustBytes} +} + +func (s *shardNodeFile) AsNode() (ipld.Node, error) { + return nil, nil +} + +func (s *shardNodeFile) Size() int { + return 0 +} + +func (s *shardNodeFile) IsAbsent() bool { + return false +} + +func (s *shardNodeFile) IsNull() bool { + return s.substrate.IsNull() +} + +func (s *shardNodeFile) Length() int64 { + return 0 +} + +func (s *shardNodeFile) ListIterator() ipld.ListIterator { + return nil +} + +func (s *shardNodeFile) MapIterator() ipld.MapIterator { + return nil +} + +func (s *shardNodeFile) LookupByIndex(idx int64) (ipld.Node, error) { + return nil, ipld.ErrWrongKind{} +} + +func (s *shardNodeFile) LookupByString(key string) (ipld.Node, error) { + return nil, ipld.ErrWrongKind{} +} + +func (s *shardNodeFile) LookupByNode(key ipld.Node) (ipld.Node, error) { + return nil, ipld.ErrWrongKind{} +} + +func (s *shardNodeFile) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return nil, ipld.ErrWrongKind{} +} + +// shardded files / nodes look like dagpb nodes. +func (s *shardNodeFile) Prototype() ipld.NodePrototype { + return dagpb.Type.PBNode +} diff --git a/unixfs/node/file/wrapped.go b/unixfs/node/file/wrapped.go new file mode 100644 index 000000000..56b2c6ccc --- /dev/null +++ b/unixfs/node/file/wrapped.go @@ -0,0 +1,34 @@ +package file + +import ( + "github.com/ipfs/go-unixfsnode/data" + "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/node/basicnode" +) + +func newWrappedNode(substrate ipld.Node) (StreamableByteNode, error) { + dataField, err := substrate.LookupByString("Data") + if err != nil { + return nil, err + } + // unpack as unixfs proto. + dfb, err := dataField.AsBytes() + if err != nil { + return nil, err + } + ufd, err := data.DecodeUnixFSData(dfb) + if err != nil { + return nil, err + } + + if ufd.Data.Exists() { + return &singleNodeFile{ + Node: ufd.Data.Must(), + }, nil + } + + // an empty degenerate one. + return &singleNodeFile{ + Node: basicnode.NewBytes(nil), + }, nil +} diff --git a/unixfs/node/reification.go b/unixfs/node/reification.go index 9a0244c44..fc79291f4 100644 --- a/unixfs/node/reification.go +++ b/unixfs/node/reification.go @@ -6,6 +6,7 @@ import ( "github.com/ipfs/go-unixfsnode/data" "github.com/ipfs/go-unixfsnode/directory" + "github.com/ipfs/go-unixfsnode/file" "github.com/ipfs/go-unixfsnode/hamt" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" @@ -37,9 +38,9 @@ func Reify(lnkCtx ipld.LinkContext, maybePBNodeRoot ipld.Node, lsys *ipld.LinkSy type reifyTypeFunc func(context.Context, dagpb.PBNode, data.UnixFSData, *ipld.LinkSystem) (ipld.Node, error) var reifyFuncs = map[int64]reifyTypeFunc{ - data.Data_File: defaultUnixFSReifier, + data.Data_File: unixFSFileReifier, data.Data_Metadata: defaultUnixFSReifier, - data.Data_Raw: defaultUnixFSReifier, + data.Data_Raw: unixFSFileReifier, data.Data_Symlink: defaultUnixFSReifier, data.Data_Directory: directory.NewUnixFSBasicDir, data.Data_HAMTShard: hamt.NewUnixFSHAMTShard, @@ -51,6 +52,10 @@ func defaultReifier(_ context.Context, substrate dagpb.PBNode, _ *ipld.LinkSyste return &_PathedPBNode{_substrate: substrate}, nil } +func unixFSFileReifier(ctx context.Context, substrate dagpb.PBNode, _ data.UnixFSData, ls *ipld.LinkSystem) (ipld.Node, error) { + return file.NewUnixFSFile(ctx, substrate, ls) +} + func defaultUnixFSReifier(ctx context.Context, substrate dagpb.PBNode, _ data.UnixFSData, ls *ipld.LinkSystem) (ipld.Node, error) { return defaultReifier(ctx, substrate, ls) } From 4d9dcddfb56d39406ff93a38548b56a566c710f0 Mon Sep 17 00:00:00 2001 From: Will Date: Fri, 5 Nov 2021 05:10:48 -0700 Subject: [PATCH 17/43] handle empty files (#15) This commit was moved from ipfs/go-unixfsnode@b9b6e9dc571e3fd0a3e4ee53987f07e0ff8008da --- unixfs/node/data/builder/directory.go | 2 ++ unixfs/node/data/builder/file.go | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/unixfs/node/data/builder/directory.go b/unixfs/node/data/builder/directory.go index c6b054939..019bc4174 100644 --- a/unixfs/node/data/builder/directory.go +++ b/unixfs/node/data/builder/directory.go @@ -77,6 +77,8 @@ func estimateDirSize(entries []dagpb.PBLink) int { cl, ok := lnk.(cidlink.Link) if ok { s += cl.ByteLen() + } else if lnk == nil { + s += 0 } else { s += len(lnk.Binary()) } diff --git a/unixfs/node/data/builder/file.go b/unixfs/node/data/builder/file.go index dcf3b810e..dd3448b59 100644 --- a/unixfs/node/data/builder/file.go +++ b/unixfs/node/data/builder/file.go @@ -43,6 +43,11 @@ func BuildUnixFSFile(r io.Reader, chunker string, ls *ipld.LinkSystem) (ipld.Lin } if prev != nil && prev[0] == root { + if root == nil { + node := basicnode.NewBytes([]byte{}) + link, err := ls.Store(ipld.LinkContext{}, leafLinkProto, node) + return link, 0, err + } return root, size, nil } From c587c00dc31ed3982f8c8465528291f9f87bb63c Mon Sep 17 00:00:00 2001 From: Will Date: Thu, 2 Dec 2021 08:57:16 -0800 Subject: [PATCH 18/43] add license (#17) fix #16 This commit was moved from ipfs/go-unixfsnode@d21ca04ca27e44757f563672280104691746aadd --- unixfs/node/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/unixfs/node/README.md b/unixfs/node/README.md index 675960209..2146b6c8e 100644 --- a/unixfs/node/README.md +++ b/unixfs/node/README.md @@ -2,4 +2,8 @@ This is an IPLD ADL that provides string based pathing for protobuf nodes. The top level node behaves like a map where LookupByString returns the Hash property on the Link in the protobufs list of Links whos Name property matches the key. This should enable selector traversals that work based of paths. -Note that while it works internally with go-codec-dagpb, the Reify method (used to get a UnixFSNode from a DagPB node should actually work successfully with go-ipld-prime-proto nodes) \ No newline at end of file +Note that while it works internally with go-codec-dagpb, the Reify method (used to get a UnixFSNode from a DagPB node should actually work successfully with go-ipld-prime-proto nodes) + +## License + +Apache-2.0/MIT © Protocol Labs From f3fe24feac59113edf767172e338181959a72573 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Tue, 21 Dec 2021 15:18:18 -0500 Subject: [PATCH 19/43] chore: update deps This commit was moved from ipfs/go-unixfsnode@b2ae22e83798928ab28ff9d64a2b0dc680e2397c --- unixfs/node/data/builder/directory.go | 2 +- unixfs/node/file/file_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/unixfs/node/data/builder/directory.go b/unixfs/node/data/builder/directory.go index 019bc4174..3ea9e36b5 100644 --- a/unixfs/node/data/builder/directory.go +++ b/unixfs/node/data/builder/directory.go @@ -89,7 +89,7 @@ func estimateDirSize(entries []dagpb.PBLink) int { // BuildUnixFSDirectory creates a directory link over a collection of entries. func BuildUnixFSDirectory(entries []dagpb.PBLink, ls *ipld.LinkSystem) (ipld.Link, error) { if estimateDirSize(entries) > shardSplitThreshold { - return BuildUnixFSShardedDirectory(defaultShardWidth, multihash.MURMUR3_128, entries, ls) + return BuildUnixFSShardedDirectory(defaultShardWidth, multihash.MURMUR3X64_64, entries, ls) } ufd, err := BuildUnixFS(func(b *Builder) { DataType(b, data.Data_Directory) diff --git a/unixfs/node/file/file_test.go b/unixfs/node/file/file_test.go index 17d221fe4..ee01a71d7 100644 --- a/unixfs/node/file/file_test.go +++ b/unixfs/node/file/file_test.go @@ -67,12 +67,12 @@ func open(car string, t *testing.T) (ipld.Node, *ipld.LinkSystem) { t.Fatal(err) } ls := cidlink.DefaultLinkSystem() - ls.StorageReadOpener = func(_ ipld.LinkContext, l ipld.Link) (io.Reader, error) { + ls.StorageReadOpener = func(lctx ipld.LinkContext, l ipld.Link) (io.Reader, error) { cl, ok := l.(cidlink.Link) if !ok { return nil, fmt.Errorf("couldn't load link") } - blk, err := baseStore.Get(cl.Cid) + blk, err := baseStore.Get(lctx.Ctx, cl.Cid) if err != nil { return nil, err } From 9b82c0474f6ec9d9da176add4e61c97eb5f252f3 Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Mon, 10 Jan 2022 13:34:26 -0800 Subject: [PATCH 20/43] feat(unixfsnode): add utils for signalling for selectors This commit was moved from ipfs/go-unixfsnode@c487b3de0a4ebec6b0ef0a06741c7f545fa56a69 --- unixfs/node/signaling.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 unixfs/node/signaling.go diff --git a/unixfs/node/signaling.go b/unixfs/node/signaling.go new file mode 100644 index 000000000..a2dee3d9c --- /dev/null +++ b/unixfs/node/signaling.go @@ -0,0 +1,34 @@ +package unixfsnode + +import ( + "strings" + + "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/datamodel" + "github.com/ipld/go-ipld-prime/linking" + "github.com/ipld/go-ipld-prime/node/basicnode" + "github.com/ipld/go-ipld-prime/traversal/selector/builder" +) + +func AddUnixFSReificationToLinkSystem(lsys *ipld.LinkSystem) { + if lsys.KnownReifiers == nil { + lsys.KnownReifiers = make(map[string]linking.NodeReifier) + } + lsys.KnownReifiers["unixfs"] = Reify +} + +// UnixFSPathSelector creates a selector for a file/path inside of a UnixFS directory +// if reification is setup on a link system +func UnixFSPathSelector(path string) datamodel.Node { + segments := strings.Split(path, "/") + ssb := builder.NewSelectorSpecBuilder(basicnode.Prototype.Any) + selectorSoFar := ssb.Matcher() + for i := len(segments) - 1; i >= 0; i-- { + selectorSoFar = ssb.ExploreInterpretAs("unixfs", + ssb.ExploreFields(func(efsb builder.ExploreFieldsSpecBuilder) { + efsb.Insert(segments[i], selectorSoFar) + }), + ) + } + return selectorSoFar.Node() +} From ee986c8a68b9112d97b43978f03e1aa478eb9f11 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Fri, 21 Jan 2022 15:31:04 +1100 Subject: [PATCH 21/43] fix: encode Tsize correctly everywhere (using wraped LinkSystem) This commit was moved from ipfs/go-unixfsnode@981d6848d40b6834543296b13611e8b66c731fa3 --- unixfs/node/data/builder/dir_test.go | 70 ++++++++++++++++++++++++++- unixfs/node/data/builder/directory.go | 40 +++++++++------ unixfs/node/data/builder/dirshard.go | 40 +++++++-------- unixfs/node/data/builder/file.go | 41 ++-------------- unixfs/node/data/builder/util.go | 53 ++++++++++++++++++++ 5 files changed, 171 insertions(+), 73 deletions(-) diff --git a/unixfs/node/data/builder/dir_test.go b/unixfs/node/data/builder/dir_test.go index 954d2dd17..b12372225 100644 --- a/unixfs/node/data/builder/dir_test.go +++ b/unixfs/node/data/builder/dir_test.go @@ -3,12 +3,16 @@ package builder import ( "bytes" "fmt" + "os" + "path/filepath" "testing" + "github.com/ipfs/go-cid" "github.com/ipfs/go-unixfsnode" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" + "github.com/stretchr/testify/require" ) func mkEntries(cnt int, ls *ipld.LinkSystem) ([]dagpb.PBLink, error) { @@ -41,11 +45,13 @@ func TestBuildUnixFSDirectory(t *testing.T) { t.Fatal(err) } - dl, err := BuildUnixFSDirectory(entries, &ls) + dl, tsize, err := BuildUnixFSDirectory(entries, &ls) if err != nil { t.Fatal(err) } + require.GreaterOrEqual(t, tsize, uint64(0)) // TODO: set properly + pbn, err := ls.Load(ipld.LinkContext{}, dl, dagpb.Type.PBNode) if err != nil { t.Fatal(err) @@ -70,3 +76,65 @@ func TestBuildUnixFSDirectory(t *testing.T) { } } } + +func TestBuildUnixFSRecursive(t *testing.T) { + // only the top CID is of interest, but this tree is correct and can be used for future validation + fixture := fentry{ + "rootDir", + "", + mustCidDecode("bafybeihswl3f7pa7fueyayewcvr3clkdz7oetv4jolyejgw26p6l3qzlbm"), + []fentry{ + {"a", "aaa", mustCidDecode("bafkreieygsdw3t5qlsywpjocjfj6xjmmjlejwgw7k7zi6l45bgxra7xi6a"), nil}, + { + "b", + "", + mustCidDecode("bafybeibohj54uixf2mso4t53suyarv6cfuxt6b5cj6qjsqaa2ezfxnu5pu"), + []fentry{ + {"1", "111", mustCidDecode("bafkreihw4cq6flcbsrnjvj77rkfkudhlyevdxteydkjjvvopqefasdqrvy"), nil}, + {"2", "222", mustCidDecode("bafkreie3q4kremt4bhhjdxletm7znjr3oqeo6jt4rtcxcaiu4yuxgdfwd4"), nil}, + }, + }, + {"c", "ccc", mustCidDecode("bafkreide3ksevvet74uks3x7vnxhp4ltfi6zpwbsifmbwn6324fhusia7y"), nil}, + }, + } + + ls := cidlink.DefaultLinkSystem() + storage := cidlink.Memory{} + ls.StorageReadOpener = storage.OpenRead + ls.StorageWriteOpener = storage.OpenWrite + + dir := t.TempDir() + makeFixture(t, dir, fixture) + + lnk, sz, err := BuildUnixFSRecursive(filepath.Join(dir, fixture.name), &ls) + require.NoError(t, err) + require.Equal(t, lnk.String(), fixture.expectedLnk.String()) + require.Equal(t, sz, uint64(245)) +} + +type fentry struct { + name string + content string + expectedLnk cid.Cid + children []fentry +} + +func makeFixture(t *testing.T, dir string, fixture fentry) { + path := filepath.Join(dir, fixture.name) + if fixture.children != nil { + require.NoError(t, os.Mkdir(path, 0755)) + for _, c := range fixture.children { + makeFixture(t, path, c) + } + } else { + os.WriteFile(path, []byte(fixture.content), 0644) + } +} + +func mustCidDecode(s string) cid.Cid { + c, err := cid.Decode(s) + if err != nil { + panic(err) + } + return c +} diff --git a/unixfs/node/data/builder/directory.go b/unixfs/node/data/builder/directory.go index 3ea9e36b5..55a3cb939 100644 --- a/unixfs/node/data/builder/directory.go +++ b/unixfs/node/data/builder/directory.go @@ -30,6 +30,7 @@ func BuildUnixFSRecursive(root string, ls *ipld.LinkSystem) (ipld.Link, uint64, m := info.Mode() switch { case m.IsDir(): + var tsize uint64 entries, err := os.ReadDir(root) if err != nil { return nil, 0, err @@ -40,27 +41,36 @@ func BuildUnixFSRecursive(root string, ls *ipld.LinkSystem) (ipld.Link, uint64, if err != nil { return nil, 0, err } + tsize += sz entry, err := BuildUnixFSDirectoryEntry(e.Name(), int64(sz), lnk) if err != nil { return nil, 0, err } lnks = append(lnks, entry) } - outLnk, err := BuildUnixFSDirectory(lnks, ls) - return outLnk, 0, err + outLnk, sz, err := BuildUnixFSDirectory(lnks, ls) + return outLnk, tsize + sz, err case m.Type() == fs.ModeSymlink: content, err := os.Readlink(root) if err != nil { return nil, 0, err } - return BuildUnixFSSymlink(content, ls) + outLnk, sz, err := BuildUnixFSSymlink(content, ls) + if err != nil { + return nil, 0, err + } + return outLnk, sz, nil case m.IsRegular(): fp, err := os.Open(root) if err != nil { return nil, 0, err } defer fp.Close() - return BuildUnixFSFile(fp, "", ls) + outLnk, sz, err := BuildUnixFSFile(fp, "", ls) + if err != nil { + return nil, 0, err + } + return outLnk, sz, nil default: return nil, 0, fmt.Errorf("cannot encode non regular file: %s", root) } @@ -87,7 +97,7 @@ func estimateDirSize(entries []dagpb.PBLink) int { } // BuildUnixFSDirectory creates a directory link over a collection of entries. -func BuildUnixFSDirectory(entries []dagpb.PBLink, ls *ipld.LinkSystem) (ipld.Link, error) { +func BuildUnixFSDirectory(entries []dagpb.PBLink, ls *ipld.LinkSystem) (ipld.Link, uint64, error) { if estimateDirSize(entries) > shardSplitThreshold { return BuildUnixFSShardedDirectory(defaultShardWidth, multihash.MURMUR3X64_64, entries, ls) } @@ -95,38 +105,38 @@ func BuildUnixFSDirectory(entries []dagpb.PBLink, ls *ipld.LinkSystem) (ipld.Lin DataType(b, data.Data_Directory) }) if err != nil { - return nil, err + return nil, 0, err } pbb := dagpb.Type.PBNode.NewBuilder() pbm, err := pbb.BeginMap(2) if err != nil { - return nil, err + return nil, 0, err } if err = pbm.AssembleKey().AssignString("Data"); err != nil { - return nil, err + return nil, 0, err } if err = pbm.AssembleValue().AssignBytes(data.EncodeUnixFSData(ufd)); err != nil { - return nil, err + return nil, 0, err } if err = pbm.AssembleKey().AssignString("Links"); err != nil { - return nil, err + return nil, 0, err } lnks, err := pbm.AssembleValue().BeginList(int64(len(entries))) if err != nil { - return nil, err + return nil, 0, err } // sorting happens in codec-dagpb for _, e := range entries { if err := lnks.AssembleValue().AssignNode(e); err != nil { - return nil, err + return nil, 0, err } } if err := lnks.Finish(); err != nil { - return nil, err + return nil, 0, err } if err := pbm.Finish(); err != nil { - return nil, err + return nil, 0, err } node := pbb.Build() - return ls.Store(ipld.LinkContext{}, fileLinkProto, node) + return sizedStore(ls, fileLinkProto, node) } diff --git a/unixfs/node/data/builder/dirshard.go b/unixfs/node/data/builder/dirshard.go index a25aa66ce..b7bf9a62d 100644 --- a/unixfs/node/data/builder/dirshard.go +++ b/unixfs/node/data/builder/dirshard.go @@ -39,7 +39,7 @@ type hamtLink struct { // BuildUnixFSShardedDirectory will build a hamt of unixfs hamt shards encoing a directory with more entries // than is typically allowed to fit in a standard IPFS single-block unixFS directory. -func BuildUnixFSShardedDirectory(size int, hasher uint64, entries []dagpb.PBLink, ls *ipld.LinkSystem) (ipld.Link, error) { +func BuildUnixFSShardedDirectory(size int, hasher uint64, entries []dagpb.PBLink, ls *ipld.LinkSystem) (ipld.Link, uint64, error) { // hash the entries var h hash.Hash var err error @@ -50,7 +50,7 @@ func BuildUnixFSShardedDirectory(size int, hasher uint64, entries []dagpb.PBLink } else { h, err = multihash.GetHasher(hasher) if err != nil { - return nil, err + return nil, 0, err } } hamtEntries := make([]hamtLink, 0, len(entries)) @@ -65,7 +65,7 @@ func BuildUnixFSShardedDirectory(size int, hasher uint64, entries []dagpb.PBLink sizeLg2, err := logtwo(size) if err != nil { - return nil, err + return nil, 0, err } sharder := shard{ @@ -81,7 +81,7 @@ func BuildUnixFSShardedDirectory(size int, hasher uint64, entries []dagpb.PBLink for _, entry := range hamtEntries { err := sharder.add(entry) if err != nil { - return nil, err + return nil, 0, err } } @@ -138,7 +138,7 @@ func (s *shard) bitmap() []byte { // serialize stores the concrete representation of this shard in the link system and // returns a link to it. -func (s *shard) serialize(ls *ipld.LinkSystem) (ipld.Link, error) { +func (s *shard) serialize(ls *ipld.LinkSystem) (ipld.Link, uint64, error) { ufd, err := BuildUnixFS(func(b *Builder) { DataType(b, data.Data_HAMTShard) HashType(b, s.hasher) @@ -146,59 +146,59 @@ func (s *shard) serialize(ls *ipld.LinkSystem) (ipld.Link, error) { Fanout(b, uint64(s.size)) }) if err != nil { - return nil, err + return nil, 0, err } pbb := dagpb.Type.PBNode.NewBuilder() pbm, err := pbb.BeginMap(2) if err != nil { - return nil, err + return nil, 0, err } if err = pbm.AssembleKey().AssignString("Data"); err != nil { - return nil, err + return nil, 0, err } if err = pbm.AssembleValue().AssignBytes(data.EncodeUnixFSData(ufd)); err != nil { - return nil, err + return nil, 0, err } if err = pbm.AssembleKey().AssignString("Links"); err != nil { - return nil, err + return nil, 0, err } lnkBuilder := dagpb.Type.PBLinks.NewBuilder() lnks, err := lnkBuilder.BeginList(int64(len(s.children))) if err != nil { - return nil, err + return nil, 0, err } // sorting happens in codec-dagpb for idx, e := range s.children { var lnk dagpb.PBLink if e.shard != nil { - ipldLnk, err := e.shard.serialize(ls) + ipldLnk, sz, err := e.shard.serialize(ls) if err != nil { - return nil, err + return nil, 0, err } fullName := s.formatLinkName("", idx) - lnk, err = BuildUnixFSDirectoryEntry(fullName, 0, ipldLnk) + lnk, err = BuildUnixFSDirectoryEntry(fullName, int64(sz), ipldLnk) if err != nil { - return nil, err + return nil, 0, err } } else { fullName := s.formatLinkName(e.Name.Must().String(), idx) lnk, err = BuildUnixFSDirectoryEntry(fullName, e.Tsize.Must().Int(), e.Hash.Link()) } if err != nil { - return nil, err + return nil, 0, err } if err := lnks.AssembleValue().AssignNode(lnk); err != nil { - return nil, err + return nil, 0, err } } if err := lnks.Finish(); err != nil { - return nil, err + return nil, 0, err } pbm.AssembleValue().AssignNode(lnkBuilder.Build()) if err := pbm.Finish(); err != nil { - return nil, err + return nil, 0, err } node := pbb.Build() - return ls.Store(ipld.LinkContext{}, fileLinkProto, node) + return sizedStore(ls, fileLinkProto, node) } diff --git a/unixfs/node/data/builder/file.go b/unixfs/node/data/builder/file.go index dd3448b59..8e2e6f158 100644 --- a/unixfs/node/data/builder/file.go +++ b/unixfs/node/data/builder/file.go @@ -86,8 +86,7 @@ func fileTreeRecursive(depth int, children []ipld.Link, childLen []uint64, src c return nil, 0, err } node := basicnode.NewBytes(leaf) - link, err := ls.Store(ipld.LinkContext{}, leafLinkProto, node) - return link, uint64(len(leaf)), err + return sizedStore(ls, leafLinkProto, node) } // depth > 1. totalSize := uint64(0) @@ -166,25 +165,11 @@ func fileTreeRecursive(depth int, children []ipld.Link, childLen []uint64, src c } pbn := dpbb.Build() - link, err := ls.Store(ipld.LinkContext{}, fileLinkProto, pbn) + link, sz, err := sizedStore(ls, fileLinkProto, pbn) if err != nil { return nil, 0, err } - // calculate the dagpb node's size and add as overhead. - cl, ok := link.(cidlink.Link) - if !ok { - return nil, 0, fmt.Errorf("unexpected non-cid linksystem") - } - rawlnk := cid.NewCidV1(uint64(multicodec.Raw), cl.Cid.Hash()) - rn, err := ls.Load(ipld.LinkContext{}, cidlink.Link{Cid: rawlnk}, basicnode.Prototype__Bytes{}) - if err != nil { - return nil, 0, fmt.Errorf("could not re-interpret dagpb node as bytes: %w", err) - } - rnb, err := rn.AsBytes() - if err != nil { - return nil, 0, fmt.Errorf("could not parse dagpb node as bytes: %w", err) - } - return link, totalSize + uint64(len(rnb)), nil + return link, totalSize + sz, nil } // BuildUnixFSDirectoryEntry creates the link to a file or directory as it appears within a unixfs directory. @@ -256,25 +241,7 @@ func BuildUnixFSSymlink(content string, ls *ipld.LinkSystem) (ipld.Link, uint64, } pbn := dpbb.Build() - link, err := ls.Store(ipld.LinkContext{}, fileLinkProto, pbn) - if err != nil { - return nil, 0, err - } - // calculate the size and add as overhead. - cl, ok := link.(cidlink.Link) - if !ok { - return nil, 0, fmt.Errorf("unexpected non-cid linksystem") - } - rawlnk := cid.NewCidV1(uint64(multicodec.Raw), cl.Cid.Hash()) - rn, err := ls.Load(ipld.LinkContext{}, cidlink.Link{Cid: rawlnk}, basicnode.Prototype__Bytes{}) - if err != nil { - return nil, 0, fmt.Errorf("could not re-interpret dagpb node as bytes: %w", err) - } - rnb, err := rn.AsBytes() - if err != nil { - return nil, 0, fmt.Errorf("could not re-interpret dagpb node as bytes: %w", err) - } - return link, uint64(len(rnb)), nil + return sizedStore(ls, fileLinkProto, pbn) } // Constants below are from diff --git a/unixfs/node/data/builder/util.go b/unixfs/node/data/builder/util.go index 8e5c0fbe2..808a5ff59 100644 --- a/unixfs/node/data/builder/util.go +++ b/unixfs/node/data/builder/util.go @@ -2,7 +2,12 @@ package builder import ( "fmt" + "io" "math/bits" + + "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/codec" + "github.com/ipld/go-ipld-prime/datamodel" ) // Common code from go-unixfs/hamt/util.go @@ -54,3 +59,51 @@ func logtwo(v int) (int, error) { } return lg2, nil } + +func sizedStore(ls *ipld.LinkSystem, lp datamodel.LinkPrototype, n datamodel.Node) (datamodel.Link, uint64, error) { + var byteCount int + lnk, err := wrappedLinkSystem(ls, func(bc int) { + byteCount = bc + }).Store(ipld.LinkContext{}, lp, n) + return lnk, uint64(byteCount), err +} + +type byteCounter struct { + w io.Writer + bc int +} + +func (bc *byteCounter) Write(p []byte) (int, error) { + bc.bc += len(p) + return bc.w.Write(p) +} + +func wrappedLinkSystem(ls *ipld.LinkSystem, byteCountCb func(byteCount int)) *ipld.LinkSystem { + wrappedEncoder := func(encoder codec.Encoder) codec.Encoder { + return func(node datamodel.Node, writer io.Writer) error { + bc := byteCounter{w: writer} + err := encoder(node, &bc) + if err == nil { + byteCountCb(bc.bc) + } + return err + } + } + wrappedEncoderChooser := func(lp datamodel.LinkPrototype) (codec.Encoder, error) { + encoder, err := ls.EncoderChooser(lp) + if err != nil { + return nil, err + } + return wrappedEncoder(encoder), nil + } + return &ipld.LinkSystem{ + EncoderChooser: wrappedEncoderChooser, + DecoderChooser: ls.DecoderChooser, + HasherChooser: ls.HasherChooser, + StorageWriteOpener: ls.StorageWriteOpener, + StorageReadOpener: ls.StorageReadOpener, + TrustedStorage: ls.TrustedStorage, + NodeReifier: ls.NodeReifier, + KnownReifiers: ls.KnownReifiers, + } +} From 16909696d7588a9c765b51d8612aa882b2e64c72 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Fri, 21 Jan 2022 17:33:31 +1100 Subject: [PATCH 22/43] fix: more Tsize fixes, fix HAMT and make it match go-unixfs output This commit was moved from ipfs/go-unixfsnode@bbf0ec6e9546cf5de051db8945c9f44dcc392c52 --- unixfs/node/data/builder/dir_test.go | 36 +++++++++++++++++++++++---- unixfs/node/data/builder/directory.go | 11 +++++--- unixfs/node/data/builder/dirshard.go | 23 ++++++++++++++--- 3 files changed, 58 insertions(+), 12 deletions(-) diff --git a/unixfs/node/data/builder/dir_test.go b/unixfs/node/data/builder/dir_test.go index b12372225..fd0b96e8c 100644 --- a/unixfs/node/data/builder/dir_test.go +++ b/unixfs/node/data/builder/dir_test.go @@ -45,13 +45,11 @@ func TestBuildUnixFSDirectory(t *testing.T) { t.Fatal(err) } - dl, tsize, err := BuildUnixFSDirectory(entries, &ls) + dl, _, err := BuildUnixFSDirectory(entries, &ls) if err != nil { t.Fatal(err) } - require.GreaterOrEqual(t, tsize, uint64(0)) // TODO: set properly - pbn, err := ls.Load(ipld.LinkContext{}, dl, dagpb.Type.PBNode) if err != nil { t.Fatal(err) @@ -108,8 +106,36 @@ func TestBuildUnixFSRecursive(t *testing.T) { lnk, sz, err := BuildUnixFSRecursive(filepath.Join(dir, fixture.name), &ls) require.NoError(t, err) - require.Equal(t, lnk.String(), fixture.expectedLnk.String()) - require.Equal(t, sz, uint64(245)) + require.Equal(t, fixture.expectedLnk.String(), lnk.String()) + require.Equal(t, uint64(245), sz) +} + +func TestBuildUnixFSRecursiveSharded(t *testing.T) { + // only the top CID is of interest, but this tree is correct and can be used for future validation + fixture := fentry{ + "rootDir", + "", + mustCidDecode("bafybeiendaawtta62lx2p2e2hecgywmqeq6ekrn2pfypxjkmdzmaeituhe"), + make([]fentry, 0), + } + + for i := 0; i < 2048; i++ { + name := fmt.Sprintf("long name to fill out bytes to make the sharded directory test flip over the sharded directory limit because link names are included in the directory entry %d", i) + fixture.children = append(fixture.children, fentry{name, name, cid.Undef, nil}) + } + + ls := cidlink.DefaultLinkSystem() + storage := cidlink.Memory{} + ls.StorageReadOpener = storage.OpenRead + ls.StorageWriteOpener = storage.OpenWrite + + dir := t.TempDir() + makeFixture(t, dir, fixture) + + lnk, sz, err := BuildUnixFSRecursive(filepath.Join(dir, fixture.name), &ls) + require.NoError(t, err) + require.Equal(t, fixture.expectedLnk.String(), lnk.String()) + require.Equal(t, uint64(778128), sz) } type fentry struct { diff --git a/unixfs/node/data/builder/directory.go b/unixfs/node/data/builder/directory.go index 55a3cb939..afb83e6a3 100644 --- a/unixfs/node/data/builder/directory.go +++ b/unixfs/node/data/builder/directory.go @@ -48,8 +48,7 @@ func BuildUnixFSRecursive(root string, ls *ipld.LinkSystem) (ipld.Link, uint64, } lnks = append(lnks, entry) } - outLnk, sz, err := BuildUnixFSDirectory(lnks, ls) - return outLnk, tsize + sz, err + return BuildUnixFSDirectory(lnks, ls) case m.Type() == fs.ModeSymlink: content, err := os.Readlink(root) if err != nil { @@ -126,7 +125,9 @@ func BuildUnixFSDirectory(entries []dagpb.PBLink, ls *ipld.LinkSystem) (ipld.Lin return nil, 0, err } // sorting happens in codec-dagpb + var totalSize uint64 for _, e := range entries { + totalSize += uint64(e.Tsize.Must().Int()) if err := lnks.AssembleValue().AssignNode(e); err != nil { return nil, 0, err } @@ -138,5 +139,9 @@ func BuildUnixFSDirectory(entries []dagpb.PBLink, ls *ipld.LinkSystem) (ipld.Lin return nil, 0, err } node := pbb.Build() - return sizedStore(ls, fileLinkProto, node) + lnk, sz, err := sizedStore(ls, fileLinkProto, node) + if err != nil { + return nil, 0, err + } + return lnk, totalSize + sz, err } diff --git a/unixfs/node/data/builder/dirshard.go b/unixfs/node/data/builder/dirshard.go index b7bf9a62d..299c81f22 100644 --- a/unixfs/node/data/builder/dirshard.go +++ b/unixfs/node/data/builder/dirshard.go @@ -56,7 +56,9 @@ func BuildUnixFSShardedDirectory(size int, hasher uint64, entries []dagpb.PBLink hamtEntries := make([]hamtLink, 0, len(entries)) for _, e := range entries { name := e.Name.Must().String() - sum := h.Sum([]byte(name)) + h.Reset() + h.Write([]byte(name)) + sum := h.Sum(nil) hamtEntries = append(hamtEntries, hamtLink{ sum, e, @@ -97,9 +99,11 @@ func (s *shard) add(lnk hamtLink) error { current, ok := s.children[bucket] if !ok { + // no bucket, make one with this entry s.children[bucket] = entry{nil, &lnk} return nil } else if current.shard != nil { + // existing shard, add this link to the shard return current.shard.add(lnk) } // make a shard for current and lnk @@ -114,15 +118,18 @@ func (s *shard) add(lnk hamtLink) error { }, nil, } + // add existing link from this bucket to the new shard if err := newShard.add(*current.hamtLink); err != nil { return err } + // replace bucket with shard s.children[bucket] = newShard + // add new link to the new shard return newShard.add(lnk) } func (s *shard) formatLinkName(name string, idx int) string { - return fmt.Sprintf("%*X%s", s.width, idx, name) + return fmt.Sprintf("%0*X%s", s.width, idx, name) } // bitmap calculates the bitmap of which links in the shard are set. @@ -169,6 +176,7 @@ func (s *shard) serialize(ls *ipld.LinkSystem) (ipld.Link, uint64, error) { return nil, 0, err } // sorting happens in codec-dagpb + var totalSize uint64 for idx, e := range s.children { var lnk dagpb.PBLink if e.shard != nil { @@ -176,6 +184,7 @@ func (s *shard) serialize(ls *ipld.LinkSystem) (ipld.Link, uint64, error) { if err != nil { return nil, 0, err } + totalSize += sz fullName := s.formatLinkName("", idx) lnk, err = BuildUnixFSDirectoryEntry(fullName, int64(sz), ipldLnk) if err != nil { @@ -183,7 +192,9 @@ func (s *shard) serialize(ls *ipld.LinkSystem) (ipld.Link, uint64, error) { } } else { fullName := s.formatLinkName(e.Name.Must().String(), idx) - lnk, err = BuildUnixFSDirectoryEntry(fullName, e.Tsize.Must().Int(), e.Hash.Link()) + sz := e.Tsize.Must().Int() + totalSize += uint64(sz) + lnk, err = BuildUnixFSDirectoryEntry(fullName, sz, e.Hash.Link()) } if err != nil { return nil, 0, err @@ -200,5 +211,9 @@ func (s *shard) serialize(ls *ipld.LinkSystem) (ipld.Link, uint64, error) { return nil, 0, err } node := pbb.Build() - return sizedStore(ls, fileLinkProto, node) + lnk, sz, err := sizedStore(ls, fileLinkProto, node) + if err != nil { + return nil, 0, err + } + return lnk, totalSize + sz, nil } From 79823b0e8265555a9be29bae5c733b37fa6a71d8 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Mon, 24 Jan 2022 14:34:54 +1100 Subject: [PATCH 23/43] fix: add extra test to span the shard/no-shard boundary This commit was moved from ipfs/go-unixfsnode@d3fccee9b573daccbb1b0b6f9972f598d04c321e --- unixfs/node/data/builder/dir_test.go | 39 +++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/unixfs/node/data/builder/dir_test.go b/unixfs/node/data/builder/dir_test.go index fd0b96e8c..a2b069813 100644 --- a/unixfs/node/data/builder/dir_test.go +++ b/unixfs/node/data/builder/dir_test.go @@ -110,16 +110,16 @@ func TestBuildUnixFSRecursive(t *testing.T) { require.Equal(t, uint64(245), sz) } -func TestBuildUnixFSRecursiveSharded(t *testing.T) { +func TestBuildUnixFSRecursiveLargeSharded(t *testing.T) { // only the top CID is of interest, but this tree is correct and can be used for future validation fixture := fentry{ "rootDir", "", - mustCidDecode("bafybeiendaawtta62lx2p2e2hecgywmqeq6ekrn2pfypxjkmdzmaeituhe"), + mustCidDecode("bafybeigyvxs6og5jbmpaa43qbhhd5swklqcfzqdrtjgfh53qjon6hpjaye"), make([]fentry, 0), } - for i := 0; i < 2048; i++ { + for i := 0; i < 1344; i++ { name := fmt.Sprintf("long name to fill out bytes to make the sharded directory test flip over the sharded directory limit because link names are included in the directory entry %d", i) fixture.children = append(fixture.children, fentry{name, name, cid.Undef, nil}) } @@ -135,7 +135,38 @@ func TestBuildUnixFSRecursiveSharded(t *testing.T) { lnk, sz, err := BuildUnixFSRecursive(filepath.Join(dir, fixture.name), &ls) require.NoError(t, err) require.Equal(t, fixture.expectedLnk.String(), lnk.String()) - require.Equal(t, uint64(778128), sz) + require.Equal(t, uint64(515735), sz) +} + +// Same as TestBuildUnixFSRecursiveLargeSharded but it's one file less which flips +// it back to the un-sharded format. So we're testing the boundary condition and +// the proper construction of large DAGs. +func TestBuildUnixFSRecursiveLargeUnsharded(t *testing.T) { + // only the top CID is of interest, but this tree is correct and can be used for future validation + fixture := fentry{ + "rootDir", + "", + mustCidDecode("bafybeihecq4rpl4nw3cgfb2uiwltgsmw5sutouvuldv5fxn4gfbihvnalq"), + make([]fentry, 0), + } + + for i := 0; i < 1343; i++ { + name := fmt.Sprintf("long name to fill out bytes to make the sharded directory test flip over the sharded directory limit because link names are included in the directory entry %d", i) + fixture.children = append(fixture.children, fentry{name, name, cid.Undef, nil}) + } + + ls := cidlink.DefaultLinkSystem() + storage := cidlink.Memory{} + ls.StorageReadOpener = storage.OpenRead + ls.StorageWriteOpener = storage.OpenWrite + + dir := t.TempDir() + makeFixture(t, dir, fixture) + + lnk, sz, err := BuildUnixFSRecursive(filepath.Join(dir, fixture.name), &ls) + require.NoError(t, err) + require.Equal(t, fixture.expectedLnk.String(), lnk.String()) + require.Equal(t, uint64(490665), sz) } type fentry struct { From 1790dea4673717de9f24b73982f5b620161814a8 Mon Sep 17 00:00:00 2001 From: Will Date: Thu, 3 Mar 2022 11:11:28 +0000 Subject: [PATCH 24/43] add AsLargeBytes support to unixfs files (#24) * add AsLargeBytes support to unixfs files This commit was moved from ipfs/go-unixfsnode@94986a76305a01f1f21eb86fb1ed41e5478367f2 --- unixfs/node/data/builder/file_test.go | 3 +- unixfs/node/file/deferred.go | 173 ++++++++++++++++++++++++++ unixfs/node/file/file.go | 43 +++++-- unixfs/node/file/shard.go | 168 +++++++++++++++++++------ unixfs/node/file/wrapped.go | 2 +- 5 files changed, 342 insertions(+), 47 deletions(-) create mode 100644 unixfs/node/file/deferred.go diff --git a/unixfs/node/data/builder/file_test.go b/unixfs/node/data/builder/file_test.go index 58619794d..de3803e4f 100644 --- a/unixfs/node/data/builder/file_test.go +++ b/unixfs/node/data/builder/file_test.go @@ -3,7 +3,6 @@ package builder import ( "bytes" "context" - "io" "testing" "github.com/ipfs/go-cid" @@ -70,7 +69,7 @@ func TestUnixFSFileRoundtrip(t *testing.T) { t.Fatal(err) } // read back out the file. - out, err := io.ReadAll(ufn) + out, err := ufn.AsBytes() if err != nil { t.Fatal(err) } diff --git a/unixfs/node/file/deferred.go b/unixfs/node/file/deferred.go new file mode 100644 index 000000000..44ce8ca27 --- /dev/null +++ b/unixfs/node/file/deferred.go @@ -0,0 +1,173 @@ +package file + +import ( + "context" + "io" + + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" +) + +func newDeferredFileNode(ctx context.Context, lsys *ipld.LinkSystem, root ipld.Link) LargeBytesNode { + dfn := deferredFileNode{ + LargeBytesNode: nil, + root: root, + lsys: lsys, + ctx: ctx, + } + dfn.LargeBytesNode = &deferred{&dfn} + return &dfn +} + +type deferredFileNode struct { + LargeBytesNode + + root ipld.Link + lsys *ipld.LinkSystem + ctx context.Context +} + +func (d *deferredFileNode) resolve() error { + if d.lsys == nil { + return nil + } + target, err := d.lsys.Load(ipld.LinkContext{Ctx: d.ctx}, d.root, protoFor(d.root)) + if err != nil { + return err + } + + asFSNode, err := NewUnixFSFile(d.ctx, target, d.lsys) + if err != nil { + return err + } + d.LargeBytesNode = asFSNode + d.root = nil + d.lsys = nil + d.ctx = nil + return nil +} + +type deferred struct { + *deferredFileNode +} + +type deferredReader struct { + io.ReadSeeker + *deferredFileNode +} + +func (d *deferred) AsLargeBytes() (io.ReadSeeker, error) { + return &deferredReader{nil, d.deferredFileNode}, nil +} + +func (d *deferredReader) Read(p []byte) (int, error) { + if d.ReadSeeker == nil { + if err := d.deferredFileNode.resolve(); err != nil { + return 0, err + } + rs, err := d.deferredFileNode.AsLargeBytes() + if err != nil { + return 0, err + } + d.ReadSeeker = rs + } + return d.ReadSeeker.Read(p) +} + +func (d *deferredReader) Seek(offset int64, whence int) (int64, error) { + if d.ReadSeeker == nil { + if err := d.deferredFileNode.resolve(); err != nil { + return 0, err + } + rs, err := d.deferredFileNode.AsLargeBytes() + if err != nil { + return 0, err + } + d.ReadSeeker = rs + } + return d.ReadSeeker.Seek(offset, whence) +} + +func (d *deferred) Kind() ipld.Kind { + return ipld.Kind_Bytes +} + +func (d *deferred) AsBytes() ([]byte, error) { + if err := d.deferredFileNode.resolve(); err != nil { + return []byte{}, err + } + + return d.deferredFileNode.AsBytes() +} + +func (d *deferred) AsBool() (bool, error) { + return false, ipld.ErrWrongKind{TypeName: "bool", MethodName: "AsBool", AppropriateKind: ipld.KindSet_JustBytes} +} + +func (d *deferred) AsInt() (int64, error) { + return 0, ipld.ErrWrongKind{TypeName: "int", MethodName: "AsInt", AppropriateKind: ipld.KindSet_JustBytes} +} + +func (d *deferred) AsFloat() (float64, error) { + return 0, ipld.ErrWrongKind{TypeName: "float", MethodName: "AsFloat", AppropriateKind: ipld.KindSet_JustBytes} +} + +func (d *deferred) AsString() (string, error) { + return "", ipld.ErrWrongKind{TypeName: "string", MethodName: "AsString", AppropriateKind: ipld.KindSet_JustBytes} +} + +func (d *deferred) AsLink() (ipld.Link, error) { + return nil, ipld.ErrWrongKind{TypeName: "link", MethodName: "AsLink", AppropriateKind: ipld.KindSet_JustBytes} +} + +func (d *deferred) AsNode() (ipld.Node, error) { + return nil, nil +} + +func (d *deferred) Size() int { + return 0 +} + +func (d *deferred) IsAbsent() bool { + return false +} + +func (d *deferred) IsNull() bool { + if err := d.deferredFileNode.resolve(); err != nil { + return true + } + return d.deferredFileNode.IsNull() +} + +func (d *deferred) Length() int64 { + return 0 +} + +func (d *deferred) ListIterator() ipld.ListIterator { + return nil +} + +func (d *deferred) MapIterator() ipld.MapIterator { + return nil +} + +func (d *deferred) LookupByIndex(idx int64) (ipld.Node, error) { + return nil, ipld.ErrWrongKind{} +} + +func (d *deferred) LookupByString(key string) (ipld.Node, error) { + return nil, ipld.ErrWrongKind{} +} + +func (d *deferred) LookupByNode(key ipld.Node) (ipld.Node, error) { + return nil, ipld.ErrWrongKind{} +} + +func (d *deferred) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return nil, ipld.ErrWrongKind{} +} + +// shardded files / nodes look like dagpb nodes. +func (d *deferred) Prototype() ipld.NodePrototype { + return dagpb.Type.PBNode +} diff --git a/unixfs/node/file/file.go b/unixfs/node/file/file.go index bda6f9ef8..17a004a5a 100644 --- a/unixfs/node/file/file.go +++ b/unixfs/node/file/file.go @@ -11,10 +11,10 @@ import ( // root of a unixfs File. // It provides a `bytes` view over the file, along with access to io.Reader streaming access // to file data. -func NewUnixFSFile(ctx context.Context, substrate ipld.Node, lsys *ipld.LinkSystem) (StreamableByteNode, error) { +func NewUnixFSFile(ctx context.Context, substrate ipld.Node, lsys *ipld.LinkSystem) (LargeBytesNode, error) { if substrate.Kind() == ipld.Kind_Bytes { // A raw / single-node file. - return &singleNodeFile{substrate, 0}, nil + return &singleNodeFile{substrate}, nil } // see if it's got children. links, err := substrate.LookupByString("Links") @@ -30,22 +30,29 @@ func NewUnixFSFile(ctx context.Context, substrate ipld.Node, lsys *ipld.LinkSyst ctx: ctx, lsys: lsys, substrate: substrate, - done: false, - rdr: nil}, nil + }, nil } -// A StreamableByteNode is an ipld.Node that can be streamed over. It is guaranteed to have a Bytes type. -type StreamableByteNode interface { +// A LargeBytesNode is an ipld.Node that can be streamed over. It is guaranteed to have a Bytes type. +type LargeBytesNode interface { ipld.Node - io.Reader + AsLargeBytes() (io.ReadSeeker, error) } type singleNodeFile struct { ipld.Node +} + +func (f *singleNodeFile) AsLargeBytes() (io.ReadSeeker, error) { + return &singleNodeReader{f, 0}, nil +} + +type singleNodeReader struct { + ipld.Node offset int } -func (f *singleNodeFile) Read(p []byte) (int, error) { +func (f *singleNodeReader) Read(p []byte) (int, error) { buf, err := f.Node.AsBytes() if err != nil { return 0, err @@ -57,3 +64,23 @@ func (f *singleNodeFile) Read(p []byte) (int, error) { f.offset += n return n, nil } + +func (f *singleNodeReader) Seek(offset int64, whence int) (int64, error) { + buf, err := f.Node.AsBytes() + if err != nil { + return 0, err + } + + switch whence { + case io.SeekStart: + f.offset = int(offset) + case io.SeekCurrent: + f.offset += int(offset) + case io.SeekEnd: + f.offset = len(buf) + int(offset) + } + if f.offset < 0 { + return 0, io.EOF + } + return int64(f.offset), nil +} diff --git a/unixfs/node/file/shard.go b/unixfs/node/file/shard.go index 303054f5f..e3dc79b14 100644 --- a/unixfs/node/file/shard.go +++ b/unixfs/node/file/shard.go @@ -4,6 +4,7 @@ import ( "context" "io" + "github.com/ipfs/go-unixfsnode/data" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" @@ -15,56 +16,147 @@ type shardNodeFile struct { ctx context.Context lsys *ipld.LinkSystem substrate ipld.Node - done bool - rdr io.Reader } var _ ipld.Node = (*shardNodeFile)(nil) -func (s *shardNodeFile) Read(p []byte) (int, error) { - if s.done { - return 0, io.EOF +type shardNodeReader struct { + *shardNodeFile + rdr io.Reader + offset int64 +} + +func (s *shardNodeReader) makeReader() (io.Reader, error) { + links, err := s.shardNodeFile.substrate.LookupByString("Links") + if err != nil { + return nil, err } - // collect the sub-nodes on first use - if s.rdr == nil { - links, err := s.substrate.LookupByString("Links") + readers := make([]io.Reader, 0) + lnki := links.ListIterator() + at := int64(0) + for !lnki.Done() { + _, lnk, err := lnki.Next() if err != nil { - return 0, err + return nil, err } - readers := make([]io.Reader, 0) - lnki := links.ListIterator() - for !lnki.Done() { - _, lnk, err := lnki.Next() - if err != nil { - return 0, err - } - lnkhash, err := lnk.LookupByString("Hash") - if err != nil { - return 0, err - } - lnklnk, err := lnkhash.AsLink() - if err != nil { - return 0, err - } - target, err := s.lsys.Load(ipld.LinkContext{Ctx: s.ctx}, lnklnk, protoFor(lnklnk)) + sz, err := lnk.LookupByString("Tsize") + if err != nil { + return nil, err + } + childSize, err := sz.AsInt() + if err != nil { + return nil, err + } + if s.offset > at+childSize { + at += childSize + continue + } + lnkhash, err := lnk.LookupByString("Hash") + if err != nil { + return nil, err + } + lnklnk, err := lnkhash.AsLink() + if err != nil { + return nil, err + } + target := newDeferredFileNode(s.ctx, s.lsys, lnklnk) + tr, err := target.AsLargeBytes() + if err != nil { + return nil, err + } + // fastforward the first one if needed. + if at < s.offset { + _, err := tr.Seek(s.offset-at, io.SeekStart) if err != nil { - return 0, err + return nil, err } + } + at += childSize + readers = append(readers, tr) + } + if len(readers) == 0 { + return nil, io.EOF + } + return io.MultiReader(readers...), nil +} - asFSNode, err := NewUnixFSFile(s.ctx, target, s.lsys) - if err != nil { - return 0, err - } - readers = append(readers, asFSNode) +func (s *shardNodeReader) Read(p []byte) (int, error) { + // build reader + if s.rdr == nil { + rdr, err := s.makeReader() + if err != nil { + return 0, err } - s.rdr = io.MultiReader(readers...) + s.rdr = rdr } n, err := s.rdr.Read(p) - if err == io.EOF { + return n, err +} + +func (s *shardNodeReader) Seek(offset int64, whence int) (int64, error) { + if s.rdr != nil { s.rdr = nil - s.done = true } - return n, err + switch whence { + case io.SeekStart: + s.offset = offset + case io.SeekCurrent: + s.offset += offset + case io.SeekEnd: + s.offset = s.length() + offset + } + return s.offset, nil +} + +func (s *shardNodeFile) length() int64 { + // see if we have size specified in the unixfs data. errors fall back to length from links + nodeData, err := s.substrate.LookupByString("Data") + if err != nil { + return s.lengthFromLinks() + } + nodeDataBytes, err := nodeData.AsBytes() + if err != nil { + return s.lengthFromLinks() + } + ud, err := data.DecodeUnixFSData(nodeDataBytes) + if err != nil { + return s.lengthFromLinks() + } + if ud.FileSize.Exists() { + if fs, err := ud.FileSize.Must().AsInt(); err == nil { + return int64(fs) + } + } + return s.lengthFromLinks() +} + +func (s *shardNodeFile) lengthFromLinks() int64 { + links, err := s.substrate.LookupByString("Links") + if err != nil { + return 0 + } + size := int64(0) + li := links.ListIterator() + for !li.Done() { + _, l, err := li.Next() + if err != nil { + return 0 + } + sn, err := l.LookupByString("Tsize") + if err != nil { + return 0 + } + ll, err := sn.AsInt() + if err != nil { + return 0 + } + size += ll + } + return size +} + +func (s *shardNodeFile) AsLargeBytes() (io.ReadSeeker, error) { + return &shardNodeReader{s, nil, 0}, nil } func protoFor(link ipld.Link) ipld.NodePrototype { @@ -81,7 +173,11 @@ func (s *shardNodeFile) Kind() ipld.Kind { } func (s *shardNodeFile) AsBytes() ([]byte, error) { - return io.ReadAll(s) + rdr, err := s.AsLargeBytes() + if err != nil { + return nil, err + } + return io.ReadAll(rdr) } func (s *shardNodeFile) AsBool() (bool, error) { diff --git a/unixfs/node/file/wrapped.go b/unixfs/node/file/wrapped.go index 56b2c6ccc..b2c2210c9 100644 --- a/unixfs/node/file/wrapped.go +++ b/unixfs/node/file/wrapped.go @@ -6,7 +6,7 @@ import ( "github.com/ipld/go-ipld-prime/node/basicnode" ) -func newWrappedNode(substrate ipld.Node) (StreamableByteNode, error) { +func newWrappedNode(substrate ipld.Node) (LargeBytesNode, error) { dataField, err := substrate.LookupByString("Data") if err != nil { return nil, err From ab5e7d186a441c44aef06caf3cebe6941a713707 Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Mon, 7 Mar 2022 16:29:24 +0000 Subject: [PATCH 25/43] fix(unixfsnode): add unixfs to path tail fix the selector for paths, wrapping the last matcher node in an ExploreInterpretAs, since the tail end of a path into a unixfs dir is itself a unixfsnode This commit was moved from ipfs/go-unixfsnode@9214f706a1fbaa9129cae3bd33f9806f615e44df --- unixfs/node/signaling.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unixfs/node/signaling.go b/unixfs/node/signaling.go index a2dee3d9c..56eb52df0 100644 --- a/unixfs/node/signaling.go +++ b/unixfs/node/signaling.go @@ -22,7 +22,7 @@ func AddUnixFSReificationToLinkSystem(lsys *ipld.LinkSystem) { func UnixFSPathSelector(path string) datamodel.Node { segments := strings.Split(path, "/") ssb := builder.NewSelectorSpecBuilder(basicnode.Prototype.Any) - selectorSoFar := ssb.Matcher() + selectorSoFar := ssb.ExploreInterpretAs("unixfs", ssb.Matcher()) for i := len(segments) - 1; i >= 0; i-- { selectorSoFar = ssb.ExploreInterpretAs("unixfs", ssb.ExploreFields(func(efsb builder.ExploreFieldsSpecBuilder) { From 7407986f44c621bc4f84ad6b0ddcf8352360a1a4 Mon Sep 17 00:00:00 2001 From: Will Scott Date: Thu, 3 Mar 2022 19:08:09 +0100 Subject: [PATCH 26/43] Roundtrip test for partial file reads and traversals This commit was moved from ipfs/go-unixfsnode@870fc826bec3d70feb4564df645dca8c5028375f --- unixfs/node/test/partial_file_access_test.go | 108 +++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 unixfs/node/test/partial_file_access_test.go diff --git a/unixfs/node/test/partial_file_access_test.go b/unixfs/node/test/partial_file_access_test.go new file mode 100644 index 000000000..fffe74f58 --- /dev/null +++ b/unixfs/node/test/partial_file_access_test.go @@ -0,0 +1,108 @@ +package test + +import ( + "bytes" + "context" + "io" + "testing" + + u "github.com/ipfs/go-ipfs-util" + "github.com/ipfs/go-unixfsnode/data/builder" + "github.com/ipfs/go-unixfsnode/file" + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/datamodel" + "github.com/ipld/go-ipld-prime/linking" + cidlink "github.com/ipld/go-ipld-prime/linking/cid" + basicnode "github.com/ipld/go-ipld-prime/node/basic" + "github.com/ipld/go-ipld-prime/traversal" + sb "github.com/ipld/go-ipld-prime/traversal/selector/builder" +) + +func TestPartialFileAccess(t *testing.T) { + buf := make([]byte, 10*1024*1024) + u.NewSeededRand(0xdeadbeef).Read(buf) + r := bytes.NewReader(buf) + + ls := cidlink.DefaultLinkSystem() + storage := cidlink.Memory{} + ls.StorageReadOpener = storage.OpenRead + ls.StorageWriteOpener = storage.OpenWrite + + f, _, err := builder.BuildUnixFSFile(r, "", &ls) + if err != nil { + t.Fatal(err) + } + + // get back the root node substrate from the link at the top of the builder. + fr, err := ls.Load(ipld.LinkContext{}, f, dagpb.Type.PBNode) + if err != nil { + t.Fatal(err) + } + + ufn, err := file.NewUnixFSFile(context.Background(), fr, &ls) + if err != nil { + t.Fatal(err) + } + + openedLinks := []ipld.Link{} + ls.StorageReadOpener = func(lc linking.LinkContext, l datamodel.Link) (io.Reader, error) { + openedLinks = append(openedLinks, l) + return storage.OpenRead(lc, l) + } + + // read back out the file. + out, err := ufn.AsBytes() + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(out, buf) { + t.Fatal("Not equal") + } + + fullLen := len(openedLinks) + + openedLinks = []ipld.Link{} + + partial, err := ufn.(datamodel.LargeBytesNode).AsLargeBytes() + if err != nil { + t.Fatal(err) + } + half := make([]byte, len(buf)/2) + if _, err := partial.Read(half); err != nil { + t.Fatal(err) + } + if len(openedLinks) >= fullLen { + t.Fatal("should not have accessed full file on a partial read.") + } + + openedLinks = []ipld.Link{} + + prog := traversal.Progress{ + Cfg: &traversal.Config{ + LinkSystem: ls, + }, + } + sb := sb.NewSelectorSpecBuilder(basicnode.Prototype.Any) + ss := sb.MatcherSubset(5*1024*1024, 6*1024*1024) + sel, err := ss.Selector() + if err != nil { + t.Fatal(err) + } + + if err := prog.WalkMatching(ufn, sel, func(_ traversal.Progress, n datamodel.Node) error { + b, err := n.AsBytes() + if err != nil { + t.Fatal(err) + } + if len(b) != 1024*1024 { + t.Fatalf("wrong length: %d", len(b)) + } + return nil + }); err != nil { + t.Fatal(err) + } + if len(openedLinks) >= fullLen { + t.Fatal("should not have accessed full file on a partial traversal.") + } +} From c08b9d2a5e3b225342b97f3ad6d124be9e34d053 Mon Sep 17 00:00:00 2001 From: Will Scott Date: Thu, 3 Mar 2022 19:13:12 +0100 Subject: [PATCH 27/43] add doc to make linter happier This commit was moved from ipfs/go-unixfsnode@e00f90a2aaf9cba3b57e8da8978ddf91d16434b2 --- unixfs/node/test/doc.go | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 unixfs/node/test/doc.go diff --git a/unixfs/node/test/doc.go b/unixfs/node/test/doc.go new file mode 100644 index 000000000..cecd77b64 --- /dev/null +++ b/unixfs/node/test/doc.go @@ -0,0 +1,4 @@ +// Package test provides ADL testing of the ipld specification around +// * traversal making use of match subsets +// * largeByteNode readers +package test From 7ec18e139cf2b3b8c740032952471afeb28909c5 Mon Sep 17 00:00:00 2001 From: Will Scott Date: Mon, 2 May 2022 11:37:00 +0200 Subject: [PATCH 28/43] add quickbuilder helper to approximate test creation commonly used with ipfs-files This commit was moved from ipfs/go-unixfsnode@f664db4b21687c8eabebed3daf43cd15dd7e9d02 --- unixfs/node/data/builder/quick/quick.go | 77 ++++++++++++++++++++ unixfs/node/data/builder/quick/quick_test.go | 35 +++++++++ 2 files changed, 112 insertions(+) create mode 100644 unixfs/node/data/builder/quick/quick.go create mode 100644 unixfs/node/data/builder/quick/quick_test.go diff --git a/unixfs/node/data/builder/quick/quick.go b/unixfs/node/data/builder/quick/quick.go new file mode 100644 index 000000000..eee1d32e5 --- /dev/null +++ b/unixfs/node/data/builder/quick/quick.go @@ -0,0 +1,77 @@ +// Package quickbuilder is designed as a replacement for the existing ipfs-files +// constructor for a simple way to generate synthetic directory trees. +package quickbuilder + +import ( + "bytes" + + "github.com/ipfs/go-unixfsnode/data/builder" + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" +) + +// A Node represents the most basic form of a file or directory +type Node interface { + Size() (int64, error) + Link() ipld.Link +} + +type lnkNode struct { + link ipld.Link + size int64 + ls *ipld.LinkSystem +} + +func (ln *lnkNode) Size() (int64, error) { + return ln.size, nil +} + +func (ln *lnkNode) Link() ipld.Link { + return ln.link +} + +// Builder provides the linksystem context for saving files & directories +type Builder struct { + ls *ipld.LinkSystem +} + +// NewMapDirectory creates a unixfs directory from a list of named entries +func (b *Builder) NewMapDirectory(entries map[string]Node) Node { + lnks := make([]dagpb.PBLink, 0, len(entries)) + for name, e := range entries { + sz, _ := e.Size() + entry, err := builder.BuildUnixFSDirectoryEntry(name, sz, e.Link()) + if err != nil { + return nil + } + lnks = append(lnks, entry) + } + n, size, err := builder.BuildUnixFSDirectory(lnks, b.ls) + if err != nil { + panic(err) + } + return &lnkNode{ + n, + int64(size), + b.ls, + } +} + +// NewBytesFile creates a unixfs file from byte contents +func (b *Builder) NewBytesFile(data []byte) Node { + n, size, err := builder.BuildUnixFSFile(bytes.NewReader(data), "", b.ls) + if err != nil { + panic(err) + } + return &lnkNode{ + n, + int64(size), + b.ls, + } +} + +// Store provides a builder context for making unixfs files and directories +func Store(ls *ipld.LinkSystem, cb func(b *Builder) error) error { + b := Builder{ls} + return cb(&b) +} diff --git a/unixfs/node/data/builder/quick/quick_test.go b/unixfs/node/data/builder/quick/quick_test.go new file mode 100644 index 000000000..e644b0fe1 --- /dev/null +++ b/unixfs/node/data/builder/quick/quick_test.go @@ -0,0 +1,35 @@ +package quickbuilder_test + +import ( + "testing" + + quickbuilder "github.com/ipfs/go-unixfsnode/data/builder/quick" + cidlink "github.com/ipld/go-ipld-prime/linking/cid" + "github.com/ipld/go-ipld-prime/storage/memstore" +) + +func TestQuickBuilder(t *testing.T) { + ls := cidlink.DefaultLinkSystem() + store := memstore.Store{Bag: make(map[string][]byte)} + ls.SetReadStorage(&store) + ls.SetWriteStorage(&store) + err := quickbuilder.Store(&ls, func(b *quickbuilder.Builder) error { + b.NewMapDirectory(map[string]quickbuilder.Node{ + "file.txt": b.NewBytesFile([]byte("1")), + "foo? #<'": b.NewMapDirectory(map[string]quickbuilder.Node{ + "file.txt": b.NewBytesFile([]byte("2")), + "bar": b.NewMapDirectory(map[string]quickbuilder.Node{ + "file.txt": b.NewBytesFile([]byte("3")), + }), + }), + }) + return nil + }) + if err != nil { + t.Fatal(err) + } + + if len(store.Bag) != 6 { + t.Fatal("unexpected number of stored nodes") + } +} From 8e150bf95647a89de2d920537ed255588d7be21f Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Mon, 2 May 2022 15:41:01 +1000 Subject: [PATCH 29/43] chore: remove Stebalien/go-bitfield in favour of ipfs/go-bitfield This commit was moved from ipfs/go-unixfsnode@31cb5601868f794b3947b8db3a71fbccc759cd50 --- unixfs/node/hamt/shardeddir.go | 2 +- unixfs/node/hamt/util.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/unixfs/node/hamt/shardeddir.go b/unixfs/node/hamt/shardeddir.go index aa219b3c8..ebc59c548 100644 --- a/unixfs/node/hamt/shardeddir.go +++ b/unixfs/node/hamt/shardeddir.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/Stebalien/go-bitfield" + bitfield "github.com/ipfs/go-bitfield" "github.com/ipfs/go-unixfsnode/data" "github.com/ipfs/go-unixfsnode/iter" dagpb "github.com/ipld/go-codec-dagpb" diff --git a/unixfs/node/hamt/util.go b/unixfs/node/hamt/util.go index 54291e457..bd72382c3 100644 --- a/unixfs/node/hamt/util.go +++ b/unixfs/node/hamt/util.go @@ -7,7 +7,7 @@ import ( "math/bits" - "github.com/Stebalien/go-bitfield" + bitfield "github.com/ipfs/go-bitfield" "github.com/ipfs/go-unixfsnode/data" dagpb "github.com/ipld/go-codec-dagpb" "github.com/spaolacci/murmur3" From fb809f93f2dd0c971263afa2a13b54691d807707 Mon Sep 17 00:00:00 2001 From: Will Scott Date: Sun, 14 Aug 2022 16:56:15 +0200 Subject: [PATCH 30/43] test for reader / sizing behavior on large files This commit was moved from ipfs/go-unixfsnode@532b121660863c5753b6ef99d9a7fcd69f894419 --- unixfs/node/data/builder/file.go | 4 +- unixfs/node/file/file_test.go | 47 ++++++++++ unixfs/node/file/shard.go | 143 +++++++++++++++++++++++-------- 3 files changed, 157 insertions(+), 37 deletions(-) diff --git a/unixfs/node/data/builder/file.go b/unixfs/node/data/builder/file.go index 8e2e6f158..8309e42a4 100644 --- a/unixfs/node/data/builder/file.go +++ b/unixfs/node/data/builder/file.go @@ -165,11 +165,11 @@ func fileTreeRecursive(depth int, children []ipld.Link, childLen []uint64, src c } pbn := dpbb.Build() - link, sz, err := sizedStore(ls, fileLinkProto, pbn) + link, _, err := sizedStore(ls, fileLinkProto, pbn) if err != nil { return nil, 0, err } - return link, totalSize + sz, nil + return link, totalSize, nil } // BuildUnixFSDirectoryEntry creates the link to a file or directory as it appears within a unixfs directory. diff --git a/unixfs/node/file/file_test.go b/unixfs/node/file/file_test.go index ee01a71d7..3277e241f 100644 --- a/unixfs/node/file/file_test.go +++ b/unixfs/node/file/file_test.go @@ -7,7 +7,9 @@ import ( "io" "testing" + ipfsutil "github.com/ipfs/go-ipfs-util" "github.com/ipfs/go-unixfsnode" + "github.com/ipfs/go-unixfsnode/data/builder" "github.com/ipfs/go-unixfsnode/directory" "github.com/ipfs/go-unixfsnode/file" "github.com/ipld/go-car/v2/blockstore" @@ -61,6 +63,51 @@ func TestNamedV0File(t *testing.T) { } } +func TestLargeFileReader(t *testing.T) { + buf := make([]byte, 1024*1024*1024) + ipfsutil.NewSeededRand(0xdeadbeef).Read(buf) + r := bytes.NewReader(buf) + + ls := cidlink.DefaultLinkSystem() + storage := cidlink.Memory{} + ls.StorageReadOpener = storage.OpenRead + ls.StorageWriteOpener = storage.OpenWrite + + f, _, err := builder.BuildUnixFSFile(r, "", &ls) + if err != nil { + t.Fatal(err) + } + + // get back the root node substrate from the link at the top of the builder. + fr, err := ls.Load(ipld.LinkContext{}, f, dagpb.Type.PBNode) + if err != nil { + t.Fatal(err) + } + + ufn, err := file.NewUnixFSFile(context.Background(), fr, &ls) + if err != nil { + t.Fatal(err) + } + // read back out the file. + for i := 0; i < len(buf); i += 100 * 1024 * 1024 { + rs, err := ufn.AsLargeBytes() + if err != nil { + t.Fatal(err) + } + _, err = rs.Seek(int64(i), io.SeekStart) + if err != nil { + t.Fatal(err) + } + ob, err := io.ReadAll(rs) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(ob, buf[i:]) { + t.Fatal("Not equal at offset", i, "expected", len(buf[i:]), "got", len(ob)) + } + } +} + func open(car string, t *testing.T) (ipld.Node, *ipld.LinkSystem) { baseStore, err := blockstore.OpenReadOnly(car) if err != nil { diff --git a/unixfs/node/file/shard.go b/unixfs/node/file/shard.go index e3dc79b14..8d2c0bd71 100644 --- a/unixfs/node/file/shard.go +++ b/unixfs/node/file/shard.go @@ -2,8 +2,11 @@ package file import ( "context" + "fmt" "io" + "sync" + "github.com/ipfs/go-cid" "github.com/ipfs/go-unixfsnode/data" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" @@ -16,6 +19,10 @@ type shardNodeFile struct { ctx context.Context lsys *ipld.LinkSystem substrate ipld.Node + + // unixfs data unpacked from the substrate. access via .unpack() + metadata data.UnixFSData + unpackLk sync.Once } var _ ipld.Node = (*shardNodeFile)(nil) @@ -24,6 +31,7 @@ type shardNodeReader struct { *shardNodeFile rdr io.Reader offset int64 + len int64 } func (s *shardNodeReader) makeReader() (io.Reader, error) { @@ -34,16 +42,13 @@ func (s *shardNodeReader) makeReader() (io.Reader, error) { readers := make([]io.Reader, 0) lnki := links.ListIterator() at := int64(0) + lin := 0 for !lnki.Done() { _, lnk, err := lnki.Next() if err != nil { return nil, err } - sz, err := lnk.LookupByString("Tsize") - if err != nil { - return nil, err - } - childSize, err := sz.AsInt() + childSize, tr, err := s.linkSize(lnk, lin) if err != nil { return nil, err } @@ -51,18 +56,20 @@ func (s *shardNodeReader) makeReader() (io.Reader, error) { at += childSize continue } - lnkhash, err := lnk.LookupByString("Hash") - if err != nil { - return nil, err - } - lnklnk, err := lnkhash.AsLink() - if err != nil { - return nil, err - } - target := newDeferredFileNode(s.ctx, s.lsys, lnklnk) - tr, err := target.AsLargeBytes() - if err != nil { - return nil, err + if tr == nil { + lnkhash, err := lnk.LookupByString("Hash") + if err != nil { + return nil, err + } + lnklnk, err := lnkhash.AsLink() + if err != nil { + return nil, err + } + target := newDeferredFileNode(s.ctx, s.lsys, lnklnk) + tr, err = target.AsLargeBytes() + if err != nil { + return nil, err + } } // fastforward the first one if needed. if at < s.offset { @@ -77,9 +84,86 @@ func (s *shardNodeReader) makeReader() (io.Reader, error) { if len(readers) == 0 { return nil, io.EOF } + s.len = at return io.MultiReader(readers...), nil } +func (s *shardNodeFile) unpack() (data.UnixFSData, error) { + var retErr error + s.unpackLk.Do(func() { + nodeData, err := s.substrate.LookupByString("Data") + if err != nil { + retErr = err + return + } + nodeDataBytes, err := nodeData.AsBytes() + if err != nil { + retErr = err + return + } + ud, err := data.DecodeUnixFSData(nodeDataBytes) + if err != nil { + retErr = err + return + } + s.metadata = ud + }) + return s.metadata, retErr +} + +// returns the size of the n'th link from this shard. +// the io.ReadSeeker of the child will be return if it was loaded as part of the size calculation. +func (s *shardNodeFile) linkSize(lnk ipld.Node, position int) (int64, io.ReadSeeker, error) { + lnkhash, err := lnk.LookupByString("Hash") + if err != nil { + return 0, nil, err + } + lnklnk, err := lnkhash.AsLink() + if err != nil { + return 0, nil, err + } + _, c, err := cid.CidFromBytes([]byte(lnklnk.Binary())) + if err != nil { + return 0, nil, err + } + + // efficiency shortcut: for raw blocks, the size will match the bytes of content + if c.Prefix().Codec == cid.Raw { + size, err := lnk.LookupByString("Tsize") + if err != nil { + return 0, nil, err + } + sz, err := size.AsInt() + return sz, nil, err + } + + // check if there are blocksizes written, use them if there are. + md, err := s.unpack() + if err == nil && md != nil { + pn, err := md.BlockSizes.LookupByIndex(int64(position)) + if err == nil { + innerNum, err := pn.AsInt() + if err == nil { + return innerNum, nil, nil + } + } + } + + // open the link and get its size. + target := newDeferredFileNode(s.ctx, s.lsys, lnklnk) + tr, err := target.AsLargeBytes() + if err != nil { + return 0, nil, err + } + fmt.Printf("had to get len by opening child.\n") + end, err := tr.Seek(0, io.SeekEnd) + if err != nil { + return end, nil, err + } + _, err = tr.Seek(0, io.SeekStart) + return end, tr, err +} + func (s *shardNodeReader) Read(p []byte) (int, error) { // build reader if s.rdr == nil { @@ -110,23 +194,16 @@ func (s *shardNodeReader) Seek(offset int64, whence int) (int64, error) { func (s *shardNodeFile) length() int64 { // see if we have size specified in the unixfs data. errors fall back to length from links - nodeData, err := s.substrate.LookupByString("Data") - if err != nil { - return s.lengthFromLinks() - } - nodeDataBytes, err := nodeData.AsBytes() + nodeData, err := s.unpack() if err != nil { return s.lengthFromLinks() } - ud, err := data.DecodeUnixFSData(nodeDataBytes) - if err != nil { - return s.lengthFromLinks() - } - if ud.FileSize.Exists() { - if fs, err := ud.FileSize.Must().AsInt(); err == nil { + if nodeData.FileSize.Exists() { + if fs, err := nodeData.FileSize.Must().AsInt(); err == nil { return int64(fs) } } + return s.lengthFromLinks() } @@ -138,15 +215,11 @@ func (s *shardNodeFile) lengthFromLinks() int64 { size := int64(0) li := links.ListIterator() for !li.Done() { - _, l, err := li.Next() - if err != nil { - return 0 - } - sn, err := l.LookupByString("Tsize") + idx, l, err := li.Next() if err != nil { return 0 } - ll, err := sn.AsInt() + ll, _, err := s.linkSize(l, int(idx)) if err != nil { return 0 } @@ -156,7 +229,7 @@ func (s *shardNodeFile) lengthFromLinks() int64 { } func (s *shardNodeFile) AsLargeBytes() (io.ReadSeeker, error) { - return &shardNodeReader{s, nil, 0}, nil + return &shardNodeReader{s, nil, 0, 0}, nil } func protoFor(link ipld.Link) ipld.NodePrototype { From 921351afa7f138abb11e2878cb8d8c53ebc62d2d Mon Sep 17 00:00:00 2001 From: Will Scott Date: Sat, 20 Aug 2022 14:00:17 +0200 Subject: [PATCH 31/43] review comments This commit was moved from ipfs/go-unixfsnode@f20625567dc52dcdaf39f168774008fc3e29b9aa --- unixfs/node/file/file_test.go | 5 ++++- unixfs/node/file/shard.go | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/unixfs/node/file/file_test.go b/unixfs/node/file/file_test.go index 3277e241f..60d996c09 100644 --- a/unixfs/node/file/file_test.go +++ b/unixfs/node/file/file_test.go @@ -64,7 +64,10 @@ func TestNamedV0File(t *testing.T) { } func TestLargeFileReader(t *testing.T) { - buf := make([]byte, 1024*1024*1024) + if testing.Short() { + t.Skip() + } + buf := make([]byte, 512*1024*1024) ipfsutil.NewSeededRand(0xdeadbeef).Read(buf) r := bytes.NewReader(buf) diff --git a/unixfs/node/file/shard.go b/unixfs/node/file/shard.go index 8d2c0bd71..959e7155e 100644 --- a/unixfs/node/file/shard.go +++ b/unixfs/node/file/shard.go @@ -2,7 +2,6 @@ package file import ( "context" - "fmt" "io" "sync" @@ -138,6 +137,8 @@ func (s *shardNodeFile) linkSize(lnk ipld.Node, position int) (int64, io.ReadSee } // check if there are blocksizes written, use them if there are. + // both err and md can be nil if this was not the first time unpack() + // was called but there was an error on the first call. md, err := s.unpack() if err == nil && md != nil { pn, err := md.BlockSizes.LookupByIndex(int64(position)) @@ -155,7 +156,7 @@ func (s *shardNodeFile) linkSize(lnk ipld.Node, position int) (int64, io.ReadSee if err != nil { return 0, nil, err } - fmt.Printf("had to get len by opening child.\n") + end, err := tr.Seek(0, io.SeekEnd) if err != nil { return end, nil, err @@ -195,7 +196,7 @@ func (s *shardNodeReader) Seek(offset int64, whence int) (int64, error) { func (s *shardNodeFile) length() int64 { // see if we have size specified in the unixfs data. errors fall back to length from links nodeData, err := s.unpack() - if err != nil { + if err != nil || nodeData == nil { return s.lengthFromLinks() } if nodeData.FileSize.Exists() { From b5a3ecd52a0053ab161b5fea7eb3e414e07bc40f Mon Sep 17 00:00:00 2001 From: Will Scott Date: Sat, 20 Aug 2022 14:10:36 +0200 Subject: [PATCH 32/43] fix nit. clearer name This commit was moved from ipfs/go-unixfsnode@5f5040a07c463f56e5dfbcf8d234374f79d0c507 --- unixfs/node/file/file_test.go | 3 ++- unixfs/node/file/shard.go | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/unixfs/node/file/file_test.go b/unixfs/node/file/file_test.go index 60d996c09..390205c73 100644 --- a/unixfs/node/file/file_test.go +++ b/unixfs/node/file/file_test.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "io" + "strconv" "testing" ipfsutil "github.com/ipfs/go-ipfs-util" @@ -64,7 +65,7 @@ func TestNamedV0File(t *testing.T) { } func TestLargeFileReader(t *testing.T) { - if testing.Short() { + if testing.Short() || strconv.IntSize == 32 { t.Skip() } buf := make([]byte, 512*1024*1024) diff --git a/unixfs/node/file/shard.go b/unixfs/node/file/shard.go index 959e7155e..0f08d140d 100644 --- a/unixfs/node/file/shard.go +++ b/unixfs/node/file/shard.go @@ -39,15 +39,14 @@ func (s *shardNodeReader) makeReader() (io.Reader, error) { return nil, err } readers := make([]io.Reader, 0) - lnki := links.ListIterator() + lnkIter := links.ListIterator() at := int64(0) - lin := 0 - for !lnki.Done() { - _, lnk, err := lnki.Next() + for !lnkIter.Done() { + lnkIdx, lnk, err := lnkIter.Next() if err != nil { return nil, err } - childSize, tr, err := s.linkSize(lnk, lin) + childSize, tr, err := s.linkSize(lnk, int(lnkIdx)) if err != nil { return nil, err } From 5031cf077f788a51eabc07f68d500bcf40e06850 Mon Sep 17 00:00:00 2001 From: Will Scott Date: Sat, 20 Aug 2022 14:40:02 +0200 Subject: [PATCH 33/43] split large file test to not run with race detector, sine that's too big for CI This commit was moved from ipfs/go-unixfsnode@05a4b1622c38f2e64eb40211e4ca19c0d524fa89 --- unixfs/node/file/file_test.go | 51 ---------------------- unixfs/node/file/large_file_test.go | 67 +++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 51 deletions(-) create mode 100644 unixfs/node/file/large_file_test.go diff --git a/unixfs/node/file/file_test.go b/unixfs/node/file/file_test.go index 390205c73..ee01a71d7 100644 --- a/unixfs/node/file/file_test.go +++ b/unixfs/node/file/file_test.go @@ -5,12 +5,9 @@ import ( "context" "fmt" "io" - "strconv" "testing" - ipfsutil "github.com/ipfs/go-ipfs-util" "github.com/ipfs/go-unixfsnode" - "github.com/ipfs/go-unixfsnode/data/builder" "github.com/ipfs/go-unixfsnode/directory" "github.com/ipfs/go-unixfsnode/file" "github.com/ipld/go-car/v2/blockstore" @@ -64,54 +61,6 @@ func TestNamedV0File(t *testing.T) { } } -func TestLargeFileReader(t *testing.T) { - if testing.Short() || strconv.IntSize == 32 { - t.Skip() - } - buf := make([]byte, 512*1024*1024) - ipfsutil.NewSeededRand(0xdeadbeef).Read(buf) - r := bytes.NewReader(buf) - - ls := cidlink.DefaultLinkSystem() - storage := cidlink.Memory{} - ls.StorageReadOpener = storage.OpenRead - ls.StorageWriteOpener = storage.OpenWrite - - f, _, err := builder.BuildUnixFSFile(r, "", &ls) - if err != nil { - t.Fatal(err) - } - - // get back the root node substrate from the link at the top of the builder. - fr, err := ls.Load(ipld.LinkContext{}, f, dagpb.Type.PBNode) - if err != nil { - t.Fatal(err) - } - - ufn, err := file.NewUnixFSFile(context.Background(), fr, &ls) - if err != nil { - t.Fatal(err) - } - // read back out the file. - for i := 0; i < len(buf); i += 100 * 1024 * 1024 { - rs, err := ufn.AsLargeBytes() - if err != nil { - t.Fatal(err) - } - _, err = rs.Seek(int64(i), io.SeekStart) - if err != nil { - t.Fatal(err) - } - ob, err := io.ReadAll(rs) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(ob, buf[i:]) { - t.Fatal("Not equal at offset", i, "expected", len(buf[i:]), "got", len(ob)) - } - } -} - func open(car string, t *testing.T) (ipld.Node, *ipld.LinkSystem) { baseStore, err := blockstore.OpenReadOnly(car) if err != nil { diff --git a/unixfs/node/file/large_file_test.go b/unixfs/node/file/large_file_test.go new file mode 100644 index 000000000..6dc64d2c9 --- /dev/null +++ b/unixfs/node/file/large_file_test.go @@ -0,0 +1,67 @@ +//go:build !race +// +build !race + +package file_test + +import ( + "bytes" + "context" + "io" + "strconv" + "testing" + + ipfsutil "github.com/ipfs/go-ipfs-util" + "github.com/ipfs/go-unixfsnode/data/builder" + "github.com/ipfs/go-unixfsnode/file" + dagpb "github.com/ipld/go-codec-dagpb" + "github.com/ipld/go-ipld-prime" + cidlink "github.com/ipld/go-ipld-prime/linking/cid" +) + +func TestLargeFileReader(t *testing.T) { + if testing.Short() || strconv.IntSize == 32 { + t.Skip() + } + buf := make([]byte, 512*1024*1024) + ipfsutil.NewSeededRand(0xdeadbeef).Read(buf) + r := bytes.NewReader(buf) + + ls := cidlink.DefaultLinkSystem() + storage := cidlink.Memory{} + ls.StorageReadOpener = storage.OpenRead + ls.StorageWriteOpener = storage.OpenWrite + + f, _, err := builder.BuildUnixFSFile(r, "", &ls) + if err != nil { + t.Fatal(err) + } + + // get back the root node substrate from the link at the top of the builder. + fr, err := ls.Load(ipld.LinkContext{}, f, dagpb.Type.PBNode) + if err != nil { + t.Fatal(err) + } + + ufn, err := file.NewUnixFSFile(context.Background(), fr, &ls) + if err != nil { + t.Fatal(err) + } + // read back out the file. + for i := 0; i < len(buf); i += 100 * 1024 * 1024 { + rs, err := ufn.AsLargeBytes() + if err != nil { + t.Fatal(err) + } + _, err = rs.Seek(int64(i), io.SeekStart) + if err != nil { + t.Fatal(err) + } + ob, err := io.ReadAll(rs) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(ob, buf[i:]) { + t.Fatal("Not equal at offset", i, "expected", len(buf[i:]), "got", len(ob)) + } + } +} From bf32171475be6e4ed8bc9461afcaaeaccfcf07c5 Mon Sep 17 00:00:00 2001 From: web3-bot Date: Wed, 24 Aug 2022 11:46:56 +0000 Subject: [PATCH 34/43] bump go.mod to Go 1.18 and run go fix This commit was moved from ipfs/go-unixfsnode@d076d377dcf6f7925e40c8e43d5b87efb633cc59 --- unixfs/node/file/large_file_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/unixfs/node/file/large_file_test.go b/unixfs/node/file/large_file_test.go index 6dc64d2c9..9403c8b28 100644 --- a/unixfs/node/file/large_file_test.go +++ b/unixfs/node/file/large_file_test.go @@ -1,5 +1,4 @@ //go:build !race -// +build !race package file_test From 00599509f2e8daaadedc776621ba6b3f84cef7b3 Mon Sep 17 00:00:00 2001 From: web3-bot Date: Wed, 24 Aug 2022 11:46:56 +0000 Subject: [PATCH 35/43] run gofmt -s This commit was moved from ipfs/go-unixfsnode@c65306aa357f0579a3214f80fff74e463a78cbcb --- unixfs/node/data/builder/builder.go | 13 ++++++------- unixfs/node/data/builder/file.go | 25 +++++++++++++------------ unixfs/node/data/ipldsch_types.go | 5 ++--- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/unixfs/node/data/builder/builder.go b/unixfs/node/data/builder/builder.go index a2641096f..9532917d8 100644 --- a/unixfs/node/data/builder/builder.go +++ b/unixfs/node/data/builder/builder.go @@ -14,13 +14,12 @@ import ( // that match the UnixFS protobuf encoded in the Data member of a ProtoNode // with sensible defaults // -// smallFileData, err := BuildUnixFS(func(b *Builder) { -// Data(b, []byte{"hello world"}) -// Mtime(b, func(tb TimeBuilder) { -// Time(tb, time.Now()) -// }) -// }) -// +// smallFileData, err := BuildUnixFS(func(b *Builder) { +// Data(b, []byte{"hello world"}) +// Mtime(b, func(tb TimeBuilder) { +// Time(tb, time.Now()) +// }) +// }) func BuildUnixFS(fn func(*Builder)) (data.UnixFSData, error) { nd, err := qp.BuildMap(data.Type.UnixFSData, -1, func(ma ipld.MapAssembler) { b := &Builder{MapAssembler: ma} diff --git a/unixfs/node/data/builder/file.go b/unixfs/node/data/builder/file.go index 8309e42a4..1aafe9778 100644 --- a/unixfs/node/data/builder/file.go +++ b/unixfs/node/data/builder/file.go @@ -24,9 +24,9 @@ import ( // go-unixfsnode & ipld-prime data layout of nodes. // We make some assumptions in building files with this builder to reduce // complexity, namely: -// * we assume we are using CIDv1, which has implied that the leaf -// data nodes are stored as raw bytes. -// ref: https://github.com/ipfs/go-mfs/blob/1b1fd06cff048caabeddb02d4dbf22d2274c7971/file.go#L50 +// - we assume we are using CIDv1, which has implied that the leaf +// data nodes are stored as raw bytes. +// ref: https://github.com/ipfs/go-mfs/blob/1b1fd06cff048caabeddb02d4dbf22d2274c7971/file.go#L50 func BuildUnixFSFile(r io.Reader, chunker string, ls *ipld.LinkSystem) (ipld.Link, uint64, error) { s, err := chunk.FromString(r, chunker) if err != nil { @@ -256,15 +256,16 @@ var roughLinkSize = 34 + 8 + 5 // sha256 multihash + size + no name + protobuf // DefaultLinksPerBlock governs how the importer decides how many links there // will be per block. This calculation is based on expected distributions of: -// * the expected distribution of block sizes -// * the expected distribution of link sizes -// * desired access speed +// - the expected distribution of block sizes +// - the expected distribution of link sizes +// - desired access speed +// // For now, we use: // -// var roughLinkBlockSize = 1 << 13 // 8KB -// var roughLinkSize = 34 + 8 + 5 // sha256 multihash + size + no name -// // + protobuf framing -// var DefaultLinksPerBlock = (roughLinkBlockSize / roughLinkSize) -// = ( 8192 / 47 ) -// = (approximately) 174 +// var roughLinkBlockSize = 1 << 13 // 8KB +// var roughLinkSize = 34 + 8 + 5 // sha256 multihash + size + no name +// // + protobuf framing +// var DefaultLinksPerBlock = (roughLinkBlockSize / roughLinkSize) +// = ( 8192 / 47 ) +// = (approximately) 174 var DefaultLinksPerBlock = roughLinkBlockSize / roughLinkSize diff --git a/unixfs/node/data/ipldsch_types.go b/unixfs/node/data/ipldsch_types.go index 6b4a65114..36897b169 100644 --- a/unixfs/node/data/ipldsch_types.go +++ b/unixfs/node/data/ipldsch_types.go @@ -11,12 +11,11 @@ var _ ipld.Node = nil // suppress errors when this dependency is not referenced // One of its major uses is to start the construction of a value. // You can use it like this: // -// data.Type.YourTypeName.NewBuilder().BeginMap() //... +// data.Type.YourTypeName.NewBuilder().BeginMap() //... // // and: // -// data.Type.OtherTypeName.NewBuilder().AssignString("x") // ... -// +// data.Type.OtherTypeName.NewBuilder().AssignString("x") // ... var Type typeSlab type typeSlab struct { From a7ae3e74cd8d704d811c5511c788ba46afe34a68 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Wed, 24 Aug 2022 14:04:42 +1000 Subject: [PATCH 36/43] fix: remove use of ioutil This commit was moved from ipfs/go-unixfsnode@4afe29f977c46c569c9579964f5e0c7a88c31cf9 --- unixfs/node/data/format_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unixfs/node/data/format_test.go b/unixfs/node/data/format_test.go index 8c53ad917..fd995c676 100644 --- a/unixfs/node/data/format_test.go +++ b/unixfs/node/data/format_test.go @@ -3,7 +3,7 @@ package data_test // adapted from https://github.com/ipfs/js-ipfs-unixfs/blob/master/packages/ipfs-unixfs/test/unixfs-format.spec.js import ( - "io/ioutil" + "io" "os" "path" "runtime" @@ -25,7 +25,7 @@ func loadFixture(name string) []byte { if err != nil { panic(err) } - data, err := ioutil.ReadAll(f) + data, err := io.ReadAll(f) if err != nil { panic(err) } From 4470d1204be8f4a272311192e6cc5170fb8e4028 Mon Sep 17 00:00:00 2001 From: Will Scott Date: Sat, 8 Oct 2022 12:56:17 -0700 Subject: [PATCH 37/43] add an ADL to preload hamt loading This commit was moved from ipfs/go-unixfsnode@e95359d55828aff7aa681fb5ea269537bc3804a3 --- unixfs/node/hamt/shardeddir.go | 16 ++++++++++++++++ unixfs/node/reification.go | 21 +++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/unixfs/node/hamt/shardeddir.go b/unixfs/node/hamt/shardeddir.go index ebc59c548..97a833ff0 100644 --- a/unixfs/node/hamt/shardeddir.go +++ b/unixfs/node/hamt/shardeddir.go @@ -54,6 +54,22 @@ func NewUnixFSHAMTShard(ctx context.Context, substrate dagpb.PBNode, data data.U }, nil } +// NewUnixFSHAMTShardWithPreload attempts to construct a UnixFSHAMTShard node from the base protobuf node plus +// a decoded UnixFSData structure, and then iterate through and load the full set of hamt shards. +func NewUnixFSHAMTShardWithPreload(ctx context.Context, substrate dagpb.PBNode, data data.UnixFSData, lsys *ipld.LinkSystem) (ipld.Node, error) { + n, err := NewUnixFSHAMTShard(ctx, substrate, data, lsys) + if err != nil { + return n, err + } + + traverse := n.Length() + if traverse == -1 { + return n, fmt.Errorf("could not fully explore hamt during preload") + } + + return n, nil +} + func (n UnixFSHAMTShard) Substrate() ipld.Node { return n._substrate } diff --git a/unixfs/node/reification.go b/unixfs/node/reification.go index fc79291f4..2f5123477 100644 --- a/unixfs/node/reification.go +++ b/unixfs/node/reification.go @@ -15,6 +15,10 @@ import ( // Reify looks at an ipld Node and tries to interpret it as a UnixFSNode // if successful, it returns the UnixFSNode func Reify(lnkCtx ipld.LinkContext, maybePBNodeRoot ipld.Node, lsys *ipld.LinkSystem) (ipld.Node, error) { + return doReify(lnkCtx, maybePBNodeRoot, lsys, true) +} + +func doReify(lnkCtx ipld.LinkContext, maybePBNodeRoot ipld.Node, lsys *ipld.LinkSystem, lazy bool) (ipld.Node, error) { pbNode, ok := maybePBNodeRoot.(dagpb.PBNode) if !ok { return maybePBNodeRoot, nil @@ -28,7 +32,12 @@ func Reify(lnkCtx ipld.LinkContext, maybePBNodeRoot ipld.Node, lsys *ipld.LinkSy // we could not decode the UnixFS data, therefore, not UnixFS return defaultReifier(lnkCtx.Ctx, pbNode, lsys) } - builder, ok := reifyFuncs[data.FieldDataType().Int()] + var builder reifyTypeFunc + if lazy { + builder, ok = lazyReifyFuncs[data.FieldDataType().Int()] + } else { + builder, ok = reifyFuncs[data.FieldDataType().Int()] + } if !ok { return nil, fmt.Errorf("no reification for this UnixFS node type") } @@ -38,6 +47,14 @@ func Reify(lnkCtx ipld.LinkContext, maybePBNodeRoot ipld.Node, lsys *ipld.LinkSy type reifyTypeFunc func(context.Context, dagpb.PBNode, data.UnixFSData, *ipld.LinkSystem) (ipld.Node, error) var reifyFuncs = map[int64]reifyTypeFunc{ + data.Data_File: unixFSFileReifier, + data.Data_Metadata: defaultUnixFSReifier, + data.Data_Raw: unixFSFileReifier, + data.Data_Symlink: defaultUnixFSReifier, + data.Data_Directory: directory.NewUnixFSBasicDir, + data.Data_HAMTShard: hamt.NewUnixFSHAMTShardWithPreload, +} +var lazyReifyFuncs = map[int64]reifyTypeFunc{ data.Data_File: unixFSFileReifier, data.Data_Metadata: defaultUnixFSReifier, data.Data_Raw: unixFSFileReifier, @@ -47,7 +64,7 @@ var reifyFuncs = map[int64]reifyTypeFunc{ } // treat non-unixFS nodes like directories -- allow them to lookup by link -// TODO: Make this a separate node as directors gain more functionality +// TODO: Make this a separate node as directories gain more functionality func defaultReifier(_ context.Context, substrate dagpb.PBNode, _ *ipld.LinkSystem) (ipld.Node, error) { return &_PathedPBNode{_substrate: substrate}, nil } From 7957235a270b77cf527e242e72b5d0e9457713a7 Mon Sep 17 00:00:00 2001 From: Will Scott Date: Sat, 8 Oct 2022 13:00:38 -0700 Subject: [PATCH 38/43] remaining linking This commit was moved from ipfs/go-unixfsnode@04e6d4d7d94b1199e1867674f4ee7203405c5d17 --- unixfs/node/file/file.go | 15 +++++++++++++++ unixfs/node/reification.go | 11 ++++++++++- unixfs/node/signaling.go | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/unixfs/node/file/file.go b/unixfs/node/file/file.go index 17a004a5a..20490dca7 100644 --- a/unixfs/node/file/file.go +++ b/unixfs/node/file/file.go @@ -33,6 +33,21 @@ func NewUnixFSFile(ctx context.Context, substrate ipld.Node, lsys *ipld.LinkSyst }, nil } +func NewUnixFSFileWithPreload(ctx context.Context, substrate ipld.Node, lsys *ipld.LinkSystem) (LargeBytesNode, error) { + f, err := NewUnixFSFile(ctx, substrate, lsys) + if err != nil { + return nil, err + } + r, err := f.AsLargeBytes() + if err != nil { + return nil, err + } + if _, err := io.Copy(io.Discard, r); err != nil { + return nil, err + } + return f, nil +} + // A LargeBytesNode is an ipld.Node that can be streamed over. It is guaranteed to have a Bytes type. type LargeBytesNode interface { ipld.Node diff --git a/unixfs/node/reification.go b/unixfs/node/reification.go index 2f5123477..dd293c1d7 100644 --- a/unixfs/node/reification.go +++ b/unixfs/node/reification.go @@ -18,6 +18,11 @@ func Reify(lnkCtx ipld.LinkContext, maybePBNodeRoot ipld.Node, lsys *ipld.LinkSy return doReify(lnkCtx, maybePBNodeRoot, lsys, true) } +// nonLazyReify works like reify but will load all of a directory or file as it reaches them. +func nonLazyReify(lnkCtx ipld.LinkContext, maybePBNodeRoot ipld.Node, lsys *ipld.LinkSystem) (ipld.Node, error) { + return doReify(lnkCtx, maybePBNodeRoot, lsys, false) +} + func doReify(lnkCtx ipld.LinkContext, maybePBNodeRoot ipld.Node, lsys *ipld.LinkSystem, lazy bool) (ipld.Node, error) { pbNode, ok := maybePBNodeRoot.(dagpb.PBNode) if !ok { @@ -47,7 +52,7 @@ func doReify(lnkCtx ipld.LinkContext, maybePBNodeRoot ipld.Node, lsys *ipld.Link type reifyTypeFunc func(context.Context, dagpb.PBNode, data.UnixFSData, *ipld.LinkSystem) (ipld.Node, error) var reifyFuncs = map[int64]reifyTypeFunc{ - data.Data_File: unixFSFileReifier, + data.Data_File: unixFSFileReifierWithPreload, data.Data_Metadata: defaultUnixFSReifier, data.Data_Raw: unixFSFileReifier, data.Data_Symlink: defaultUnixFSReifier, @@ -73,6 +78,10 @@ func unixFSFileReifier(ctx context.Context, substrate dagpb.PBNode, _ data.UnixF return file.NewUnixFSFile(ctx, substrate, ls) } +func unixFSFileReifierWithPreload(ctx context.Context, substrate dagpb.PBNode, _ data.UnixFSData, ls *ipld.LinkSystem) (ipld.Node, error) { + return file.NewUnixFSFileWithPreload(ctx, substrate, ls) +} + func defaultUnixFSReifier(ctx context.Context, substrate dagpb.PBNode, _ data.UnixFSData, ls *ipld.LinkSystem) (ipld.Node, error) { return defaultReifier(ctx, substrate, ls) } diff --git a/unixfs/node/signaling.go b/unixfs/node/signaling.go index 56eb52df0..056d2ab01 100644 --- a/unixfs/node/signaling.go +++ b/unixfs/node/signaling.go @@ -15,6 +15,7 @@ func AddUnixFSReificationToLinkSystem(lsys *ipld.LinkSystem) { lsys.KnownReifiers = make(map[string]linking.NodeReifier) } lsys.KnownReifiers["unixfs"] = Reify + lsys.KnownReifiers["unixfs-preload"] = nonLazyReify } // UnixFSPathSelector creates a selector for a file/path inside of a UnixFS directory From e438fa7bf1be3f34bef273a9485dbb2daa3f33aa Mon Sep 17 00:00:00 2001 From: Will Date: Sat, 15 Oct 2022 13:31:39 +0000 Subject: [PATCH 39/43] Update file/file.go Co-authored-by: Rod Vagg This commit was moved from ipfs/go-unixfsnode@79130b4b766c45dbfa0a0d4a7e9ccdf2bf32ab32 --- unixfs/node/file/file.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/unixfs/node/file/file.go b/unixfs/node/file/file.go index 20490dca7..d9710330c 100644 --- a/unixfs/node/file/file.go +++ b/unixfs/node/file/file.go @@ -33,6 +33,10 @@ func NewUnixFSFile(ctx context.Context, substrate ipld.Node, lsys *ipld.LinkSyst }, nil } +// NewUnixFSFileWithPreload is the same as NewUnixFSFile but it performs a full load of constituent +// blocks where the file spans multiple blocks. This is useful where a system needs to watch the +// LinkSystem for block loads to determine which blocks make up this file. +// NewUnixFSFileWithPreload is used by the "unixfs-preload" reifier. func NewUnixFSFileWithPreload(ctx context.Context, substrate ipld.Node, lsys *ipld.LinkSystem) (LargeBytesNode, error) { f, err := NewUnixFSFile(ctx, substrate, lsys) if err != nil { From d91d9739e4b168f9682f277addde2cc5a4442007 Mon Sep 17 00:00:00 2001 From: Will Scott Date: Sat, 15 Oct 2022 08:37:39 -0500 Subject: [PATCH 40/43] expand readme a bit This commit was moved from ipfs/go-unixfsnode@f9e443f107fd7ad7168a4b7b2e7a5ccf6b549ab7 --- unixfs/node/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/unixfs/node/README.md b/unixfs/node/README.md index 2146b6c8e..f55a1b5a9 100644 --- a/unixfs/node/README.md +++ b/unixfs/node/README.md @@ -4,6 +4,17 @@ This is an IPLD ADL that provides string based pathing for protobuf nodes. The t Note that while it works internally with go-codec-dagpb, the Reify method (used to get a UnixFSNode from a DagPB node should actually work successfully with go-ipld-prime-proto nodes) +## Usage + +The primary interaction with this package is to register an ADL on a link system. This is done with via a helper method. + +```go +AddUnixFSReificationToLinkSystem(lsys *ipld.LinkSystem) +``` + +For link systems which have UnixFS reification registered, two ADLs will be available to the [`InterpretAs`](https://ipld.io/specs/selectors/) selector: 'unixfs' and 'unixfs-preload'. The different between these two ADLs is that the preload variant will access all blocks within a UnixFS Object (file or directory) when that object is accessed by a selector traversal. The non-preload variant in contrast will only access the subset of blocks strictly needed for the traversal. In practice, this means the subset of a sharded directory needed to access a specific file, or the sub-range of a file directly accessed by a range selector. + + ## License Apache-2.0/MIT © Protocol Labs From 971cdf424debc02b5f0e9280168449460e31d56f Mon Sep 17 00:00:00 2001 From: Rong Zhou Date: Mon, 9 Jan 2023 17:57:19 +0800 Subject: [PATCH 41/43] fix a possible `index out of range` crash This commit was moved from ipfs/go-unixfsnode@3771b58d40916a251bfe3c5b95ff8a6a6e5da2b8 --- unixfs/node/data/builder/file.go | 1 + 1 file changed, 1 insertion(+) diff --git a/unixfs/node/data/builder/file.go b/unixfs/node/data/builder/file.go index 1aafe9778..a52278486 100644 --- a/unixfs/node/data/builder/file.go +++ b/unixfs/node/data/builder/file.go @@ -109,6 +109,7 @@ func fileTreeRecursive(depth int, children []ipld.Link, childLen []uint64, src c } totalSize += sz children = append(children, nxt) + childLen = append(childLen, sz) blksizes = append(blksizes, sz) } if len(children) == 0 { From 0d10ff9c13613b97229c3443e2338eb84ee04ac4 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 12 Jan 2023 11:40:58 +0100 Subject: [PATCH 42/43] chore: go mod tidy --- go.mod | 52 +++++++++++++--- go.sum | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 221 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index 7f40a640f..a041d3781 100644 --- a/go.mod +++ b/go.mod @@ -6,48 +6,84 @@ require ( github.com/benbjohnson/clock v1.3.0 github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 github.com/gorilla/mux v1.8.0 + github.com/ipfs/go-bitfield v1.0.0 github.com/ipfs/go-cid v0.3.2 + github.com/ipfs/go-ipfs-chunker v0.0.5 + github.com/ipfs/go-ipfs-util v0.0.2 + github.com/ipfs/go-ipld-format v0.4.0 github.com/ipfs/go-ipns v0.3.0 github.com/ipfs/go-log/v2 v2.5.1 + github.com/ipfs/go-merkledag v0.9.0 + github.com/ipfs/go-unixfs v0.4.1 + github.com/ipfs/go-unixfsnode v1.5.1 + github.com/ipld/go-car/v2 v2.5.1 + github.com/ipld/go-codec-dagpb v1.5.0 + github.com/ipld/go-ipld-prime v0.19.0 github.com/libp2p/go-libp2p v0.23.4 github.com/libp2p/go-libp2p-record v0.2.0 github.com/multiformats/go-multiaddr v0.8.0 github.com/multiformats/go-multibase v0.1.1 + github.com/multiformats/go-multicodec v0.6.0 github.com/multiformats/go-multihash v0.2.1 github.com/samber/lo v1.36.0 + github.com/spaolacci/murmur3 v1.1.0 github.com/stretchr/testify v1.8.1 go.opencensus.io v0.23.0 golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab + google.golang.org/protobuf v1.28.1 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect + github.com/go-logr/logr v1.2.3 // indirect + github.com/go-logr/stdr v1.2.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/ipfs/go-ipfs-util v0.0.2 // indirect - github.com/ipld/go-ipld-prime v0.9.0 // indirect - github.com/klauspost/cpuid/v2 v2.1.1 // indirect + github.com/google/uuid v1.3.0 // indirect + github.com/hashicorp/golang-lru v0.5.4 // indirect + github.com/ipfs/bbloom v0.0.4 // indirect + github.com/ipfs/go-block-format v0.0.3 // indirect + github.com/ipfs/go-blockservice v0.5.0 // indirect + github.com/ipfs/go-datastore v0.6.0 // indirect + github.com/ipfs/go-ipfs-blockstore v1.2.0 // indirect + github.com/ipfs/go-ipfs-ds-help v1.1.0 // indirect + github.com/ipfs/go-ipfs-exchange-interface v0.2.0 // indirect + github.com/ipfs/go-ipfs-exchange-offline v0.3.0 // indirect + github.com/ipfs/go-ipld-cbor v0.0.6 // indirect + github.com/ipfs/go-ipld-legacy v0.1.1 // indirect + github.com/ipfs/go-log v1.0.5 // indirect + github.com/ipfs/go-metrics-interface v0.0.1 // indirect + github.com/ipfs/go-verifcid v0.0.2 // indirect + github.com/jbenet/goprocess v0.1.4 // indirect + github.com/klauspost/cpuid/v2 v2.1.2 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-openssl v0.1.0 // indirect - github.com/mattn/go-isatty v0.0.16 // indirect + github.com/mattn/go-isatty v0.0.17 // indirect github.com/mattn/go-pointer v0.0.1 // indirect github.com/minio/sha256-simd v1.0.0 // indirect github.com/mr-tron/base58 v1.2.0 // indirect github.com/multiformats/go-base32 v0.1.0 // indirect github.com/multiformats/go-base36 v0.1.0 // indirect - github.com/multiformats/go-multicodec v0.6.0 // indirect - github.com/multiformats/go-varint v0.0.6 // indirect + github.com/multiformats/go-varint v0.0.7 // indirect + github.com/opentracing/opentracing-go v1.2.0 // indirect + github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/polydawn/refmt v0.0.0-20190807091052-3d65705ee9f1 // indirect + github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e // indirect github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect - github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/stretchr/objx v0.5.0 // indirect + github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11 // indirect + github.com/whyrusleeping/cbor-gen v0.0.0-20221220214510-0333c149dec0 // indirect + github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f // indirect + go.opentelemetry.io/otel v1.7.0 // indirect + go.opentelemetry.io/otel/trace v1.7.0 // indirect go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.8.0 // indirect go.uber.org/zap v1.23.0 // indirect golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect golang.org/x/exp v0.0.0-20220916125017-b168a2c6b86b // indirect + golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect + golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.1.7 // indirect ) diff --git a/go.sum b/go.sum index ab57d0a12..30b80e416 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,7 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 h1:HVTnpeuvF6Owjd5mniCL8DEXo7uYXdQEmOP4FJbV5tg= github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3/go.mod h1:p1d6YEZWvFzEh4KLyvBcVSnrfNDDvK2zfK/4x2v/4pE= +github.com/cskr/pubsub v1.0.2 h1:vlOzMhl6PFn60gRlTQQsIfVwaPB/B/8MziK8FhEPt/0= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -19,6 +20,13 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= +github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= +github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -34,6 +42,7 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -41,50 +50,149 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= +github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= +github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= +github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/huin/goupnp v1.0.3 h1:N8No57ls+MnjlB+JPiCVSOyy/ot7MJTqlo7rn+NYSqQ= +github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs= +github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0= +github.com/ipfs/go-bitfield v1.0.0 h1:y/XHm2GEmD9wKngheWNNCNL0pzrWXZwCdQGv1ikXknQ= +github.com/ipfs/go-bitfield v1.0.0/go.mod h1:N/UiujQy+K+ceU1EF5EkVd1TNqevLrCQMIcAEPrdtus= +github.com/ipfs/go-bitswap v0.11.0 h1:j1WVvhDX1yhG32NTC9xfxnqycqYIlhzEzLXG/cU1HyQ= +github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY= +github.com/ipfs/go-block-format v0.0.3 h1:r8t66QstRp/pd/or4dpnbVfXT5Gt7lOqRvC+/dDTpMc= +github.com/ipfs/go-block-format v0.0.3/go.mod h1:4LmD4ZUw0mhO+JSKdpWwrzATiEfM7WWgQ8H5l6P8MVk= +github.com/ipfs/go-blockservice v0.5.0 h1:B2mwhhhVQl2ntW2EIpaWPwSCxSuqr5fFA93Ms4bYLEY= +github.com/ipfs/go-blockservice v0.5.0/go.mod h1:W6brZ5k20AehbmERplmERn8o2Ni3ZZubvAxaIUeaT6w= +github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= +github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= +github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= github.com/ipfs/go-cid v0.0.4/go.mod h1:4LLaPOQwmk5z9LBgQnpkivrx8BJjUyGwTXCd5Xfj6+M= +github.com/ipfs/go-cid v0.0.5/go.mod h1:plgt+Y5MnOey4vO4UlUazGqdbEXuFYitED67FexhXog= +github.com/ipfs/go-cid v0.0.6/go.mod h1:6Ux9z5e+HpkQdckYoX1PG/6xqKspzlEIR5SDmgqgC/I= +github.com/ipfs/go-cid v0.0.7/go.mod h1:6Ux9z5e+HpkQdckYoX1PG/6xqKspzlEIR5SDmgqgC/I= github.com/ipfs/go-cid v0.3.2 h1:OGgOd+JCFM+y1DjWPmVH+2/4POtpDzwcr7VgnB7mZXc= github.com/ipfs/go-cid v0.3.2/go.mod h1:gQ8pKqT/sUxGY+tIwy1RPpAojYu7jAyCp5Tz1svoupw= +github.com/ipfs/go-datastore v0.5.0/go.mod h1:9zhEApYMTl17C8YDp7JmU7sQZi2/wqiYh73hakZ90Bk= +github.com/ipfs/go-datastore v0.6.0 h1:JKyz+Gvz1QEZw0LsX1IBn+JFCJQH4SJVFtM4uWU0Myk= +github.com/ipfs/go-datastore v0.6.0/go.mod h1:rt5M3nNbSO/8q1t4LNkLyUwRs8HupMeN/8O4Vn9YAT8= +github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk= +github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= +github.com/ipfs/go-ipfs-blockstore v1.2.0 h1:n3WTeJ4LdICWs/0VSfjHrlqpPpl6MZ+ySd3j8qz0ykw= +github.com/ipfs/go-ipfs-blockstore v1.2.0/go.mod h1:eh8eTFLiINYNSNawfZOC7HOxNTxpB1PFuA5E1m/7exE= +github.com/ipfs/go-ipfs-blocksutil v0.0.1 h1:Eh/H4pc1hsvhzsQoMEP3Bke/aW5P5rVM1IWFJMcGIPQ= +github.com/ipfs/go-ipfs-chunker v0.0.5 h1:ojCf7HV/m+uS2vhUGWcogIIxiO5ubl5O57Q7NapWLY8= +github.com/ipfs/go-ipfs-chunker v0.0.5/go.mod h1:jhgdF8vxRHycr00k13FM8Y0E+6BoalYeobXmUyTreP8= +github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= +github.com/ipfs/go-ipfs-delay v0.0.1 h1:r/UXYyRcddO6thwOnhiznIAiSvxMECGgtv35Xs1IeRQ= +github.com/ipfs/go-ipfs-ds-help v1.1.0 h1:yLE2w9RAsl31LtfMt91tRZcrx+e61O5mDxFRR994w4Q= +github.com/ipfs/go-ipfs-ds-help v1.1.0/go.mod h1:YR5+6EaebOhfcqVCyqemItCLthrpVNot+rsOU/5IatU= +github.com/ipfs/go-ipfs-exchange-interface v0.2.0 h1:8lMSJmKogZYNo2jjhUs0izT+dck05pqUw4mWNW9Pw6Y= +github.com/ipfs/go-ipfs-exchange-interface v0.2.0/go.mod h1:z6+RhJuDQbqKguVyslSOuVDhqF9JtTrO3eptSAiW2/Y= +github.com/ipfs/go-ipfs-exchange-offline v0.3.0 h1:c/Dg8GDPzixGd0MC8Jh6mjOwU57uYokgWRFidfvEkuA= +github.com/ipfs/go-ipfs-exchange-offline v0.3.0/go.mod h1:MOdJ9DChbb5u37M1IcbrRB02e++Z7521fMxqCNRrz9s= +github.com/ipfs/go-ipfs-pq v0.0.2 h1:e1vOOW6MuOwG2lqxcLA+wEn93i/9laCY8sXAw76jFOY= +github.com/ipfs/go-ipfs-routing v0.3.0 h1:9W/W3N+g+y4ZDeffSgqhgo7BsBSJwPMcyssET9OWevc= +github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc= github.com/ipfs/go-ipfs-util v0.0.2 h1:59Sswnk1MFaiq+VcaknX7aYEyGyGDAA73ilhEK2POp8= github.com/ipfs/go-ipfs-util v0.0.2/go.mod h1:CbPtkWJzjLdEcezDns2XYaehFVNXG9zrdrtMecczcsQ= +github.com/ipfs/go-ipld-cbor v0.0.6 h1:pYuWHyvSpIsOOLw4Jy7NbBkCyzLDcl64Bf/LZW7eBQ0= +github.com/ipfs/go-ipld-cbor v0.0.6/go.mod h1:ssdxxaLJPXH7OjF5V4NSjBbcfh+evoR4ukuru0oPXMA= +github.com/ipfs/go-ipld-format v0.0.1/go.mod h1:kyJtbkDALmFHv3QR6et67i35QzO3S0dCDnkOJhcZkms= +github.com/ipfs/go-ipld-format v0.2.0/go.mod h1:3l3C1uKoadTPbeNfrDi+xMInYKlx2Cvg1BuydPSdzQs= +github.com/ipfs/go-ipld-format v0.3.0/go.mod h1:co/SdBE8h99968X0hViiw1MNlh6fvxxnHpvVLnH7jSM= +github.com/ipfs/go-ipld-format v0.4.0 h1:yqJSaJftjmjc9jEOFYlpkwOLVKv68OD27jFLlSghBlQ= +github.com/ipfs/go-ipld-format v0.4.0/go.mod h1:co/SdBE8h99968X0hViiw1MNlh6fvxxnHpvVLnH7jSM= +github.com/ipfs/go-ipld-legacy v0.1.1 h1:BvD8PEuqwBHLTKqlGFTHSwrwFOMkVESEvwIYwR2cdcc= +github.com/ipfs/go-ipld-legacy v0.1.1/go.mod h1:8AyKFCjgRPsQFf15ZQgDB8Din4DML/fOmKZkkFkrIEg= github.com/ipfs/go-ipns v0.3.0 h1:ai791nTgVo+zTuq2bLvEGmWP1M0A6kGTXUsgv/Yq67A= github.com/ipfs/go-ipns v0.3.0/go.mod h1:3cLT2rbvgPZGkHJoPO1YMJeh6LtkxopCkKFcio/wE24= +github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= +github.com/ipfs/go-log v1.0.5 h1:2dOuUCB1Z7uoczMWgAyDck5JLb72zHzrMnGnCNNbvY8= +github.com/ipfs/go-log v1.0.5/go.mod h1:j0b8ZoR+7+R99LD9jZ6+AJsrzkPbSXbZfGakb5JPtIo= +github.com/ipfs/go-log/v2 v2.1.3/go.mod h1:/8d0SH3Su5Ooc31QlL1WysJhvyOTDCjcCZ9Axpmri6g= github.com/ipfs/go-log/v2 v2.5.1 h1:1XdUzF7048prq4aBjDQQ4SL5RxftpRGdXhNRwKSAlcY= github.com/ipfs/go-log/v2 v2.5.1/go.mod h1:prSpmC1Gpllc9UYWxDiZDreBYw7zp4Iqp1kOLU9U5UI= -github.com/ipld/go-ipld-prime v0.9.0 h1:N2OjJMb+fhyFPwPnVvJcWU/NsumP8etal+d2v3G4eww= -github.com/ipld/go-ipld-prime v0.9.0/go.mod h1:KvBLMr4PX1gWptgkzRjVZCrLmSGcZCb/jioOQwCqZN8= +github.com/ipfs/go-merkledag v0.9.0 h1:DFC8qZ96Dz1hMT7dtIpcY524eFFDiEWAF8hNJHWW2pk= +github.com/ipfs/go-merkledag v0.9.0/go.mod h1:bPHqkHt5OZ0p1n3iqPeDiw2jIBkjAytRjS3WSBwjq90= +github.com/ipfs/go-metrics-interface v0.0.1 h1:j+cpbjYvu4R8zbleSs36gvB7jR+wsL2fGD6n0jO4kdg= +github.com/ipfs/go-metrics-interface v0.0.1/go.mod h1:6s6euYU4zowdslK0GKHmqaIZ3j/b/tL7HTWtJ4VPgWY= +github.com/ipfs/go-peertaskqueue v0.8.0 h1:JyNO144tfu9bx6Hpo119zvbEL9iQ760FHOiJYsUjqaU= +github.com/ipfs/go-unixfs v0.4.1 h1:nmJFKvF+khK03PIWyCxxydD/nkQX315NZDcgvRqMXf0= +github.com/ipfs/go-unixfs v0.4.1/go.mod h1:2SUDFhUSzrcL408B1qpIkJJ5HznnyTzweViPXUAvkNg= +github.com/ipfs/go-unixfsnode v1.5.1 h1:JcR3t5C2nM1V7PMzhJ/Qmo19NkoFIKweDSZyDx+CjkI= +github.com/ipfs/go-unixfsnode v1.5.1/go.mod h1:ed79DaG9IEuZITJVQn4U6MZDftv6I3ygUBLPfhEbHvk= +github.com/ipfs/go-verifcid v0.0.2 h1:XPnUv0XmdH+ZIhLGKg6U2vaPaRDXb9urMyNVCE7uvTs= +github.com/ipfs/go-verifcid v0.0.2/go.mod h1:40cD9x1y4OWnFXbLNJYRe7MpNvWlMn3LZAG5Wb4xnPU= +github.com/ipld/go-car/v2 v2.5.1 h1:U2ux9JS23upEgrJScW8VQuxmE94560kYxj9CQUpcfmk= +github.com/ipld/go-car/v2 v2.5.1/go.mod h1:jKjGOqoCj5zn6KjnabD6JbnCsMntqU2hLiU6baZVO3E= +github.com/ipld/go-codec-dagpb v1.5.0 h1:RspDRdsJpLfgCI0ONhTAnbHdySGD4t+LHSPK4X1+R0k= +github.com/ipld/go-codec-dagpb v1.5.0/go.mod h1:0yRIutEFD8o1DGVqw4RSHh+BUTlJA9XWldxaaWR/o4g= +github.com/ipld/go-ipld-prime v0.9.1-0.20210324083106-dc342a9917db/go.mod h1:KvBLMr4PX1gWptgkzRjVZCrLmSGcZCb/jioOQwCqZN8= +github.com/ipld/go-ipld-prime v0.19.0 h1:5axC7rJmPc17Emw6TelxGwnzALk0PdupZ2oj2roDj04= +github.com/ipld/go-ipld-prime v0.19.0/go.mod h1:Q9j3BaVXwaA3o5JUDNvptDDr/x8+F7FG6XJ8WI3ILg4= +github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20211210234204-ce2a1c70cd73 h1:TsyATB2ZRRQGTwafJdgEUQkmjOExRV0DNokcihZxbnQ= +github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= +github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= +github.com/jbenet/goprocess v0.1.4 h1:DRGOFReOMqqDNXwW70QkacFW0YN9QnwLV0Vqk+3oU0o= +github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4= +github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.1.1 h1:t0wUqjowdm8ezddV5k0tLWVklVuvLJpoHeb4WBdydm0= -github.com/klauspost/cpuid/v2 v2.1.1/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +github.com/klauspost/cpuid/v2 v2.1.2 h1:XhdX4fqAJUA0yj+kUwMavO0hHrSPAecYdYf1ZmxHvak= +github.com/klauspost/cpuid/v2 v2.1.2/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +github.com/koron/go-ssdp v0.0.3 h1:JivLMY45N76b4p/vsWGOKewBQu6uf39y8l+AQ7sDKx8= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM= github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg= +github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38yPW7c= github.com/libp2p/go-libp2p v0.23.4 h1:hWi9XHSOVFR1oDWRk7rigfyA4XNMuYL20INNybP9LP8= github.com/libp2p/go-libp2p v0.23.4/go.mod h1:s9DEa5NLR4g+LZS+md5uGU4emjMWFiqkZr6hBTY8UxI= +github.com/libp2p/go-libp2p-asn-util v0.2.0 h1:rg3+Os8jbnO5DxkC7K/Utdi+DkY3q/d1/1q+8WeNAsw= github.com/libp2p/go-libp2p-record v0.2.0 h1:oiNUOCWno2BFuxt3my4i1frNrt7PerzB3queqa1NkQ0= github.com/libp2p/go-libp2p-record v0.2.0/go.mod h1:I+3zMkvvg5m2OcSdoL0KPljyJyvNDFGKX7QdlpYUcwk= +github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA= +github.com/libp2p/go-msgio v0.2.0 h1:W6shmB+FeynDrUVl2dgFQvzfBZcXiyqY4VmpQLu9FqU= +github.com/libp2p/go-nat v0.1.0 h1:MfVsH6DLcpa04Xr+p8hmVRG4juse0s3J8HyNWYHffXg= +github.com/libp2p/go-netroute v0.2.0 h1:0FpsbsvuSnAhXFnCY0VLFbJOzaK0VnP0r1QT/o4nWRE= github.com/libp2p/go-openssl v0.1.0 h1:LBkKEcUv6vtZIQLVTegAil8jbNpJErQ9AnT+bWV+Ooo= github.com/libp2p/go-openssl v0.1.0/go.mod h1:OiOxwPpL3n4xlenjx2h7AwSGaFSC/KZvf6gNdOBQMtc= +github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= +github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= +github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-pointer v0.0.1 h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o0= github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc= +github.com/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= +github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g= github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= @@ -100,33 +208,49 @@ github.com/multiformats/go-base36 v0.1.0 h1:JR6TyF7JjGd3m6FbLU2cOxhC0Li8z8dLNGQ8 github.com/multiformats/go-base36 v0.1.0/go.mod h1:kFGE83c6s80PklsHO9sRn2NCoffoRdUUOENyW/Vv6sM= github.com/multiformats/go-multiaddr v0.8.0 h1:aqjksEcqK+iD/Foe1RRFsGZh8+XFiGo7FgUCZlpv3LU= github.com/multiformats/go-multiaddr v0.8.0/go.mod h1:Fs50eBDWvZu+l3/9S6xAE7ZYj6yhxlvaVZjakWN7xRs= +github.com/multiformats/go-multiaddr-dns v0.3.1 h1:QgQgR+LQVt3NPTjbrLLpsaT2ufAA2y0Mkk+QRVJbW3A= github.com/multiformats/go-multiaddr-fmt v0.1.0 h1:WLEFClPycPkp4fnIzoFoV9FVd49/eQsuaL3/CWe167E= github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= +github.com/multiformats/go-multibase v0.0.3/go.mod h1:5+1R4eQrT3PkYZ24C3W2Ue2tPwIdYQD509ZjSb5y9Oc= github.com/multiformats/go-multibase v0.1.1 h1:3ASCDsuLX8+j4kx58qnJ4YFq/JWTJpCyDW27ztsVTOI= github.com/multiformats/go-multibase v0.1.1/go.mod h1:ZEjHE+IsUrgp5mhlEAYjMtZwK1k4haNkcaPg9aoe1a8= github.com/multiformats/go-multicodec v0.6.0 h1:KhH2kSuCARyuJraYMFxrNO3DqIaYhOdS039kbhgVwpE= github.com/multiformats/go-multicodec v0.6.0/go.mod h1:GUC8upxSBE4oG+q3kWZRw/+6yC1BqO550bjhWsJbZlw= +github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= github.com/multiformats/go-multihash v0.0.10/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew= github.com/multiformats/go-multihash v0.0.13/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc= +github.com/multiformats/go-multihash v0.0.14/go.mod h1:VdAWLKTwram9oKAatUcLxBNUjdtcVwxObEQBtRfuyjc= github.com/multiformats/go-multihash v0.0.15/go.mod h1:D6aZrWNLFTV/ynMpKsNtB40mJzmCl4jb1alC0OvHiHg= github.com/multiformats/go-multihash v0.2.1 h1:aem8ZT0VA2nCHHk7bPJ1BjUbHNciqZC/d16Vve9l108= github.com/multiformats/go-multihash v0.2.1/go.mod h1:WxoMcYG85AZVQUyRyo9s4wULvW5qrI9vb2Lt6evduFc= +github.com/multiformats/go-multistream v0.3.3 h1:d5PZpjwRgVlbwfdTDjife7XszfZd8KYWfROYFlGcR8o= github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= -github.com/multiformats/go-varint v0.0.6 h1:gk85QWKxh3TazbLxED/NlDVv8+q+ReFJk7Y2W/KhfNY= github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= +github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8= +github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= +github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= +github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9 h1:1/WtZae0yGtPq+TI6+Tv1WTxkukpXeMlviSxvL7SRgk= +github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9/go.mod h1:x3N5drFsm2uilKKuuYo6LdyD8vZAW55sH/9w+pbo1sw= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polydawn/refmt v0.0.0-20190807091052-3d65705ee9f1 h1:CskT+S6Ay54OwxBGB0R3Rsx4Muto6UnEYTyKJbyRIAI= +github.com/polydawn/refmt v0.0.0-20190221155625-df39d6c2d992/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o= github.com/polydawn/refmt v0.0.0-20190807091052-3d65705ee9f1/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o= +github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e h1:ZOcivgkkFRnjfoTcGsDq3UQYiBmekwLA+qg0OjyB/ls= +github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= github.com/samber/lo v1.36.0 h1:4LaOxH1mHnbDGhTVE0i1z8v/lWaQW8AIfOD3HU4mSaw= github.com/samber/lo v1.36.0/go.mod h1:HLeWcJRRyLKp3+/XBJvOrerCQn9mhdKMHyd7IRlgeQ8= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa/go.mod h1:2RVY1rIf+2J2o/IM9+vPq9RzmHDSseB7FoXiSNIUsoU= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 h1:RC6RW7j+1+HkWaX/Yh71Ee5ZHaHYt7ZP4sQgUrm6cDU= @@ -138,6 +262,7 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -145,25 +270,45 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/thoas/go-funk v0.9.1 h1:O549iLZqPpTUQ10ykd26sZhzD+rmR5pWhuElrhbC20M= +github.com/warpfork/go-testmark v0.10.0 h1:E86YlUMYfwIacEsQGlnTvjk1IgYkyTGjPhF0RnwTCmw= +github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw= github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a h1:G++j5e0OC488te356JvdhaM8YS6nMsjLAYF7JxCv07w= github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw= +github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11 h1:5HZfQkwe0mIfyDmc1Em5GqlNRzcdtlv4HTNmdpt7XH0= +github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11/go.mod h1:Wlo/SzPmxVp6vXpGt/zaXhHH0fn4IxgqZc82aKg6bpQ= +github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI= +github.com/whyrusleeping/cbor-gen v0.0.0-20221220214510-0333c149dec0 h1:obKzQ1ey5AJg5NKjgtTo/CKwLImVP4ETLRcsmzFJ4Qw= +github.com/whyrusleeping/cbor-gen v0.0.0-20221220214510-0333c149dec0/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= +github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f h1:jQa4QT2UP9WYv2nzyawpKMOCl+Z/jW7djv2/J50lj9E= +github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f/go.mod h1:p9UJB6dDgdPgMJZs7UjUOdulKyRr9fqkS+6JKAInPy8= +github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= +go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM= +go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk= +go.opentelemetry.io/otel/trace v1.7.0 h1:O37Iogk1lEkMRXewVtZ1BBTVn5JEp8GrJvP92bJqC6o= +go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48yyE4TNvoHqU= +go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= +go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8= go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= +go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY= go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY= +golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -177,12 +322,15 @@ golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTk golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190227160552-c95aed5357e7/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -190,6 +338,7 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20220920183852-bf014ff85ad5 h1:KafLifaRFIuSJ5C+7CyFJOF9haxKNC1CEIDk8GX6X0k= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -197,8 +346,12 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -214,20 +367,27 @@ golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXR golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= +golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= @@ -247,15 +407,23 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= lukechampine.com/blake3 v1.1.7 h1:GgRMhmdsuK8+ii6UZFDL8Nb+VyMwadAgcJyfYHxG6n0= lukechampine.com/blake3 v1.1.7/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA= From 6f33aab212e70db6823e83fcc9650bed6c0df37a Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 12 Jan 2023 12:18:40 +0100 Subject: [PATCH 43/43] chore: replace import paths --- go.mod | 2 +- unixfs/node/data/builder/builder.go | 2 +- unixfs/node/data/builder/dir_test.go | 2 +- unixfs/node/data/builder/directory.go | 2 +- unixfs/node/data/builder/dirshard.go | 4 ++-- unixfs/node/data/builder/file.go | 2 +- unixfs/node/data/builder/file_test.go | 2 +- unixfs/node/data/builder/quick/quick.go | 2 +- unixfs/node/data/builder/quick/quick_test.go | 2 +- unixfs/node/data/format_test.go | 4 ++-- unixfs/node/directory/basicdir.go | 6 +++--- unixfs/node/file/file_test.go | 6 +++--- unixfs/node/file/large_file_test.go | 4 ++-- unixfs/node/file/shard.go | 2 +- unixfs/node/file/wrapped.go | 2 +- unixfs/node/hamt/shardeddir.go | 4 ++-- unixfs/node/hamt/shardeddir_test.go | 2 +- unixfs/node/hamt/util.go | 2 +- unixfs/node/pathpbnode.go | 4 ++-- unixfs/node/reification.go | 8 ++++---- unixfs/node/test/partial_file_access_test.go | 4 ++-- 21 files changed, 34 insertions(+), 34 deletions(-) diff --git a/go.mod b/go.mod index a041d3781..1649a482f 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,6 @@ require ( github.com/ipfs/go-log/v2 v2.5.1 github.com/ipfs/go-merkledag v0.9.0 github.com/ipfs/go-unixfs v0.4.1 - github.com/ipfs/go-unixfsnode v1.5.1 github.com/ipld/go-car/v2 v2.5.1 github.com/ipld/go-codec-dagpb v1.5.0 github.com/ipld/go-ipld-prime v0.19.0 @@ -53,6 +52,7 @@ require ( github.com/ipfs/go-ipld-legacy v0.1.1 // indirect github.com/ipfs/go-log v1.0.5 // indirect github.com/ipfs/go-metrics-interface v0.0.1 // indirect + github.com/ipfs/go-unixfsnode v1.5.1 // indirect github.com/ipfs/go-verifcid v0.0.2 // indirect github.com/jbenet/goprocess v0.1.4 // indirect github.com/klauspost/cpuid/v2 v2.1.2 // indirect diff --git a/unixfs/node/data/builder/builder.go b/unixfs/node/data/builder/builder.go index 9532917d8..3637b3a92 100644 --- a/unixfs/node/data/builder/builder.go +++ b/unixfs/node/data/builder/builder.go @@ -5,7 +5,7 @@ import ( "strconv" "time" - "github.com/ipfs/go-unixfsnode/data" + "github.com/ipfs/go-libipfs/unixfs/node/data" "github.com/ipld/go-ipld-prime" "github.com/ipld/go-ipld-prime/fluent/qp" ) diff --git a/unixfs/node/data/builder/dir_test.go b/unixfs/node/data/builder/dir_test.go index a2b069813..901b9e160 100644 --- a/unixfs/node/data/builder/dir_test.go +++ b/unixfs/node/data/builder/dir_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/ipfs/go-cid" - "github.com/ipfs/go-unixfsnode" + unixfsnode "github.com/ipfs/go-libipfs/unixfs/node" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" diff --git a/unixfs/node/data/builder/directory.go b/unixfs/node/data/builder/directory.go index afb83e6a3..15b200624 100644 --- a/unixfs/node/data/builder/directory.go +++ b/unixfs/node/data/builder/directory.go @@ -6,7 +6,7 @@ import ( "os" "path" - "github.com/ipfs/go-unixfsnode/data" + "github.com/ipfs/go-libipfs/unixfs/node/data" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" diff --git a/unixfs/node/data/builder/dirshard.go b/unixfs/node/data/builder/dirshard.go index 299c81f22..4ced27046 100644 --- a/unixfs/node/data/builder/dirshard.go +++ b/unixfs/node/data/builder/dirshard.go @@ -5,8 +5,8 @@ import ( "hash" bitfield "github.com/ipfs/go-bitfield" - "github.com/ipfs/go-unixfsnode/data" - "github.com/ipfs/go-unixfsnode/hamt" + "github.com/ipfs/go-libipfs/unixfs/node/data" + "github.com/ipfs/go-libipfs/unixfs/node/hamt" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" "github.com/multiformats/go-multihash" diff --git a/unixfs/node/data/builder/file.go b/unixfs/node/data/builder/file.go index a52278486..d13891bb5 100644 --- a/unixfs/node/data/builder/file.go +++ b/unixfs/node/data/builder/file.go @@ -6,7 +6,7 @@ import ( "github.com/ipfs/go-cid" chunk "github.com/ipfs/go-ipfs-chunker" - "github.com/ipfs/go-unixfsnode/data" + "github.com/ipfs/go-libipfs/unixfs/node/data" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" diff --git a/unixfs/node/data/builder/file_test.go b/unixfs/node/data/builder/file_test.go index de3803e4f..f6719033b 100644 --- a/unixfs/node/data/builder/file_test.go +++ b/unixfs/node/data/builder/file_test.go @@ -7,7 +7,7 @@ import ( "github.com/ipfs/go-cid" u "github.com/ipfs/go-ipfs-util" - "github.com/ipfs/go-unixfsnode/file" + "github.com/ipfs/go-libipfs/unixfs/node/file" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" diff --git a/unixfs/node/data/builder/quick/quick.go b/unixfs/node/data/builder/quick/quick.go index eee1d32e5..ac1f65d71 100644 --- a/unixfs/node/data/builder/quick/quick.go +++ b/unixfs/node/data/builder/quick/quick.go @@ -5,7 +5,7 @@ package quickbuilder import ( "bytes" - "github.com/ipfs/go-unixfsnode/data/builder" + "github.com/ipfs/go-libipfs/unixfs/node/data/builder" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" ) diff --git a/unixfs/node/data/builder/quick/quick_test.go b/unixfs/node/data/builder/quick/quick_test.go index e644b0fe1..440caa6d4 100644 --- a/unixfs/node/data/builder/quick/quick_test.go +++ b/unixfs/node/data/builder/quick/quick_test.go @@ -3,7 +3,7 @@ package quickbuilder_test import ( "testing" - quickbuilder "github.com/ipfs/go-unixfsnode/data/builder/quick" + quickbuilder "github.com/ipfs/go-libipfs/unixfs/node/data/builder/quick" cidlink "github.com/ipld/go-ipld-prime/linking/cid" "github.com/ipld/go-ipld-prime/storage/memstore" ) diff --git a/unixfs/node/data/format_test.go b/unixfs/node/data/format_test.go index fd995c676..3079dcd50 100644 --- a/unixfs/node/data/format_test.go +++ b/unixfs/node/data/format_test.go @@ -11,8 +11,8 @@ import ( "testing" "time" - . "github.com/ipfs/go-unixfsnode/data" - "github.com/ipfs/go-unixfsnode/data/builder" + . "github.com/ipfs/go-libipfs/unixfs/node/data" + "github.com/ipfs/go-libipfs/unixfs/node/data/builder" "github.com/ipld/go-ipld-prime" "github.com/ipld/go-ipld-prime/fluent/qp" "github.com/stretchr/testify/require" diff --git a/unixfs/node/directory/basicdir.go b/unixfs/node/directory/basicdir.go index a41a8f05b..c160becb4 100644 --- a/unixfs/node/directory/basicdir.go +++ b/unixfs/node/directory/basicdir.go @@ -3,9 +3,9 @@ package directory import ( "context" - "github.com/ipfs/go-unixfsnode/data" - "github.com/ipfs/go-unixfsnode/iter" - "github.com/ipfs/go-unixfsnode/utils" + "github.com/ipfs/go-libipfs/unixfs/node/data" + "github.com/ipfs/go-libipfs/unixfs/node/iter" + "github.com/ipfs/go-libipfs/unixfs/node/utils" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" "github.com/ipld/go-ipld-prime/schema" diff --git a/unixfs/node/file/file_test.go b/unixfs/node/file/file_test.go index ee01a71d7..14378c553 100644 --- a/unixfs/node/file/file_test.go +++ b/unixfs/node/file/file_test.go @@ -7,9 +7,9 @@ import ( "io" "testing" - "github.com/ipfs/go-unixfsnode" - "github.com/ipfs/go-unixfsnode/directory" - "github.com/ipfs/go-unixfsnode/file" + unixfsnode "github.com/ipfs/go-libipfs/unixfs/node" + "github.com/ipfs/go-libipfs/unixfs/node/directory" + "github.com/ipfs/go-libipfs/unixfs/node/file" "github.com/ipld/go-car/v2/blockstore" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" diff --git a/unixfs/node/file/large_file_test.go b/unixfs/node/file/large_file_test.go index 9403c8b28..378ded20f 100644 --- a/unixfs/node/file/large_file_test.go +++ b/unixfs/node/file/large_file_test.go @@ -10,8 +10,8 @@ import ( "testing" ipfsutil "github.com/ipfs/go-ipfs-util" - "github.com/ipfs/go-unixfsnode/data/builder" - "github.com/ipfs/go-unixfsnode/file" + "github.com/ipfs/go-libipfs/unixfs/node/data/builder" + "github.com/ipfs/go-libipfs/unixfs/node/file" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" diff --git a/unixfs/node/file/shard.go b/unixfs/node/file/shard.go index 0f08d140d..d159ed674 100644 --- a/unixfs/node/file/shard.go +++ b/unixfs/node/file/shard.go @@ -6,7 +6,7 @@ import ( "sync" "github.com/ipfs/go-cid" - "github.com/ipfs/go-unixfsnode/data" + "github.com/ipfs/go-libipfs/unixfs/node/data" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" diff --git a/unixfs/node/file/wrapped.go b/unixfs/node/file/wrapped.go index b2c2210c9..b744cafc7 100644 --- a/unixfs/node/file/wrapped.go +++ b/unixfs/node/file/wrapped.go @@ -1,7 +1,7 @@ package file import ( - "github.com/ipfs/go-unixfsnode/data" + "github.com/ipfs/go-libipfs/unixfs/node/data" "github.com/ipld/go-ipld-prime" "github.com/ipld/go-ipld-prime/node/basicnode" ) diff --git a/unixfs/node/hamt/shardeddir.go b/unixfs/node/hamt/shardeddir.go index 97a833ff0..7fc4b1ed1 100644 --- a/unixfs/node/hamt/shardeddir.go +++ b/unixfs/node/hamt/shardeddir.go @@ -5,8 +5,8 @@ import ( "fmt" bitfield "github.com/ipfs/go-bitfield" - "github.com/ipfs/go-unixfsnode/data" - "github.com/ipfs/go-unixfsnode/iter" + "github.com/ipfs/go-libipfs/unixfs/node/data" + "github.com/ipfs/go-libipfs/unixfs/node/iter" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" "github.com/ipld/go-ipld-prime/schema" diff --git a/unixfs/node/hamt/shardeddir_test.go b/unixfs/node/hamt/shardeddir_test.go index 4b76be249..07b99095e 100644 --- a/unixfs/node/hamt/shardeddir_test.go +++ b/unixfs/node/hamt/shardeddir_test.go @@ -11,11 +11,11 @@ import ( "time" format "github.com/ipfs/go-ipld-format" + "github.com/ipfs/go-libipfs/unixfs/node/hamt" dag "github.com/ipfs/go-merkledag" mdtest "github.com/ipfs/go-merkledag/test" ft "github.com/ipfs/go-unixfs" legacy "github.com/ipfs/go-unixfs/hamt" - "github.com/ipfs/go-unixfsnode/hamt" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" "github.com/ipld/go-ipld-prime/fluent/qp" diff --git a/unixfs/node/hamt/util.go b/unixfs/node/hamt/util.go index bd72382c3..bf615ced8 100644 --- a/unixfs/node/hamt/util.go +++ b/unixfs/node/hamt/util.go @@ -8,7 +8,7 @@ import ( "math/bits" bitfield "github.com/ipfs/go-bitfield" - "github.com/ipfs/go-unixfsnode/data" + "github.com/ipfs/go-libipfs/unixfs/node/data" dagpb "github.com/ipld/go-codec-dagpb" "github.com/spaolacci/murmur3" ) diff --git a/unixfs/node/pathpbnode.go b/unixfs/node/pathpbnode.go index 2dc2b088b..b24f878ee 100644 --- a/unixfs/node/pathpbnode.go +++ b/unixfs/node/pathpbnode.go @@ -1,8 +1,8 @@ package unixfsnode import ( - "github.com/ipfs/go-unixfsnode/iter" - "github.com/ipfs/go-unixfsnode/utils" + "github.com/ipfs/go-libipfs/unixfs/node/iter" + "github.com/ipfs/go-libipfs/unixfs/node/utils" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" "github.com/ipld/go-ipld-prime/schema" diff --git a/unixfs/node/reification.go b/unixfs/node/reification.go index dd293c1d7..a9885d45e 100644 --- a/unixfs/node/reification.go +++ b/unixfs/node/reification.go @@ -4,10 +4,10 @@ import ( "context" "fmt" - "github.com/ipfs/go-unixfsnode/data" - "github.com/ipfs/go-unixfsnode/directory" - "github.com/ipfs/go-unixfsnode/file" - "github.com/ipfs/go-unixfsnode/hamt" + "github.com/ipfs/go-libipfs/unixfs/node/data" + "github.com/ipfs/go-libipfs/unixfs/node/directory" + "github.com/ipfs/go-libipfs/unixfs/node/file" + "github.com/ipfs/go-libipfs/unixfs/node/hamt" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" ) diff --git a/unixfs/node/test/partial_file_access_test.go b/unixfs/node/test/partial_file_access_test.go index fffe74f58..27ed963e2 100644 --- a/unixfs/node/test/partial_file_access_test.go +++ b/unixfs/node/test/partial_file_access_test.go @@ -7,8 +7,8 @@ import ( "testing" u "github.com/ipfs/go-ipfs-util" - "github.com/ipfs/go-unixfsnode/data/builder" - "github.com/ipfs/go-unixfsnode/file" + "github.com/ipfs/go-libipfs/unixfs/node/data/builder" + "github.com/ipfs/go-libipfs/unixfs/node/file" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" "github.com/ipld/go-ipld-prime/datamodel"