2019-11-05 03:42:13 +00:00
|
|
|
package retrieval
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
cbg "github.com/whyrusleeping/cbor-gen"
|
|
|
|
xerrors "golang.org/x/xerrors"
|
|
|
|
)
|
|
|
|
|
2019-12-12 23:00:20 +00:00
|
|
|
// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT.
|
2019-11-05 03:42:13 +00:00
|
|
|
|
|
|
|
var _ = xerrors.Errorf
|
|
|
|
|
|
|
|
func (t *RetParams) MarshalCBOR(w io.Writer) error {
|
|
|
|
if t == nil {
|
|
|
|
_, err := w.Write(cbg.CborNull)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := w.Write([]byte{129}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Unixfs0 (retrieval.Unixfs0Offer) (struct)
|
2019-11-05 03:42:13 +00:00
|
|
|
if err := t.Unixfs0.MarshalCBOR(w); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *RetParams) UnmarshalCBOR(r io.Reader) error {
|
|
|
|
br := cbg.GetPeeker(r)
|
|
|
|
|
|
|
|
maj, extra, err := cbg.CborReadHeader(br)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if maj != cbg.MajArray {
|
|
|
|
return fmt.Errorf("cbor input should be of type array")
|
|
|
|
}
|
|
|
|
|
|
|
|
if extra != 1 {
|
|
|
|
return fmt.Errorf("cbor input had wrong number of fields")
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Unixfs0 (retrieval.Unixfs0Offer) (struct)
|
2019-11-05 03:42:13 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
pb, err := br.PeekByte()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if pb == cbg.CborNull[0] {
|
|
|
|
var nbuf [1]byte
|
|
|
|
if _, err := br.Read(nbuf[:]); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
t.Unixfs0 = new(Unixfs0Offer)
|
|
|
|
if err := t.Unixfs0.UnmarshalCBOR(br); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Query) MarshalCBOR(w io.Writer) error {
|
|
|
|
if t == nil {
|
|
|
|
_, err := w.Write(cbg.CborNull)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := w.Write([]byte{129}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Piece (cid.Cid) (struct)
|
2019-11-05 03:42:13 +00:00
|
|
|
|
|
|
|
if err := cbg.WriteCid(w, t.Piece); err != nil {
|
|
|
|
return xerrors.Errorf("failed to write cid field t.Piece: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Query) UnmarshalCBOR(r io.Reader) error {
|
|
|
|
br := cbg.GetPeeker(r)
|
|
|
|
|
|
|
|
maj, extra, err := cbg.CborReadHeader(br)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if maj != cbg.MajArray {
|
|
|
|
return fmt.Errorf("cbor input should be of type array")
|
|
|
|
}
|
|
|
|
|
|
|
|
if extra != 1 {
|
|
|
|
return fmt.Errorf("cbor input had wrong number of fields")
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Piece (cid.Cid) (struct)
|
2019-11-05 03:42:13 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
c, err := cbg.ReadCid(br)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("failed to read cid field t.Piece: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Piece = c
|
|
|
|
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *QueryResponse) MarshalCBOR(w io.Writer) error {
|
|
|
|
if t == nil {
|
|
|
|
_, err := w.Write(cbg.CborNull)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := w.Write([]byte{131}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Status (retrieval.QueryResponseStatus) (uint64)
|
2019-11-05 03:42:13 +00:00
|
|
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Status))); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Size (uint64) (uint64)
|
2019-11-05 03:42:13 +00:00
|
|
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Size))); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.MinPrice (types.BigInt) (struct)
|
2019-11-05 03:42:13 +00:00
|
|
|
if err := t.MinPrice.MarshalCBOR(w); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *QueryResponse) UnmarshalCBOR(r io.Reader) error {
|
|
|
|
br := cbg.GetPeeker(r)
|
|
|
|
|
|
|
|
maj, extra, err := cbg.CborReadHeader(br)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if maj != cbg.MajArray {
|
|
|
|
return fmt.Errorf("cbor input should be of type array")
|
|
|
|
}
|
|
|
|
|
|
|
|
if extra != 3 {
|
|
|
|
return fmt.Errorf("cbor input had wrong number of fields")
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Status (retrieval.QueryResponseStatus) (uint64)
|
2019-11-05 03:42:13 +00:00
|
|
|
|
|
|
|
maj, extra, err = cbg.CborReadHeader(br)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if maj != cbg.MajUnsignedInt {
|
|
|
|
return fmt.Errorf("wrong type for uint64 field")
|
|
|
|
}
|
|
|
|
t.Status = QueryResponseStatus(extra)
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Size (uint64) (uint64)
|
2019-11-05 03:42:13 +00:00
|
|
|
|
|
|
|
maj, extra, err = cbg.CborReadHeader(br)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if maj != cbg.MajUnsignedInt {
|
|
|
|
return fmt.Errorf("wrong type for uint64 field")
|
|
|
|
}
|
|
|
|
t.Size = uint64(extra)
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.MinPrice (types.BigInt) (struct)
|
2019-11-05 03:42:13 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if err := t.MinPrice.UnmarshalCBOR(br); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Unixfs0Offer) MarshalCBOR(w io.Writer) error {
|
|
|
|
if t == nil {
|
|
|
|
_, err := w.Write(cbg.CborNull)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := w.Write([]byte{130}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Offset (uint64) (uint64)
|
2019-11-05 03:42:13 +00:00
|
|
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Offset))); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Size (uint64) (uint64)
|
2019-11-05 03:42:13 +00:00
|
|
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Size))); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Unixfs0Offer) UnmarshalCBOR(r io.Reader) error {
|
|
|
|
br := cbg.GetPeeker(r)
|
|
|
|
|
|
|
|
maj, extra, err := cbg.CborReadHeader(br)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if maj != cbg.MajArray {
|
|
|
|
return fmt.Errorf("cbor input should be of type array")
|
|
|
|
}
|
|
|
|
|
|
|
|
if extra != 2 {
|
|
|
|
return fmt.Errorf("cbor input had wrong number of fields")
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Offset (uint64) (uint64)
|
2019-11-05 03:42:13 +00:00
|
|
|
|
|
|
|
maj, extra, err = cbg.CborReadHeader(br)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if maj != cbg.MajUnsignedInt {
|
|
|
|
return fmt.Errorf("wrong type for uint64 field")
|
|
|
|
}
|
|
|
|
t.Offset = uint64(extra)
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Size (uint64) (uint64)
|
2019-11-05 03:42:13 +00:00
|
|
|
|
|
|
|
maj, extra, err = cbg.CborReadHeader(br)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if maj != cbg.MajUnsignedInt {
|
|
|
|
return fmt.Errorf("wrong type for uint64 field")
|
|
|
|
}
|
|
|
|
t.Size = uint64(extra)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *DealProposal) MarshalCBOR(w io.Writer) error {
|
|
|
|
if t == nil {
|
|
|
|
_, err := w.Write(cbg.CborNull)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := w.Write([]byte{131}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Payment (api.PaymentInfo) (struct)
|
2019-11-05 03:42:13 +00:00
|
|
|
if err := t.Payment.MarshalCBOR(w); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Ref (cid.Cid) (struct)
|
2019-11-05 03:42:13 +00:00
|
|
|
|
|
|
|
if err := cbg.WriteCid(w, t.Ref); err != nil {
|
|
|
|
return xerrors.Errorf("failed to write cid field t.Ref: %w", err)
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Params (retrieval.RetParams) (struct)
|
2019-11-05 03:42:13 +00:00
|
|
|
if err := t.Params.MarshalCBOR(w); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *DealProposal) UnmarshalCBOR(r io.Reader) error {
|
|
|
|
br := cbg.GetPeeker(r)
|
|
|
|
|
|
|
|
maj, extra, err := cbg.CborReadHeader(br)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if maj != cbg.MajArray {
|
|
|
|
return fmt.Errorf("cbor input should be of type array")
|
|
|
|
}
|
|
|
|
|
|
|
|
if extra != 3 {
|
|
|
|
return fmt.Errorf("cbor input had wrong number of fields")
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Payment (api.PaymentInfo) (struct)
|
2019-11-05 03:42:13 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if err := t.Payment.UnmarshalCBOR(br); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Ref (cid.Cid) (struct)
|
2019-11-05 03:42:13 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
c, err := cbg.ReadCid(br)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("failed to read cid field t.Ref: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Ref = c
|
|
|
|
|
|
|
|
}
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Params (retrieval.RetParams) (struct)
|
2019-11-05 03:42:13 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if err := t.Params.UnmarshalCBOR(br); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *DealResponse) MarshalCBOR(w io.Writer) error {
|
|
|
|
if t == nil {
|
|
|
|
_, err := w.Write(cbg.CborNull)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := w.Write([]byte{130}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Status (uint64) (uint64)
|
2019-11-05 03:42:13 +00:00
|
|
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Status))); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Message (string) (string)
|
2019-12-16 23:44:14 +00:00
|
|
|
if len(t.Message) > cbg.MaxLength {
|
|
|
|
return xerrors.Errorf("Value in field t.Message was too long")
|
|
|
|
}
|
|
|
|
|
2019-11-05 03:42:13 +00:00
|
|
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.Message)))); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := w.Write([]byte(t.Message)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *DealResponse) UnmarshalCBOR(r io.Reader) error {
|
|
|
|
br := cbg.GetPeeker(r)
|
|
|
|
|
|
|
|
maj, extra, err := cbg.CborReadHeader(br)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if maj != cbg.MajArray {
|
|
|
|
return fmt.Errorf("cbor input should be of type array")
|
|
|
|
}
|
|
|
|
|
|
|
|
if extra != 2 {
|
|
|
|
return fmt.Errorf("cbor input had wrong number of fields")
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Status (uint64) (uint64)
|
2019-11-05 03:42:13 +00:00
|
|
|
|
|
|
|
maj, extra, err = cbg.CborReadHeader(br)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if maj != cbg.MajUnsignedInt {
|
|
|
|
return fmt.Errorf("wrong type for uint64 field")
|
|
|
|
}
|
|
|
|
t.Status = uint64(extra)
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Message (string) (string)
|
2019-11-05 03:42:13 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
sval, err := cbg.ReadString(br)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Message = string(sval)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Block) MarshalCBOR(w io.Writer) error {
|
|
|
|
if t == nil {
|
|
|
|
_, err := w.Write(cbg.CborNull)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := w.Write([]byte{130}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Prefix ([]uint8) (slice)
|
2019-12-16 23:44:14 +00:00
|
|
|
if len(t.Prefix) > cbg.ByteArrayMaxLen {
|
|
|
|
return xerrors.Errorf("Byte array in field t.Prefix was too long")
|
|
|
|
}
|
|
|
|
|
2019-11-05 03:42:13 +00:00
|
|
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Prefix)))); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := w.Write(t.Prefix); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Data ([]uint8) (slice)
|
2019-12-16 23:44:14 +00:00
|
|
|
if len(t.Data) > cbg.ByteArrayMaxLen {
|
|
|
|
return xerrors.Errorf("Byte array in field t.Data was too long")
|
|
|
|
}
|
|
|
|
|
2019-11-05 16:38:54 +00:00
|
|
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Data)))); err != nil {
|
2019-11-05 03:42:13 +00:00
|
|
|
return err
|
|
|
|
}
|
2019-11-05 16:38:54 +00:00
|
|
|
if _, err := w.Write(t.Data); err != nil {
|
2019-11-05 03:42:13 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Block) UnmarshalCBOR(r io.Reader) error {
|
|
|
|
br := cbg.GetPeeker(r)
|
|
|
|
|
|
|
|
maj, extra, err := cbg.CborReadHeader(br)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if maj != cbg.MajArray {
|
2019-11-05 16:38:54 +00:00
|
|
|
return fmt.Errorf("cbor input should be of type array")
|
2019-11-05 03:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if extra != 2 {
|
|
|
|
return fmt.Errorf("cbor input had wrong number of fields")
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Prefix ([]uint8) (slice)
|
2019-11-05 03:42:13 +00:00
|
|
|
|
|
|
|
maj, extra, err = cbg.CborReadHeader(br)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
if extra > cbg.ByteArrayMaxLen {
|
|
|
|
return fmt.Errorf("t.Prefix: byte array too large (%d)", extra)
|
|
|
|
}
|
2019-11-05 03:42:13 +00:00
|
|
|
if maj != cbg.MajByteString {
|
|
|
|
return fmt.Errorf("expected byte array")
|
|
|
|
}
|
|
|
|
t.Prefix = make([]byte, extra)
|
|
|
|
if _, err := io.ReadFull(br, t.Prefix); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-12-09 16:40:15 +00:00
|
|
|
// t.Data ([]uint8) (slice)
|
2019-11-05 03:42:13 +00:00
|
|
|
|
|
|
|
maj, extra, err = cbg.CborReadHeader(br)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:40:15 +00:00
|
|
|
if extra > cbg.ByteArrayMaxLen {
|
|
|
|
return fmt.Errorf("t.Data: byte array too large (%d)", extra)
|
|
|
|
}
|
2019-11-05 03:42:13 +00:00
|
|
|
if maj != cbg.MajByteString {
|
|
|
|
return fmt.Errorf("expected byte array")
|
|
|
|
}
|
|
|
|
t.Data = make([]byte, extra)
|
|
|
|
if _, err := io.ReadFull(br, t.Data); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|