465 lines
9.1 KiB
Go
465 lines
9.1 KiB
Go
package retrieval
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
|
|
cbg "github.com/whyrusleeping/cbor-gen"
|
|
xerrors "golang.org/x/xerrors"
|
|
)
|
|
|
|
/* This file was generated by github.com/whyrusleeping/cbor-gen */
|
|
|
|
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
|
|
}
|
|
|
|
// t.t.Unixfs0 (retrieval.Unixfs0Offer) (struct)
|
|
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")
|
|
}
|
|
|
|
// t.t.Unixfs0 (retrieval.Unixfs0Offer) (struct)
|
|
|
|
{
|
|
|
|
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
|
|
}
|
|
|
|
// t.t.Piece (cid.Cid) (struct)
|
|
|
|
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")
|
|
}
|
|
|
|
// t.t.Piece (cid.Cid) (struct)
|
|
|
|
{
|
|
|
|
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
|
|
}
|
|
|
|
// t.t.Status (retrieval.QueryResponseStatus) (uint64)
|
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Status))); err != nil {
|
|
return err
|
|
}
|
|
|
|
// t.t.Size (uint64) (uint64)
|
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Size))); err != nil {
|
|
return err
|
|
}
|
|
|
|
// t.t.MinPrice (types.BigInt) (struct)
|
|
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")
|
|
}
|
|
|
|
// t.t.Status (retrieval.QueryResponseStatus) (uint64)
|
|
|
|
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)
|
|
// t.t.Size (uint64) (uint64)
|
|
|
|
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)
|
|
// t.t.MinPrice (types.BigInt) (struct)
|
|
|
|
{
|
|
|
|
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
|
|
}
|
|
|
|
// t.t.Offset (uint64) (uint64)
|
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Offset))); err != nil {
|
|
return err
|
|
}
|
|
|
|
// t.t.Size (uint64) (uint64)
|
|
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")
|
|
}
|
|
|
|
// t.t.Offset (uint64) (uint64)
|
|
|
|
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)
|
|
// t.t.Size (uint64) (uint64)
|
|
|
|
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
|
|
}
|
|
|
|
// t.t.Payment (api.PaymentInfo) (struct)
|
|
if err := t.Payment.MarshalCBOR(w); err != nil {
|
|
return err
|
|
}
|
|
|
|
// t.t.Ref (cid.Cid) (struct)
|
|
|
|
if err := cbg.WriteCid(w, t.Ref); err != nil {
|
|
return xerrors.Errorf("failed to write cid field t.Ref: %w", err)
|
|
}
|
|
|
|
// t.t.Params (retrieval.RetParams) (struct)
|
|
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")
|
|
}
|
|
|
|
// t.t.Payment (api.PaymentInfo) (struct)
|
|
|
|
{
|
|
|
|
if err := t.Payment.UnmarshalCBOR(br); err != nil {
|
|
return err
|
|
}
|
|
|
|
}
|
|
// t.t.Ref (cid.Cid) (struct)
|
|
|
|
{
|
|
|
|
c, err := cbg.ReadCid(br)
|
|
if err != nil {
|
|
return xerrors.Errorf("failed to read cid field t.Ref: %w", err)
|
|
}
|
|
|
|
t.Ref = c
|
|
|
|
}
|
|
// t.t.Params (retrieval.RetParams) (struct)
|
|
|
|
{
|
|
|
|
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
|
|
}
|
|
|
|
// t.t.Status (uint64) (uint64)
|
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Status))); err != nil {
|
|
return err
|
|
}
|
|
|
|
// t.t.Message (string) (string)
|
|
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")
|
|
}
|
|
|
|
// t.t.Status (uint64) (uint64)
|
|
|
|
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)
|
|
// t.t.Message (string) (string)
|
|
|
|
{
|
|
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
|
|
}
|
|
|
|
// t.t.Prefix ([]uint8) (slice)
|
|
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
|
|
}
|
|
|
|
// t.t.Data ([]uint8) (slice)
|
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Data)))); err != nil {
|
|
return err
|
|
}
|
|
if _, err := w.Write(t.Data); err != nil {
|
|
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 {
|
|
return fmt.Errorf("cbor input should be of type array")
|
|
}
|
|
|
|
if extra != 2 {
|
|
return fmt.Errorf("cbor input had wrong number of fields")
|
|
}
|
|
|
|
// t.t.Prefix ([]uint8) (slice)
|
|
|
|
maj, extra, err = cbg.CborReadHeader(br)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if extra > cbg.ByteArrayMaxLen {
|
|
return fmt.Errorf("t.Prefix: byte array too large (%d)", extra)
|
|
}
|
|
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
|
|
}
|
|
// t.t.Data ([]uint8) (slice)
|
|
|
|
maj, extra, err = cbg.CborReadHeader(br)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if extra > cbg.ByteArrayMaxLen {
|
|
return fmt.Errorf("t.Data: byte array too large (%d)", extra)
|
|
}
|
|
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
|
|
}
|