diff --git a/go.mod b/go.mod index 1649a482f8..7f40a640fe 100644 --- a/go.mod +++ b/go.mod @@ -6,84 +6,48 @@ 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/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/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-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 + 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/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-openssl v0.1.0 // indirect - github.com/mattn/go-isatty v0.0.17 // indirect + github.com/mattn/go-isatty v0.0.16 // 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-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/multiformats/go-multicodec v0.6.0 // indirect + github.com/multiformats/go-varint v0.0.6 // 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-20201211092308-30ac6d18308e // indirect + github.com/polydawn/refmt v0.0.0-20190807091052-3d65705ee9f1 // 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 30b80e416f..ab57d0a126 100644 --- a/go.sum +++ b/go.sum @@ -8,7 +8,6 @@ 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= @@ -20,13 +19,6 @@ 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= @@ -42,7 +34,6 @@ 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= @@ -50,149 +41,50 @@ 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.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/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= 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/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/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/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.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/klauspost/cpuid/v2 v2.1.1 h1:t0wUqjowdm8ezddV5k0tLWVklVuvLJpoHeb4WBdydm0= +github.com/klauspost/cpuid/v2 v2.1.1/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= 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.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= -github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +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-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= @@ -208,49 +100,33 @@ 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-20190221155625-df39d6c2d992/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o= +github.com/polydawn/refmt v0.0.0-20190807091052-3d65705ee9f1 h1:CskT+S6Ay54OwxBGB0R3Rsx4Muto6UnEYTyKJbyRIAI= 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= @@ -262,7 +138,6 @@ 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= @@ -270,45 +145,25 @@ 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= @@ -322,15 +177,12 @@ 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= @@ -338,7 +190,6 @@ 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= @@ -346,12 +197,8 @@ 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= @@ -367,27 +214,20 @@ 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= @@ -407,23 +247,15 @@ 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= diff --git a/unixfs/node/README.md b/unixfs/node/README.md deleted file mode 100644 index f55a1b5a90..0000000000 --- a/unixfs/node/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# 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) - -## 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 diff --git a/unixfs/node/data/builder/builder.go b/unixfs/node/data/builder/builder.go deleted file mode 100644 index 3637b3a927..0000000000 --- a/unixfs/node/data/builder/builder.go +++ /dev/null @@ -1,142 +0,0 @@ -package builder - -import ( - "errors" - "strconv" - "time" - - "github.com/ipfs/go-libipfs/unixfs/node/data" - "github.com/ipld/go-ipld-prime" - "github.com/ipld/go-ipld-prime/fluent/qp" -) - -// 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) - if !b.hasBlockSizes { - qp.MapEntry(ma, data.Field__BlockSizes, qp.List(0, func(ipld.ListAssembler) {})) - } - if !b.hasDataType { - qp.MapEntry(ma, data.Field__DataType, qp.Int(data.Data_File)) - } - }) - if err != nil { - return nil, err - } - 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(data.ErrInvalidDataType{DataType: 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, 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, 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, data.Field__BlockSizes, qp.List(int64(len(blockSizes)), func(la ipld.ListAssembler) { - for _, bs := range blockSizes { - qp.ListEntry(la, qp.Int(int64(bs))) - } - })) - b.hasBlockSizes = true -} - -// 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, 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, data.Field__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) -} - -// 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 { - panic(err) - } - mode64 = mode64 & 0xFFF - 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, data.Field__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, data.Field__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]")) - } - qp.MapEntry(ma, data.Field__Nanoseconds, qp.Int(int64(nanoseconds))) -} diff --git a/unixfs/node/data/builder/dir_test.go b/unixfs/node/data/builder/dir_test.go deleted file mode 100644 index 901b9e1604..0000000000 --- a/unixfs/node/data/builder/dir_test.go +++ /dev/null @@ -1,197 +0,0 @@ -package builder - -import ( - "bytes" - "fmt" - "os" - "path/filepath" - "testing" - - "github.com/ipfs/go-cid" - 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" - "github.com/stretchr/testify/require" -) - -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) - } - } -} - -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, fixture.expectedLnk.String(), lnk.String()) - require.Equal(t, uint64(245), sz) -} - -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("bafybeigyvxs6og5jbmpaa43qbhhd5swklqcfzqdrtjgfh53qjon6hpjaye"), - make([]fentry, 0), - } - - 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}) - } - - 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(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 { - 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 deleted file mode 100644 index 15b2006240..0000000000 --- a/unixfs/node/data/builder/directory.go +++ /dev/null @@ -1,147 +0,0 @@ -package builder - -import ( - "fmt" - "io/fs" - "os" - "path" - - "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" - "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(): - var tsize uint64 - 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 - } - tsize += sz - entry, err := BuildUnixFSDirectoryEntry(e.Name(), int64(sz), lnk) - if err != nil { - return nil, 0, err - } - lnks = append(lnks, entry) - } - return BuildUnixFSDirectory(lnks, ls) - case m.Type() == fs.ModeSymlink: - content, err := os.Readlink(root) - if err != nil { - return nil, 0, err - } - 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() - 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) - } -} - -// 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 if lnk == nil { - s += 0 - } 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, uint64, error) { - if estimateDirSize(entries) > shardSplitThreshold { - return BuildUnixFSShardedDirectory(defaultShardWidth, multihash.MURMUR3X64_64, entries, ls) - } - ufd, err := BuildUnixFS(func(b *Builder) { - DataType(b, data.Data_Directory) - }) - if err != nil { - return nil, 0, err - } - pbb := dagpb.Type.PBNode.NewBuilder() - pbm, err := pbb.BeginMap(2) - if 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(ufd)); err != nil { - return nil, 0, err - } - if err = pbm.AssembleKey().AssignString("Links"); err != nil { - return nil, 0, err - } - lnks, err := pbm.AssembleValue().BeginList(int64(len(entries))) - if err != nil { - 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 - } - } - if err := lnks.Finish(); err != nil { - return nil, 0, err - } - if err := pbm.Finish(); err != nil { - return nil, 0, err - } - node := pbb.Build() - 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 deleted file mode 100644 index 4ced270463..0000000000 --- a/unixfs/node/data/builder/dirshard.go +++ /dev/null @@ -1,219 +0,0 @@ -package builder - -import ( - "fmt" - "hash" - - bitfield "github.com/ipfs/go-bitfield" - "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" - "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, uint64, 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, 0, err - } - } - hamtEntries := make([]hamtLink, 0, len(entries)) - for _, e := range entries { - name := e.Name.Must().String() - h.Reset() - h.Write([]byte(name)) - sum := h.Sum(nil) - hamtEntries = append(hamtEntries, hamtLink{ - sum, - e, - }) - } - - sizeLg2, err := logtwo(size) - if err != nil { - return nil, 0, 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, 0, 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 { - // 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 - 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, - } - // 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("%0*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, uint64, 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, 0, err - } - pbb := dagpb.Type.PBNode.NewBuilder() - pbm, err := pbb.BeginMap(2) - if 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(ufd)); err != nil { - return nil, 0, err - } - if err = pbm.AssembleKey().AssignString("Links"); err != nil { - return nil, 0, err - } - - lnkBuilder := dagpb.Type.PBLinks.NewBuilder() - lnks, err := lnkBuilder.BeginList(int64(len(s.children))) - if err != nil { - 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 { - ipldLnk, sz, err := e.shard.serialize(ls) - if err != nil { - return nil, 0, err - } - totalSize += sz - fullName := s.formatLinkName("", idx) - lnk, err = BuildUnixFSDirectoryEntry(fullName, int64(sz), ipldLnk) - if err != nil { - return nil, 0, err - } - } else { - fullName := s.formatLinkName(e.Name.Must().String(), idx) - sz := e.Tsize.Must().Int() - totalSize += uint64(sz) - lnk, err = BuildUnixFSDirectoryEntry(fullName, sz, e.Hash.Link()) - } - if err != nil { - return nil, 0, err - } - if err := lnks.AssembleValue().AssignNode(lnk); err != nil { - return nil, 0, err - } - } - if err := lnks.Finish(); err != nil { - return nil, 0, err - } - pbm.AssembleValue().AssignNode(lnkBuilder.Build()) - if err := pbm.Finish(); err != nil { - return nil, 0, err - } - node := pbb.Build() - lnk, sz, err := sizedStore(ls, fileLinkProto, node) - if err != nil { - return nil, 0, err - } - return lnk, totalSize + sz, nil -} diff --git a/unixfs/node/data/builder/file.go b/unixfs/node/data/builder/file.go deleted file mode 100644 index d13891bb55..0000000000 --- a/unixfs/node/data/builder/file.go +++ /dev/null @@ -1,272 +0,0 @@ -package builder - -import ( - "fmt" - "io" - - "github.com/ipfs/go-cid" - chunk "github.com/ipfs/go-ipfs-chunker" - "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" - 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 { - if root == nil { - node := basicnode.NewBytes([]byte{}) - link, err := ls.Store(ipld.LinkContext{}, leafLinkProto, node) - return link, 0, err - } - 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) - return sizedStore(ls, leafLinkProto, node) - } - // 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) - childLen = append(childLen, sz) - 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 := sizedStore(ls, fileLinkProto, pbn) - if err != nil { - return nil, 0, err - } - return link, totalSize, 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() - - return sizedStore(ls, fileLinkProto, pbn) -} - -// 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 deleted file mode 100644 index f6719033b8..0000000000 --- a/unixfs/node/data/builder/file_test.go +++ /dev/null @@ -1,79 +0,0 @@ -package builder - -import ( - "bytes" - "context" - "testing" - - "github.com/ipfs/go-cid" - u "github.com/ipfs/go-ipfs-util" - "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" -) - -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.") - } -} - -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 := ufn.AsBytes() - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(out, buf) { - t.Fatal("Not equal") - } -} diff --git a/unixfs/node/data/builder/quick/quick.go b/unixfs/node/data/builder/quick/quick.go deleted file mode 100644 index ac1f65d714..0000000000 --- a/unixfs/node/data/builder/quick/quick.go +++ /dev/null @@ -1,77 +0,0 @@ -// 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-libipfs/unixfs/node/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 deleted file mode 100644 index 440caa6d40..0000000000 --- a/unixfs/node/data/builder/quick/quick_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package quickbuilder_test - -import ( - "testing" - - 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" -) - -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") - } -} diff --git a/unixfs/node/data/builder/util.go b/unixfs/node/data/builder/util.go deleted file mode 100644 index 808a5ff598..0000000000 --- a/unixfs/node/data/builder/util.go +++ /dev/null @@ -1,109 +0,0 @@ -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 - -// 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<= 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{TypeName: "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{TypeName: "data.BlockSizes"}.AsBool() -} -func (BlockSizes) AsInt() (int64, error) { - return mixins.List{TypeName: "data.BlockSizes"}.AsInt() -} -func (BlockSizes) AsFloat() (float64, error) { - return mixins.List{TypeName: "data.BlockSizes"}.AsFloat() -} -func (BlockSizes) AsString() (string, error) { - return mixins.List{TypeName: "data.BlockSizes"}.AsString() -} -func (BlockSizes) AsBytes() ([]byte, error) { - return mixins.List{TypeName: "data.BlockSizes"}.AsBytes() -} -func (BlockSizes) AsLink() (ipld.Link, error) { - 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 { - 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{TypeName: "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 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{TypeName: "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{TypeName: "data.BlockSizes"}.AssignBool(false) -} -func (_BlockSizes__Assembler) AssignInt(int64) error { - return mixins.ListAssembler{TypeName: "data.BlockSizes"}.AssignInt(0) -} -func (_BlockSizes__Assembler) AssignFloat(float64) error { - return mixins.ListAssembler{TypeName: "data.BlockSizes"}.AssignFloat(0) -} -func (_BlockSizes__Assembler) AssignString(string) error { - return mixins.ListAssembler{TypeName: "data.BlockSizes"}.AssignString("") -} -func (_BlockSizes__Assembler) AssignBytes([]byte) error { - return mixins.ListAssembler{TypeName: "data.BlockSizes"}.AssignBytes(nil) -} -func (_BlockSizes__Assembler) AssignLink(ipld.Link) error { - return mixins.ListAssembler{TypeName: "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!") - } - *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{TypeName: "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{TypeName: "data.BlockSizes.Repr"}.AsBool() -} -func (_BlockSizes__Repr) AsInt() (int64, error) { - return mixins.List{TypeName: "data.BlockSizes.Repr"}.AsInt() -} -func (_BlockSizes__Repr) AsFloat() (float64, error) { - return mixins.List{TypeName: "data.BlockSizes.Repr"}.AsFloat() -} -func (_BlockSizes__Repr) AsString() (string, error) { - return mixins.List{TypeName: "data.BlockSizes.Repr"}.AsString() -} -func (_BlockSizes__Repr) AsBytes() ([]byte, error) { - return mixins.List{TypeName: "data.BlockSizes.Repr"}.AsBytes() -} -func (_BlockSizes__Repr) AsLink() (ipld.Link, error) { - 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 { - 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{TypeName: "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 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{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: - 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{TypeName: "data.BlockSizes.Repr"}.AssignBool(false) -} -func (_BlockSizes__ReprAssembler) AssignInt(int64) error { - return mixins.ListAssembler{TypeName: "data.BlockSizes.Repr"}.AssignInt(0) -} -func (_BlockSizes__ReprAssembler) AssignFloat(float64) error { - return mixins.ListAssembler{TypeName: "data.BlockSizes.Repr"}.AssignFloat(0) -} -func (_BlockSizes__ReprAssembler) AssignString(string) error { - return mixins.ListAssembler{TypeName: "data.BlockSizes.Repr"}.AssignString("") -} -func (_BlockSizes__ReprAssembler) AssignBytes([]byte) error { - return mixins.ListAssembler{TypeName: "data.BlockSizes.Repr"}.AssignBytes(nil) -} -func (_BlockSizes__ReprAssembler) AssignLink(ipld.Link) error { - return mixins.ListAssembler{TypeName: "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!") - } - *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{TypeName: "data.Bytes"}.LookupByString("") -} -func (Bytes) LookupByNode(ipld.Node) (ipld.Node, error) { - return mixins.Bytes{TypeName: "data.Bytes"}.LookupByNode(nil) -} -func (Bytes) LookupByIndex(idx int64) (ipld.Node, error) { - return mixins.Bytes{TypeName: "data.Bytes"}.LookupByIndex(0) -} -func (Bytes) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { - return mixins.Bytes{TypeName: "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{TypeName: "data.Bytes"}.AsBool() -} -func (Bytes) AsInt() (int64, error) { - return mixins.Bytes{TypeName: "data.Bytes"}.AsInt() -} -func (Bytes) AsFloat() (float64, error) { - return mixins.Bytes{TypeName: "data.Bytes"}.AsFloat() -} -func (Bytes) AsString() (string, error) { - 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{TypeName: "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{TypeName: "data.Bytes"}.BeginMap(0) -} -func (_Bytes__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.BytesAssembler{TypeName: "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{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{TypeName: "data.Bytes"}.AssignBool(false) -} -func (_Bytes__Assembler) AssignInt(int64) error { - return mixins.BytesAssembler{TypeName: "data.Bytes"}.AssignInt(0) -} -func (_Bytes__Assembler) AssignFloat(float64) error { - return mixins.BytesAssembler{TypeName: "data.Bytes"}.AssignFloat(0) -} -func (_Bytes__Assembler) AssignString(string) error { - 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") - } - na.w.x = v - *na.m = schema.Maybe_Value - return nil -} -func (_Bytes__Assembler) AssignLink(ipld.Link) error { - return mixins.BytesAssembler{TypeName: "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") - } - *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{TypeName: "data.Int"}.LookupByString("") -} -func (Int) LookupByNode(ipld.Node) (ipld.Node, error) { - return mixins.Int{TypeName: "data.Int"}.LookupByNode(nil) -} -func (Int) LookupByIndex(idx int64) (ipld.Node, error) { - return mixins.Int{TypeName: "data.Int"}.LookupByIndex(0) -} -func (Int) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { - return mixins.Int{TypeName: "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{TypeName: "data.Int"}.AsBool() -} -func (n Int) AsInt() (int64, error) { - return n.x, nil -} -func (Int) AsFloat() (float64, error) { - return mixins.Int{TypeName: "data.Int"}.AsFloat() -} -func (Int) AsString() (string, error) { - return mixins.Int{TypeName: "data.Int"}.AsString() -} -func (Int) AsBytes() ([]byte, error) { - return mixins.Int{TypeName: "data.Int"}.AsBytes() -} -func (Int) AsLink() (ipld.Link, error) { - 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 { - 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{TypeName: "data.Int"}.BeginMap(0) -} -func (_Int__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.IntAssembler{TypeName: "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{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{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") - } - na.w.x = v - *na.m = schema.Maybe_Value - return nil -} -func (_Int__Assembler) AssignFloat(float64) error { - return mixins.IntAssembler{TypeName: "data.Int"}.AssignFloat(0) -} -func (_Int__Assembler) AssignString(string) error { - return mixins.IntAssembler{TypeName: "data.Int"}.AssignString("") -} -func (_Int__Assembler) AssignBytes([]byte) error { - return mixins.IntAssembler{TypeName: "data.Int"}.AssignBytes(nil) -} -func (_Int__Assembler) AssignLink(ipld.Link) error { - return mixins.IntAssembler{TypeName: "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") - } - *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{TypeName: "data.String"}.LookupByString("") -} -func (String) LookupByNode(ipld.Node) (ipld.Node, error) { - return mixins.String{TypeName: "data.String"}.LookupByNode(nil) -} -func (String) LookupByIndex(idx int64) (ipld.Node, error) { - return mixins.String{TypeName: "data.String"}.LookupByIndex(0) -} -func (String) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { - return mixins.String{TypeName: "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{TypeName: "data.String"}.AsBool() -} -func (String) AsInt() (int64, error) { - return mixins.String{TypeName: "data.String"}.AsInt() -} -func (String) AsFloat() (float64, error) { - 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{TypeName: "data.String"}.AsBytes() -} -func (String) AsLink() (ipld.Link, error) { - 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 { - 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{TypeName: "data.String"}.BeginMap(0) -} -func (_String__Assembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.StringAssembler{TypeName: "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{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{TypeName: "data.String"}.AssignBool(false) -} -func (_String__Assembler) AssignInt(int64) error { - return mixins.StringAssembler{TypeName: "data.String"}.AssignInt(0) -} -func (_String__Assembler) AssignFloat(float64) error { - 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") - } - na.w.x = v - *na.m = schema.Maybe_Value - return nil -} -func (_String__Assembler) AssignBytes([]byte) error { - return mixins.StringAssembler{TypeName: "data.String"}.AssignBytes(nil) -} -func (_String__Assembler) AssignLink(ipld.Link) error { - return mixins.StringAssembler{TypeName: "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") - } - *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{TypeName: "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{TypeName: "data.UnixFSData"}.AsBool() -} -func (UnixFSData) AsInt() (int64, error) { - return mixins.Map{TypeName: "data.UnixFSData"}.AsInt() -} -func (UnixFSData) AsFloat() (float64, error) { - return mixins.Map{TypeName: "data.UnixFSData"}.AsFloat() -} -func (UnixFSData) AsString() (string, error) { - return mixins.Map{TypeName: "data.UnixFSData"}.AsString() -} -func (UnixFSData) AsBytes() ([]byte, error) { - return mixins.Map{TypeName: "data.UnixFSData"}.AsBytes() -} -func (UnixFSData) AsLink() (ipld.Link, error) { - 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 { - 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{TypeName: "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{TypeName: "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{TypeName: "data.UnixFSData"}.AssignBool(false) -} -func (_UnixFSData__Assembler) AssignInt(int64) error { - return mixins.MapAssembler{TypeName: "data.UnixFSData"}.AssignInt(0) -} -func (_UnixFSData__Assembler) AssignFloat(float64) error { - return mixins.MapAssembler{TypeName: "data.UnixFSData"}.AssignFloat(0) -} -func (_UnixFSData__Assembler) AssignString(string) error { - return mixins.MapAssembler{TypeName: "data.UnixFSData"}.AssignString("") -} -func (_UnixFSData__Assembler) AssignBytes([]byte) error { - return mixins.MapAssembler{TypeName: "data.UnixFSData"}.AssignBytes(nil) -} -func (_UnixFSData__Assembler) AssignLink(ipld.Link) error { - return mixins.MapAssembler{TypeName: "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.state = maState_initial - return true - default: - return false - } - case 2: - switch ma.w.FileSize.m { - case schema.Maybe_Value: - 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.state = maState_initial - return true - default: - return false - } - case 5: - switch ma.w.Fanout.m { - case schema.Maybe_Value: - ma.state = maState_initial - return true - default: - return false - } - case 6: - switch ma.w.Mode.m { - case schema.Maybe_Value: - 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{TypeName: "data.UnixFSData.KeyAssembler"}.BeginMap(0) -} -func (_UnixFSData__KeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.StringAssembler{TypeName: "data.UnixFSData.KeyAssembler"}.BeginList(0) -} -func (na *_UnixFSData__KeyAssembler) AssignNull() error { - return mixins.StringAssembler{TypeName: "data.UnixFSData.KeyAssembler"}.AssignNull() -} -func (_UnixFSData__KeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{TypeName: "data.UnixFSData.KeyAssembler"}.AssignBool(false) -} -func (_UnixFSData__KeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{TypeName: "data.UnixFSData.KeyAssembler"}.AssignInt(0) -} -func (_UnixFSData__KeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{TypeName: "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{TypeName: "data.UnixFSData.KeyAssembler"}.AssignBytes(nil) -} -func (_UnixFSData__KeyAssembler) AssignLink(ipld.Link) error { - 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 { - 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{TypeName: "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{TypeName: "data.UnixFSData.Repr"}.AsBool() -} -func (_UnixFSData__Repr) AsInt() (int64, error) { - return mixins.Map{TypeName: "data.UnixFSData.Repr"}.AsInt() -} -func (_UnixFSData__Repr) AsFloat() (float64, error) { - return mixins.Map{TypeName: "data.UnixFSData.Repr"}.AsFloat() -} -func (_UnixFSData__Repr) AsString() (string, error) { - return mixins.Map{TypeName: "data.UnixFSData.Repr"}.AsString() -} -func (_UnixFSData__Repr) AsBytes() ([]byte, error) { - return mixins.Map{TypeName: "data.UnixFSData.Repr"}.AsBytes() -} -func (_UnixFSData__Repr) AsLink() (ipld.Link, error) { - 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 { - 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{TypeName: "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{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: - 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{TypeName: "data.UnixFSData.Repr"}.AssignBool(false) -} -func (_UnixFSData__ReprAssembler) AssignInt(int64) error { - return mixins.MapAssembler{TypeName: "data.UnixFSData.Repr"}.AssignInt(0) -} -func (_UnixFSData__ReprAssembler) AssignFloat(float64) error { - return mixins.MapAssembler{TypeName: "data.UnixFSData.Repr"}.AssignFloat(0) -} -func (_UnixFSData__ReprAssembler) AssignString(string) error { - return mixins.MapAssembler{TypeName: "data.UnixFSData.Repr"}.AssignString("") -} -func (_UnixFSData__ReprAssembler) AssignBytes([]byte) error { - return mixins.MapAssembler{TypeName: "data.UnixFSData.Repr"}.AssignBytes(nil) -} -func (_UnixFSData__ReprAssembler) AssignLink(ipld.Link) error { - return mixins.MapAssembler{TypeName: "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.state = maState_initial - return true - default: - return false - } - case 2: - switch ma.w.FileSize.m { - case schema.Maybe_Value: - 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.state = maState_initial - return true - default: - return false - } - case 5: - switch ma.w.Fanout.m { - case schema.Maybe_Value: - ma.state = maState_initial - return true - default: - return false - } - case 6: - switch ma.w.Mode.m { - case schema.Maybe_Value: - 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{TypeName: "data.UnixFSData.Repr.KeyAssembler"}.BeginMap(0) -} -func (_UnixFSData__ReprKeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.StringAssembler{TypeName: "data.UnixFSData.Repr.KeyAssembler"}.BeginList(0) -} -func (na *_UnixFSData__ReprKeyAssembler) AssignNull() error { - return mixins.StringAssembler{TypeName: "data.UnixFSData.Repr.KeyAssembler"}.AssignNull() -} -func (_UnixFSData__ReprKeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{TypeName: "data.UnixFSData.Repr.KeyAssembler"}.AssignBool(false) -} -func (_UnixFSData__ReprKeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{TypeName: "data.UnixFSData.Repr.KeyAssembler"}.AssignInt(0) -} -func (_UnixFSData__ReprKeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{TypeName: "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{TypeName: "data.UnixFSData.Repr.KeyAssembler"}.AssignBytes(nil) -} -func (_UnixFSData__ReprKeyAssembler) AssignLink(ipld.Link) error { - 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 { - 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{TypeName: "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{TypeName: "data.UnixFSMetadata"}.AsBool() -} -func (UnixFSMetadata) AsInt() (int64, error) { - return mixins.Map{TypeName: "data.UnixFSMetadata"}.AsInt() -} -func (UnixFSMetadata) AsFloat() (float64, error) { - return mixins.Map{TypeName: "data.UnixFSMetadata"}.AsFloat() -} -func (UnixFSMetadata) AsString() (string, error) { - return mixins.Map{TypeName: "data.UnixFSMetadata"}.AsString() -} -func (UnixFSMetadata) AsBytes() ([]byte, error) { - return mixins.Map{TypeName: "data.UnixFSMetadata"}.AsBytes() -} -func (UnixFSMetadata) AsLink() (ipld.Link, error) { - 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 { - 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{TypeName: "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{TypeName: "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{TypeName: "data.UnixFSMetadata"}.AssignBool(false) -} -func (_UnixFSMetadata__Assembler) AssignInt(int64) error { - return mixins.MapAssembler{TypeName: "data.UnixFSMetadata"}.AssignInt(0) -} -func (_UnixFSMetadata__Assembler) AssignFloat(float64) error { - return mixins.MapAssembler{TypeName: "data.UnixFSMetadata"}.AssignFloat(0) -} -func (_UnixFSMetadata__Assembler) AssignString(string) error { - return mixins.MapAssembler{TypeName: "data.UnixFSMetadata"}.AssignString("") -} -func (_UnixFSMetadata__Assembler) AssignBytes([]byte) error { - return mixins.MapAssembler{TypeName: "data.UnixFSMetadata"}.AssignBytes(nil) -} -func (_UnixFSMetadata__Assembler) AssignLink(ipld.Link) error { - return mixins.MapAssembler{TypeName: "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.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{TypeName: "data.UnixFSMetadata.KeyAssembler"}.BeginMap(0) -} -func (_UnixFSMetadata__KeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.KeyAssembler"}.BeginList(0) -} -func (na *_UnixFSMetadata__KeyAssembler) AssignNull() error { - return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.KeyAssembler"}.AssignNull() -} -func (_UnixFSMetadata__KeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.KeyAssembler"}.AssignBool(false) -} -func (_UnixFSMetadata__KeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.KeyAssembler"}.AssignInt(0) -} -func (_UnixFSMetadata__KeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{TypeName: "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{TypeName: "data.UnixFSMetadata.KeyAssembler"}.AssignBytes(nil) -} -func (_UnixFSMetadata__KeyAssembler) AssignLink(ipld.Link) error { - 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 { - 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{TypeName: "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{TypeName: "data.UnixFSMetadata.Repr"}.AsBool() -} -func (_UnixFSMetadata__Repr) AsInt() (int64, error) { - return mixins.Map{TypeName: "data.UnixFSMetadata.Repr"}.AsInt() -} -func (_UnixFSMetadata__Repr) AsFloat() (float64, error) { - return mixins.Map{TypeName: "data.UnixFSMetadata.Repr"}.AsFloat() -} -func (_UnixFSMetadata__Repr) AsString() (string, error) { - return mixins.Map{TypeName: "data.UnixFSMetadata.Repr"}.AsString() -} -func (_UnixFSMetadata__Repr) AsBytes() ([]byte, error) { - return mixins.Map{TypeName: "data.UnixFSMetadata.Repr"}.AsBytes() -} -func (_UnixFSMetadata__Repr) AsLink() (ipld.Link, error) { - 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 { - 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{TypeName: "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{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: - 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{TypeName: "data.UnixFSMetadata.Repr"}.AssignBool(false) -} -func (_UnixFSMetadata__ReprAssembler) AssignInt(int64) error { - return mixins.MapAssembler{TypeName: "data.UnixFSMetadata.Repr"}.AssignInt(0) -} -func (_UnixFSMetadata__ReprAssembler) AssignFloat(float64) error { - return mixins.MapAssembler{TypeName: "data.UnixFSMetadata.Repr"}.AssignFloat(0) -} -func (_UnixFSMetadata__ReprAssembler) AssignString(string) error { - return mixins.MapAssembler{TypeName: "data.UnixFSMetadata.Repr"}.AssignString("") -} -func (_UnixFSMetadata__ReprAssembler) AssignBytes([]byte) error { - return mixins.MapAssembler{TypeName: "data.UnixFSMetadata.Repr"}.AssignBytes(nil) -} -func (_UnixFSMetadata__ReprAssembler) AssignLink(ipld.Link) error { - return mixins.MapAssembler{TypeName: "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.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{TypeName: "data.UnixFSMetadata.Repr.KeyAssembler"}.BeginMap(0) -} -func (_UnixFSMetadata__ReprKeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.Repr.KeyAssembler"}.BeginList(0) -} -func (na *_UnixFSMetadata__ReprKeyAssembler) AssignNull() error { - return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.Repr.KeyAssembler"}.AssignNull() -} -func (_UnixFSMetadata__ReprKeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.Repr.KeyAssembler"}.AssignBool(false) -} -func (_UnixFSMetadata__ReprKeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{TypeName: "data.UnixFSMetadata.Repr.KeyAssembler"}.AssignInt(0) -} -func (_UnixFSMetadata__ReprKeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{TypeName: "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{TypeName: "data.UnixFSMetadata.Repr.KeyAssembler"}.AssignBytes(nil) -} -func (_UnixFSMetadata__ReprKeyAssembler) AssignLink(ipld.Link) error { - 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 { - 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{TypeName: "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{TypeName: "data.UnixTime"}.AsBool() -} -func (UnixTime) AsInt() (int64, error) { - return mixins.Map{TypeName: "data.UnixTime"}.AsInt() -} -func (UnixTime) AsFloat() (float64, error) { - return mixins.Map{TypeName: "data.UnixTime"}.AsFloat() -} -func (UnixTime) AsString() (string, error) { - return mixins.Map{TypeName: "data.UnixTime"}.AsString() -} -func (UnixTime) AsBytes() ([]byte, error) { - return mixins.Map{TypeName: "data.UnixTime"}.AsBytes() -} -func (UnixTime) AsLink() (ipld.Link, error) { - 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 { - 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{TypeName: "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{TypeName: "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{TypeName: "data.UnixTime"}.AssignBool(false) -} -func (_UnixTime__Assembler) AssignInt(int64) error { - return mixins.MapAssembler{TypeName: "data.UnixTime"}.AssignInt(0) -} -func (_UnixTime__Assembler) AssignFloat(float64) error { - return mixins.MapAssembler{TypeName: "data.UnixTime"}.AssignFloat(0) -} -func (_UnixTime__Assembler) AssignString(string) error { - return mixins.MapAssembler{TypeName: "data.UnixTime"}.AssignString("") -} -func (_UnixTime__Assembler) AssignBytes([]byte) error { - return mixins.MapAssembler{TypeName: "data.UnixTime"}.AssignBytes(nil) -} -func (_UnixTime__Assembler) AssignLink(ipld.Link) error { - return mixins.MapAssembler{TypeName: "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.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{TypeName: "data.UnixTime.KeyAssembler"}.BeginMap(0) -} -func (_UnixTime__KeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.StringAssembler{TypeName: "data.UnixTime.KeyAssembler"}.BeginList(0) -} -func (na *_UnixTime__KeyAssembler) AssignNull() error { - return mixins.StringAssembler{TypeName: "data.UnixTime.KeyAssembler"}.AssignNull() -} -func (_UnixTime__KeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{TypeName: "data.UnixTime.KeyAssembler"}.AssignBool(false) -} -func (_UnixTime__KeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{TypeName: "data.UnixTime.KeyAssembler"}.AssignInt(0) -} -func (_UnixTime__KeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{TypeName: "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{TypeName: "data.UnixTime.KeyAssembler"}.AssignBytes(nil) -} -func (_UnixTime__KeyAssembler) AssignLink(ipld.Link) error { - 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 { - 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{TypeName: "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{TypeName: "data.UnixTime.Repr"}.AsBool() -} -func (_UnixTime__Repr) AsInt() (int64, error) { - return mixins.Map{TypeName: "data.UnixTime.Repr"}.AsInt() -} -func (_UnixTime__Repr) AsFloat() (float64, error) { - return mixins.Map{TypeName: "data.UnixTime.Repr"}.AsFloat() -} -func (_UnixTime__Repr) AsString() (string, error) { - return mixins.Map{TypeName: "data.UnixTime.Repr"}.AsString() -} -func (_UnixTime__Repr) AsBytes() ([]byte, error) { - return mixins.Map{TypeName: "data.UnixTime.Repr"}.AsBytes() -} -func (_UnixTime__Repr) AsLink() (ipld.Link, error) { - 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 { - 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{TypeName: "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{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: - 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{TypeName: "data.UnixTime.Repr"}.AssignBool(false) -} -func (_UnixTime__ReprAssembler) AssignInt(int64) error { - return mixins.MapAssembler{TypeName: "data.UnixTime.Repr"}.AssignInt(0) -} -func (_UnixTime__ReprAssembler) AssignFloat(float64) error { - return mixins.MapAssembler{TypeName: "data.UnixTime.Repr"}.AssignFloat(0) -} -func (_UnixTime__ReprAssembler) AssignString(string) error { - return mixins.MapAssembler{TypeName: "data.UnixTime.Repr"}.AssignString("") -} -func (_UnixTime__ReprAssembler) AssignBytes([]byte) error { - return mixins.MapAssembler{TypeName: "data.UnixTime.Repr"}.AssignBytes(nil) -} -func (_UnixTime__ReprAssembler) AssignLink(ipld.Link) error { - return mixins.MapAssembler{TypeName: "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.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{TypeName: "data.UnixTime.Repr.KeyAssembler"}.BeginMap(0) -} -func (_UnixTime__ReprKeyAssembler) BeginList(sizeHint int64) (ipld.ListAssembler, error) { - return mixins.StringAssembler{TypeName: "data.UnixTime.Repr.KeyAssembler"}.BeginList(0) -} -func (na *_UnixTime__ReprKeyAssembler) AssignNull() error { - return mixins.StringAssembler{TypeName: "data.UnixTime.Repr.KeyAssembler"}.AssignNull() -} -func (_UnixTime__ReprKeyAssembler) AssignBool(bool) error { - return mixins.StringAssembler{TypeName: "data.UnixTime.Repr.KeyAssembler"}.AssignBool(false) -} -func (_UnixTime__ReprKeyAssembler) AssignInt(int64) error { - return mixins.StringAssembler{TypeName: "data.UnixTime.Repr.KeyAssembler"}.AssignInt(0) -} -func (_UnixTime__ReprKeyAssembler) AssignFloat(float64) error { - return mixins.StringAssembler{TypeName: "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{TypeName: "data.UnixTime.Repr.KeyAssembler"}.AssignBytes(nil) -} -func (_UnixTime__ReprKeyAssembler) AssignLink(ipld.Link) error { - 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 { - 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 deleted file mode 100644 index 36897b169a..0000000000 --- a/unixfs/node/data/ipldsch_types.go +++ /dev/null @@ -1,82 +0,0 @@ -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 deleted file mode 100644 index 79dbb50cf6..0000000000 --- a/unixfs/node/data/marshal.go +++ /dev/null @@ -1,84 +0,0 @@ -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 deleted file mode 100644 index 00652e65f6..0000000000 --- a/unixfs/node/data/permissions.go +++ /dev/null @@ -1,27 +0,0 @@ -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) -} - -// DefaultPermissions gets the default permissions for a UnixFS object based on its -// type -func DefaultPermissions(u UnixFSData) int { - switch u.FieldDataType().Int() { - case Data_File: - return FilePermissionsDefault - case Data_Directory: - return DirectorPerimissionsDefault - case Data_HAMTShard: - return HAMTShardPerimissionsDefault - default: - return 0 - } -} diff --git a/unixfs/node/data/unmarshal.go b/unixfs/node/data/unmarshal.go deleted file mode 100644 index c46ed62ad3..0000000000 --- a/unixfs/node/data/unmarshal.go +++ /dev/null @@ -1,293 +0,0 @@ -package data - -import ( - "errors" - "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 len(remaining) != 0 { - - 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 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, Field__DataType, qp.Int(int64(dataType))) - case Data_DataWireNum: - if wireType != protowire.BytesType { - 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, Field__Data, qp.Bytes(data)) - case Data_FileSizeWireNum: - if wireType != protowire.VarintType { - 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, Field__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, Field__BlockSizes, qp.List(blockSizeCount, func(la ipld.ListAssembler) { - err := consumeBlockSizes(blockSizesBytes, blockSizeCount, la) - if err != nil { - panic(err) - } - })) - default: - return ErrWrongWireType{"UnixFSData", Field__BlockSizes, protowire.VarintType, wireType} - } - case Data_HashTypeWireNum: - if wireType != protowire.VarintType { - 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, Field__HashType, qp.Int(int64(hashType))) - case Data_FanoutWireNum: - if wireType != protowire.VarintType { - 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, Field__Fanout, qp.Int(int64(fanout))) - case Data_ModeWireNum: - if wireType != protowire.VarintType { - return ErrWrongWireType{"UnixFSData", Field__Mode, 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, Field__Mode, qp.Int(int64(mode))) - case Data_MtimeWireNum: - if wireType != protowire.BytesType { - 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, Field__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, Field__BlockSizes, qp.List(0, func(ipld.ListAssembler) {})) - } else { - err := la.Finish() - if err != nil { - return err - } - nd := bsa.Build() - qp.MapEntry(ma, Field__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 len(remaining) != 0 { - 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 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, Field__Seconds, qp.Int(int64(seconds))) - case UnixTime_FractionalNanosecondsWireNum: - if wireType != protowire.Fixed32Type { - 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, Field__Nanoseconds, 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 len(remaining) != 0 { - - 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 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, Field__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 deleted file mode 100644 index 5bb1462563..0000000000 --- a/unixfs/node/data/wirenumbers.go +++ /dev/null @@ -1,17 +0,0 @@ -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 -) diff --git a/unixfs/node/directory/basicdir.go b/unixfs/node/directory/basicdir.go deleted file mode 100644 index c160becb44..0000000000 --- a/unixfs/node/directory/basicdir.go +++ /dev/null @@ -1,153 +0,0 @@ -package directory - -import ( - "context" - - "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" -) - -var _ ipld.Node = UnixFSBasicDir(nil) -var _ schema.TypedNode = UnixFSBasicDir(nil) -var _ ipld.ADL = 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{Expected: data.Data_Directory, Actual: 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 := utils.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 utils.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() -} - -// 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/file/deferred.go b/unixfs/node/file/deferred.go deleted file mode 100644 index 44ce8ca273..0000000000 --- a/unixfs/node/file/deferred.go +++ /dev/null @@ -1,173 +0,0 @@ -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 deleted file mode 100644 index d9710330c7..0000000000 --- a/unixfs/node/file/file.go +++ /dev/null @@ -1,105 +0,0 @@ -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) (LargeBytesNode, error) { - if substrate.Kind() == ipld.Kind_Bytes { - // A raw / single-node file. - return &singleNodeFile{substrate}, 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, - }, 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 { - 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 - 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 *singleNodeReader) 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 -} - -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/file_test.go b/unixfs/node/file/file_test.go deleted file mode 100644 index 14378c5532..0000000000 --- a/unixfs/node/file/file_test.go +++ /dev/null @@ -1,90 +0,0 @@ -package file_test - -import ( - "bytes" - "context" - "fmt" - "io" - "testing" - - 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" - 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(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(lctx.Ctx, 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 deleted file mode 100644 index 7ec9782d88..0000000000 Binary files a/unixfs/node/file/fixtures/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o.car and /dev/null differ diff --git a/unixfs/node/file/fixtures/QmT8EC9sJq63SkDZ1mWLbWWyVV66PuqyHWpKkH4pcVyY4H.car b/unixfs/node/file/fixtures/QmT8EC9sJq63SkDZ1mWLbWWyVV66PuqyHWpKkH4pcVyY4H.car deleted file mode 100644 index 88b4a08ebe..0000000000 Binary files a/unixfs/node/file/fixtures/QmT8EC9sJq63SkDZ1mWLbWWyVV66PuqyHWpKkH4pcVyY4H.car and /dev/null differ diff --git a/unixfs/node/file/large_file_test.go b/unixfs/node/file/large_file_test.go deleted file mode 100644 index 378ded20fb..0000000000 --- a/unixfs/node/file/large_file_test.go +++ /dev/null @@ -1,66 +0,0 @@ -//go:build !race - -package file_test - -import ( - "bytes" - "context" - "io" - "strconv" - "testing" - - ipfsutil "github.com/ipfs/go-ipfs-util" - "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" -) - -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)) - } - } -} diff --git a/unixfs/node/file/shard.go b/unixfs/node/file/shard.go deleted file mode 100644 index d159ed6748..0000000000 --- a/unixfs/node/file/shard.go +++ /dev/null @@ -1,323 +0,0 @@ -package file - -import ( - "context" - "io" - "sync" - - "github.com/ipfs/go-cid" - "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" - "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 - - // unixfs data unpacked from the substrate. access via .unpack() - metadata data.UnixFSData - unpackLk sync.Once -} - -var _ ipld.Node = (*shardNodeFile)(nil) - -type shardNodeReader struct { - *shardNodeFile - rdr io.Reader - offset int64 - len int64 -} - -func (s *shardNodeReader) makeReader() (io.Reader, error) { - links, err := s.shardNodeFile.substrate.LookupByString("Links") - if err != nil { - return nil, err - } - readers := make([]io.Reader, 0) - lnkIter := links.ListIterator() - at := int64(0) - for !lnkIter.Done() { - lnkIdx, lnk, err := lnkIter.Next() - if err != nil { - return nil, err - } - childSize, tr, err := s.linkSize(lnk, int(lnkIdx)) - if err != nil { - return nil, err - } - if s.offset > at+childSize { - at += childSize - continue - } - 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 { - _, err := tr.Seek(s.offset-at, io.SeekStart) - if err != nil { - return nil, err - } - } - at += childSize - readers = append(readers, tr) - } - 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. - // 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)) - 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 - } - - 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 { - rdr, err := s.makeReader() - if err != nil { - return 0, err - } - s.rdr = rdr - } - n, err := s.rdr.Read(p) - return n, err -} - -func (s *shardNodeReader) Seek(offset int64, whence int) (int64, error) { - if s.rdr != nil { - s.rdr = nil - } - 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.unpack() - if err != nil || nodeData == nil { - return s.lengthFromLinks() - } - if nodeData.FileSize.Exists() { - if fs, err := nodeData.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() { - idx, l, err := li.Next() - if err != nil { - return 0 - } - ll, _, err := s.linkSize(l, int(idx)) - if err != nil { - return 0 - } - size += ll - } - return size -} - -func (s *shardNodeFile) AsLargeBytes() (io.ReadSeeker, error) { - return &shardNodeReader{s, nil, 0, 0}, nil -} - -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) { - rdr, err := s.AsLargeBytes() - if err != nil { - return nil, err - } - return io.ReadAll(rdr) -} - -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 deleted file mode 100644 index b744cafc7b..0000000000 --- a/unixfs/node/file/wrapped.go +++ /dev/null @@ -1,34 +0,0 @@ -package file - -import ( - "github.com/ipfs/go-libipfs/unixfs/node/data" - "github.com/ipld/go-ipld-prime" - "github.com/ipld/go-ipld-prime/node/basicnode" -) - -func newWrappedNode(substrate ipld.Node) (LargeBytesNode, 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/hamt/errors.go b/unixfs/node/hamt/errors.go deleted file mode 100644 index e24e9361dc..0000000000 --- a/unixfs/node/hamt/errors.go +++ /dev/null @@ -1,40 +0,0 @@ -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" - // 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" - // 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 deleted file mode 100644 index 7fc4b1ed12..0000000000 --- a/unixfs/node/hamt/shardeddir.go +++ /dev/null @@ -1,384 +0,0 @@ -package hamt - -import ( - "context" - "fmt" - - bitfield "github.com/ipfs/go-bitfield" - "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" -) - -const ( - // HashMurmur3 is the multiformats identifier for Murmur3 - HashMurmur3 uint64 = 0x22 -) - -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 -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 -} - -// 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 - } - 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 -} - -// 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 -} - -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))} - return n.lookup(key, hv) -} - -func (n UnixFSHAMTShard) lookup(key string, hv *hashBits) (dagpb.Link, error) { - log2 := log2Size(n.data) - maxPadLen := 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, maxPadLen) - if err != nil { - return nil, err - } - if isValue { - if MatchKey(pbLink, key, maxPadLen) { - return pbLink.FieldHash(), 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)} -} - -// 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) - } - if !pbnd.FieldData().Exists() { - return nil, fmt.Errorf("hamt.AttemptHAMTShardFromNode: %w", ErrNotUnixFSNode) - } - 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.Link { - hv := &hashBits{b: hash([]byte(key.String()))} - link, err := n.lookup(key.String(), hv) - if err != nil { - return nil - } - return link -} - -// 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, ErrInvalidChildIndex - } - 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 deleted file mode 100644 index 07b99095e7..0000000000 --- a/unixfs/node/hamt/shardeddir_test.go +++ /dev/null @@ -1,202 +0,0 @@ -package hamt_test - -import ( - "bytes" - "context" - "fmt" - "io" - "math/rand" - "sort" - "testing" - "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" - 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 := dag.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 deleted file mode 100644 index bf615ced8d..0000000000 --- a/unixfs/node/hamt/util.go +++ /dev/null @@ -1,130 +0,0 @@ -package hamt - -// adapted from https://github.com/ipfs/go-unixfs/blob/master/hamt/util.go - -import ( - "fmt" - - "math/bits" - - bitfield "github.com/ipfs/go-bitfield" - "github.com/ipfs/go-libipfs/unixfs/node/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, ErrHAMTTooDeep - } - 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 - } - 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) - } - 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{Expected: data.Data_HAMTShard, Actual: nd.FieldDataType().Int()} - } - - if !nd.FieldHashType().Exists() || uint64(nd.FieldHashType().Must().Int()) != HashMurmur3 { - return ErrInvalidHashType - } - - if !nd.FieldData().Exists() { - return ErrNoDataField - } - - if !nd.FieldFanout().Exists() { - return ErrNoFanoutField - } - 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 ErrHAMTSizeInvalid - } - lg2 := bits.TrailingZeros(uint(v)) - if 1<= 0; i-- { - selectorSoFar = ssb.ExploreInterpretAs("unixfs", - ssb.ExploreFields(func(efsb builder.ExploreFieldsSpecBuilder) { - efsb.Insert(segments[i], selectorSoFar) - }), - ) - } - return selectorSoFar.Node() -} diff --git a/unixfs/node/test/doc.go b/unixfs/node/test/doc.go deleted file mode 100644 index cecd77b64c..0000000000 --- a/unixfs/node/test/doc.go +++ /dev/null @@ -1,4 +0,0 @@ -// Package test provides ADL testing of the ipld specification around -// * traversal making use of match subsets -// * largeByteNode readers -package test diff --git a/unixfs/node/test/partial_file_access_test.go b/unixfs/node/test/partial_file_access_test.go deleted file mode 100644 index 27ed963e2b..0000000000 --- a/unixfs/node/test/partial_file_access_test.go +++ /dev/null @@ -1,108 +0,0 @@ -package test - -import ( - "bytes" - "context" - "io" - "testing" - - u "github.com/ipfs/go-ipfs-util" - "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" - "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.") - } -} diff --git a/unixfs/node/utils/utils.go b/unixfs/node/utils/utils.go deleted file mode 100644 index 9543835d18..0000000000 --- a/unixfs/node/utils/utils.go +++ /dev/null @@ -1,19 +0,0 @@ -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 -}