diff --git a/pkg/atproto/cbor_gen.go b/pkg/atproto/cbor_gen.go index 80fcd9e..3d6fef2 100644 --- a/pkg/atproto/cbor_gen.go +++ b/pkg/atproto/cbor_gen.go @@ -8,6 +8,7 @@ import ( "math" "sort" + util "github.com/bluesky-social/indigo/lex/util" cid "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" xerrors "golang.org/x/xerrors" @@ -18,7 +19,3199 @@ var _ = cid.Undef var _ = math.E var _ = sort.Sort -func (t *CrewRecord) MarshalCBOR(w io.Writer) error { +func (t *Manifest) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 14 + + if t.Annotations == nil { + fieldCount-- + } + + if t.Config == nil { + fieldCount-- + } + + if t.HoldDid == nil { + fieldCount-- + } + + if t.HoldEndpoint == nil { + fieldCount-- + } + + if t.Layers == nil { + fieldCount-- + } + + if t.ManifestBlob == nil { + fieldCount-- + } + + if t.Manifests == nil { + fieldCount-- + } + + if t.Subject == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if len("$type") > 8192 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.manifest"))); err != nil { + return err + } + if _, err := cw.WriteString(string("io.atcr.manifest")); err != nil { + return err + } + + // t.Config (atproto.Manifest_BlobReference) (struct) + if t.Config != nil { + + if len("config") > 8192 { + return xerrors.Errorf("Value in field \"config\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("config"))); err != nil { + return err + } + if _, err := cw.WriteString(string("config")); err != nil { + return err + } + + if err := t.Config.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.Digest (string) (string) + if len("digest") > 8192 { + return xerrors.Errorf("Value in field \"digest\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("digest"))); err != nil { + return err + } + if _, err := cw.WriteString(string("digest")); err != nil { + return err + } + + if len(t.Digest) > 8192 { + return xerrors.Errorf("Value in field t.Digest was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Digest))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Digest)); err != nil { + return err + } + + // t.Layers ([]atproto.Manifest_BlobReference) (slice) + if t.Layers != nil { + + if len("layers") > 8192 { + return xerrors.Errorf("Value in field \"layers\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("layers"))); err != nil { + return err + } + if _, err := cw.WriteString(string("layers")); err != nil { + return err + } + + if len(t.Layers) > 8192 { + return xerrors.Errorf("Slice value in field t.Layers was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Layers))); err != nil { + return err + } + for _, v := range t.Layers { + if err := v.MarshalCBOR(cw); err != nil { + return err + } + + } + } + + // t.HoldDid (string) (string) + if t.HoldDid != nil { + + if len("holdDid") > 8192 { + return xerrors.Errorf("Value in field \"holdDid\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("holdDid"))); err != nil { + return err + } + if _, err := cw.WriteString(string("holdDid")); err != nil { + return err + } + + if t.HoldDid == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.HoldDid) > 8192 { + return xerrors.Errorf("Value in field t.HoldDid was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.HoldDid))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.HoldDid)); err != nil { + return err + } + } + } + + // t.Subject (atproto.Manifest_BlobReference) (struct) + if t.Subject != nil { + + if len("subject") > 8192 { + return xerrors.Errorf("Value in field \"subject\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("subject"))); err != nil { + return err + } + if _, err := cw.WriteString(string("subject")); err != nil { + return err + } + + if err := t.Subject.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.CreatedAt (string) (string) + if len("createdAt") > 8192 { + return xerrors.Errorf("Value in field \"createdAt\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { + return err + } + if _, err := cw.WriteString(string("createdAt")); err != nil { + return err + } + + if len(t.CreatedAt) > 8192 { + return xerrors.Errorf("Value in field t.CreatedAt was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.CreatedAt)); err != nil { + return err + } + + // t.Manifests ([]atproto.Manifest_ManifestReference) (slice) + if t.Manifests != nil { + + if len("manifests") > 8192 { + return xerrors.Errorf("Value in field \"manifests\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("manifests"))); err != nil { + return err + } + if _, err := cw.WriteString(string("manifests")); err != nil { + return err + } + + if len(t.Manifests) > 8192 { + return xerrors.Errorf("Slice value in field t.Manifests was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Manifests))); err != nil { + return err + } + for _, v := range t.Manifests { + if err := v.MarshalCBOR(cw); err != nil { + return err + } + + } + } + + // t.MediaType (string) (string) + if len("mediaType") > 8192 { + return xerrors.Errorf("Value in field \"mediaType\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("mediaType"))); err != nil { + return err + } + if _, err := cw.WriteString(string("mediaType")); err != nil { + return err + } + + if len(t.MediaType) > 8192 { + return xerrors.Errorf("Value in field t.MediaType was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.MediaType))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.MediaType)); err != nil { + return err + } + + // t.Repository (string) (string) + if len("repository") > 8192 { + return xerrors.Errorf("Value in field \"repository\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("repository"))); err != nil { + return err + } + if _, err := cw.WriteString(string("repository")); err != nil { + return err + } + + if len(t.Repository) > 8192 { + return xerrors.Errorf("Value in field t.Repository was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Repository))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Repository)); err != nil { + return err + } + + // t.Annotations (atproto.Manifest_Annotations) (struct) + if t.Annotations != nil { + + if len("annotations") > 8192 { + return xerrors.Errorf("Value in field \"annotations\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("annotations"))); err != nil { + return err + } + if _, err := cw.WriteString(string("annotations")); err != nil { + return err + } + + if err := t.Annotations.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.HoldEndpoint (string) (string) + if t.HoldEndpoint != nil { + + if len("holdEndpoint") > 8192 { + return xerrors.Errorf("Value in field \"holdEndpoint\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("holdEndpoint"))); err != nil { + return err + } + if _, err := cw.WriteString(string("holdEndpoint")); err != nil { + return err + } + + if t.HoldEndpoint == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.HoldEndpoint) > 8192 { + return xerrors.Errorf("Value in field t.HoldEndpoint was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.HoldEndpoint))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.HoldEndpoint)); err != nil { + return err + } + } + } + + // t.ManifestBlob (util.LexBlob) (struct) + if t.ManifestBlob != nil { + + if len("manifestBlob") > 8192 { + return xerrors.Errorf("Value in field \"manifestBlob\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("manifestBlob"))); err != nil { + return err + } + if _, err := cw.WriteString(string("manifestBlob")); err != nil { + return err + } + + if err := t.ManifestBlob.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.SchemaVersion (int64) (int64) + if len("schemaVersion") > 8192 { + return xerrors.Errorf("Value in field \"schemaVersion\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("schemaVersion"))); err != nil { + return err + } + if _, err := cw.WriteString(string("schemaVersion")); err != nil { + return err + } + + if t.SchemaVersion >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.SchemaVersion)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.SchemaVersion-1)); err != nil { + return err + } + } + + return nil +} + +func (t *Manifest) UnmarshalCBOR(r io.Reader) (err error) { + *t = Manifest{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("Manifest: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 13) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Config (atproto.Manifest_BlobReference) (struct) + case "config": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Config = new(Manifest_BlobReference) + if err := t.Config.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Config pointer: %w", err) + } + } + + } + // t.Digest (string) (string) + case "digest": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.Digest = string(sval) + } + // t.Layers ([]atproto.Manifest_BlobReference) (slice) + case "layers": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > 8192 { + return fmt.Errorf("t.Layers: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Layers = make([]Manifest_BlobReference, extra) + } + + for i := 0; i < int(extra); i++ { + { + var maj byte + var extra uint64 + var err error + _ = maj + _ = extra + _ = err + + { + + if err := t.Layers[i].UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Layers[i]: %w", err) + } + + } + + } + } + // t.HoldDid (string) (string) + case "holdDid": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.HoldDid = (*string)(&sval) + } + } + // t.Subject (atproto.Manifest_BlobReference) (struct) + case "subject": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Subject = new(Manifest_BlobReference) + if err := t.Subject.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Subject pointer: %w", err) + } + } + + } + // t.CreatedAt (string) (string) + case "createdAt": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.CreatedAt = string(sval) + } + // t.Manifests ([]atproto.Manifest_ManifestReference) (slice) + case "manifests": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > 8192 { + return fmt.Errorf("t.Manifests: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Manifests = make([]Manifest_ManifestReference, extra) + } + + for i := 0; i < int(extra); i++ { + { + var maj byte + var extra uint64 + var err error + _ = maj + _ = extra + _ = err + + { + + if err := t.Manifests[i].UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Manifests[i]: %w", err) + } + + } + + } + } + // t.MediaType (string) (string) + case "mediaType": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.MediaType = string(sval) + } + // t.Repository (string) (string) + case "repository": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.Repository = string(sval) + } + // t.Annotations (atproto.Manifest_Annotations) (struct) + case "annotations": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Annotations = new(Manifest_Annotations) + if err := t.Annotations.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Annotations pointer: %w", err) + } + } + + } + // t.HoldEndpoint (string) (string) + case "holdEndpoint": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.HoldEndpoint = (*string)(&sval) + } + } + // t.ManifestBlob (util.LexBlob) (struct) + case "manifestBlob": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.ManifestBlob = new(util.LexBlob) + if err := t.ManifestBlob.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.ManifestBlob pointer: %w", err) + } + } + + } + // t.SchemaVersion (int64) (int64) + case "schemaVersion": + { + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + var extraI int64 + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative overflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.SchemaVersion = int64(extraI) + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *Manifest_BlobReference) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 6 + + if t.LexiconTypeID == "" { + fieldCount-- + } + + if t.Annotations == nil { + fieldCount-- + } + + if t.Urls == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.Size (int64) (int64) + if len("size") > 8192 { + return xerrors.Errorf("Value in field \"size\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("size"))); err != nil { + return err + } + if _, err := cw.WriteString(string("size")); err != nil { + return err + } + + if t.Size >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Size)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Size-1)); err != nil { + return err + } + } + + // t.Urls ([]string) (slice) + if t.Urls != nil { + + if len("urls") > 8192 { + return xerrors.Errorf("Value in field \"urls\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("urls"))); err != nil { + return err + } + if _, err := cw.WriteString(string("urls")); err != nil { + return err + } + + if len(t.Urls) > 8192 { + return xerrors.Errorf("Slice value in field t.Urls was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Urls))); err != nil { + return err + } + for _, v := range t.Urls { + if len(v) > 8192 { + return xerrors.Errorf("Value in field v was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(v))); err != nil { + return err + } + if _, err := cw.WriteString(string(v)); err != nil { + return err + } + + } + } + + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { + + if len("$type") > 8192 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.manifest#blobReference"))); err != nil { + return err + } + if _, err := cw.WriteString(string("io.atcr.manifest#blobReference")); err != nil { + return err + } + } + + // t.Digest (string) (string) + if len("digest") > 8192 { + return xerrors.Errorf("Value in field \"digest\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("digest"))); err != nil { + return err + } + if _, err := cw.WriteString(string("digest")); err != nil { + return err + } + + if len(t.Digest) > 8192 { + return xerrors.Errorf("Value in field t.Digest was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Digest))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Digest)); err != nil { + return err + } + + // t.MediaType (string) (string) + if len("mediaType") > 8192 { + return xerrors.Errorf("Value in field \"mediaType\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("mediaType"))); err != nil { + return err + } + if _, err := cw.WriteString(string("mediaType")); err != nil { + return err + } + + if len(t.MediaType) > 8192 { + return xerrors.Errorf("Value in field t.MediaType was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.MediaType))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.MediaType)); err != nil { + return err + } + + // t.Annotations (atproto.Manifest_BlobReference_Annotations) (struct) + if t.Annotations != nil { + + if len("annotations") > 8192 { + return xerrors.Errorf("Value in field \"annotations\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("annotations"))); err != nil { + return err + } + if _, err := cw.WriteString(string("annotations")); err != nil { + return err + } + + if err := t.Annotations.MarshalCBOR(cw); err != nil { + return err + } + } + return nil +} + +func (t *Manifest_BlobReference) UnmarshalCBOR(r io.Reader) (err error) { + *t = Manifest_BlobReference{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("Manifest_BlobReference: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 11) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.Size (int64) (int64) + case "size": + { + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + var extraI int64 + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative overflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.Size = int64(extraI) + } + // t.Urls ([]string) (slice) + case "urls": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > 8192 { + return fmt.Errorf("t.Urls: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Urls = make([]string, extra) + } + + for i := 0; i < int(extra); i++ { + { + var maj byte + var extra uint64 + var err error + _ = maj + _ = extra + _ = err + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.Urls[i] = string(sval) + } + + } + } + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Digest (string) (string) + case "digest": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.Digest = string(sval) + } + // t.MediaType (string) (string) + case "mediaType": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.MediaType = string(sval) + } + // t.Annotations (atproto.Manifest_BlobReference_Annotations) (struct) + case "annotations": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Annotations = new(Manifest_BlobReference_Annotations) + if err := t.Annotations.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Annotations pointer: %w", err) + } + } + + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *Manifest_ManifestReference) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 6 + + if t.LexiconTypeID == "" { + fieldCount-- + } + + if t.Annotations == nil { + fieldCount-- + } + + if t.Platform == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.Size (int64) (int64) + if len("size") > 8192 { + return xerrors.Errorf("Value in field \"size\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("size"))); err != nil { + return err + } + if _, err := cw.WriteString(string("size")); err != nil { + return err + } + + if t.Size >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Size)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Size-1)); err != nil { + return err + } + } + + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { + + if len("$type") > 8192 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.manifest#manifestReference"))); err != nil { + return err + } + if _, err := cw.WriteString(string("io.atcr.manifest#manifestReference")); err != nil { + return err + } + } + + // t.Digest (string) (string) + if len("digest") > 8192 { + return xerrors.Errorf("Value in field \"digest\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("digest"))); err != nil { + return err + } + if _, err := cw.WriteString(string("digest")); err != nil { + return err + } + + if len(t.Digest) > 8192 { + return xerrors.Errorf("Value in field t.Digest was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Digest))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Digest)); err != nil { + return err + } + + // t.Platform (atproto.Manifest_Platform) (struct) + if t.Platform != nil { + + if len("platform") > 8192 { + return xerrors.Errorf("Value in field \"platform\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("platform"))); err != nil { + return err + } + if _, err := cw.WriteString(string("platform")); err != nil { + return err + } + + if err := t.Platform.MarshalCBOR(cw); err != nil { + return err + } + } + + // t.MediaType (string) (string) + if len("mediaType") > 8192 { + return xerrors.Errorf("Value in field \"mediaType\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("mediaType"))); err != nil { + return err + } + if _, err := cw.WriteString(string("mediaType")); err != nil { + return err + } + + if len(t.MediaType) > 8192 { + return xerrors.Errorf("Value in field t.MediaType was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.MediaType))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.MediaType)); err != nil { + return err + } + + // t.Annotations (atproto.Manifest_ManifestReference_Annotations) (struct) + if t.Annotations != nil { + + if len("annotations") > 8192 { + return xerrors.Errorf("Value in field \"annotations\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("annotations"))); err != nil { + return err + } + if _, err := cw.WriteString(string("annotations")); err != nil { + return err + } + + if err := t.Annotations.MarshalCBOR(cw); err != nil { + return err + } + } + return nil +} + +func (t *Manifest_ManifestReference) UnmarshalCBOR(r io.Reader) (err error) { + *t = Manifest_ManifestReference{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("Manifest_ManifestReference: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 11) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.Size (int64) (int64) + case "size": + { + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + var extraI int64 + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative overflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.Size = int64(extraI) + } + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Digest (string) (string) + case "digest": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.Digest = string(sval) + } + // t.Platform (atproto.Manifest_Platform) (struct) + case "platform": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Platform = new(Manifest_Platform) + if err := t.Platform.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Platform pointer: %w", err) + } + } + + } + // t.MediaType (string) (string) + case "mediaType": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.MediaType = string(sval) + } + // t.Annotations (atproto.Manifest_ManifestReference_Annotations) (struct) + case "annotations": + + { + + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + t.Annotations = new(Manifest_ManifestReference_Annotations) + if err := t.Annotations.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Annotations pointer: %w", err) + } + } + + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *Manifest_Platform) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 6 + + if t.LexiconTypeID == "" { + fieldCount-- + } + + if t.OsFeatures == nil { + fieldCount-- + } + + if t.OsVersion == nil { + fieldCount-- + } + + if t.Variant == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.Os (string) (string) + if len("os") > 8192 { + return xerrors.Errorf("Value in field \"os\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("os"))); err != nil { + return err + } + if _, err := cw.WriteString(string("os")); err != nil { + return err + } + + if len(t.Os) > 8192 { + return xerrors.Errorf("Value in field t.Os was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Os))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Os)); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { + + if len("$type") > 8192 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.manifest#platform"))); err != nil { + return err + } + if _, err := cw.WriteString(string("io.atcr.manifest#platform")); err != nil { + return err + } + } + + // t.Variant (string) (string) + if t.Variant != nil { + + if len("variant") > 8192 { + return xerrors.Errorf("Value in field \"variant\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("variant"))); err != nil { + return err + } + if _, err := cw.WriteString(string("variant")); err != nil { + return err + } + + if t.Variant == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.Variant) > 8192 { + return xerrors.Errorf("Value in field t.Variant was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Variant))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.Variant)); err != nil { + return err + } + } + } + + // t.OsVersion (string) (string) + if t.OsVersion != nil { + + if len("osVersion") > 8192 { + return xerrors.Errorf("Value in field \"osVersion\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("osVersion"))); err != nil { + return err + } + if _, err := cw.WriteString(string("osVersion")); err != nil { + return err + } + + if t.OsVersion == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.OsVersion) > 8192 { + return xerrors.Errorf("Value in field t.OsVersion was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.OsVersion))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.OsVersion)); err != nil { + return err + } + } + } + + // t.OsFeatures ([]string) (slice) + if t.OsFeatures != nil { + + if len("osFeatures") > 8192 { + return xerrors.Errorf("Value in field \"osFeatures\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("osFeatures"))); err != nil { + return err + } + if _, err := cw.WriteString(string("osFeatures")); err != nil { + return err + } + + if len(t.OsFeatures) > 8192 { + return xerrors.Errorf("Slice value in field t.OsFeatures was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.OsFeatures))); err != nil { + return err + } + for _, v := range t.OsFeatures { + if len(v) > 8192 { + return xerrors.Errorf("Value in field v was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(v))); err != nil { + return err + } + if _, err := cw.WriteString(string(v)); err != nil { + return err + } + + } + } + + // t.Architecture (string) (string) + if len("architecture") > 8192 { + return xerrors.Errorf("Value in field \"architecture\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("architecture"))); err != nil { + return err + } + if _, err := cw.WriteString(string("architecture")); err != nil { + return err + } + + if len(t.Architecture) > 8192 { + return xerrors.Errorf("Value in field t.Architecture was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Architecture))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Architecture)); err != nil { + return err + } + return nil +} + +func (t *Manifest_Platform) UnmarshalCBOR(r io.Reader) (err error) { + *t = Manifest_Platform{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("Manifest_Platform: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 12) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.Os (string) (string) + case "os": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.Os = string(sval) + } + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Variant (string) (string) + case "variant": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.Variant = (*string)(&sval) + } + } + // t.OsVersion (string) (string) + case "osVersion": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.OsVersion = (*string)(&sval) + } + } + // t.OsFeatures ([]string) (slice) + case "osFeatures": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + + if extra > 8192 { + return fmt.Errorf("t.OsFeatures: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.OsFeatures = make([]string, extra) + } + + for i := 0; i < int(extra); i++ { + { + var maj byte + var extra uint64 + var err error + _ = maj + _ = extra + _ = err + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.OsFeatures[i] = string(sval) + } + + } + } + // t.Architecture (string) (string) + case "architecture": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.Architecture = string(sval) + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *Manifest_Annotations) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{160}); err != nil { + return err + } + return nil +} + +func (t *Manifest_Annotations) UnmarshalCBOR(r io.Reader) (err error) { + *t = Manifest_Annotations{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("Manifest_Annotations: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 0) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *Manifest_BlobReference_Annotations) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{160}); err != nil { + return err + } + return nil +} + +func (t *Manifest_BlobReference_Annotations) UnmarshalCBOR(r io.Reader) (err error) { + *t = Manifest_BlobReference_Annotations{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("Manifest_BlobReference_Annotations: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 0) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *Manifest_ManifestReference_Annotations) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{160}); err != nil { + return err + } + return nil +} + +func (t *Manifest_ManifestReference_Annotations) UnmarshalCBOR(r io.Reader) (err error) { + *t = Manifest_ManifestReference_Annotations{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("Manifest_ManifestReference_Annotations: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 0) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *Tag) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 6 + + if t.Manifest == nil { + fieldCount-- + } + + if t.ManifestDigest == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.Tag (string) (string) + if len("tag") > 8192 { + return xerrors.Errorf("Value in field \"tag\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("tag"))); err != nil { + return err + } + if _, err := cw.WriteString(string("tag")); err != nil { + return err + } + + if len(t.Tag) > 8192 { + return xerrors.Errorf("Value in field t.Tag was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Tag))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Tag)); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if len("$type") > 8192 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.tag"))); err != nil { + return err + } + if _, err := cw.WriteString(string("io.atcr.tag")); err != nil { + return err + } + + // t.Manifest (string) (string) + if t.Manifest != nil { + + if len("manifest") > 8192 { + return xerrors.Errorf("Value in field \"manifest\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("manifest"))); err != nil { + return err + } + if _, err := cw.WriteString(string("manifest")); err != nil { + return err + } + + if t.Manifest == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.Manifest) > 8192 { + return xerrors.Errorf("Value in field t.Manifest was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Manifest))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.Manifest)); err != nil { + return err + } + } + } + + // t.CreatedAt (string) (string) + if len("createdAt") > 8192 { + return xerrors.Errorf("Value in field \"createdAt\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { + return err + } + if _, err := cw.WriteString(string("createdAt")); err != nil { + return err + } + + if len(t.CreatedAt) > 8192 { + return xerrors.Errorf("Value in field t.CreatedAt was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.CreatedAt)); err != nil { + return err + } + + // t.Repository (string) (string) + if len("repository") > 8192 { + return xerrors.Errorf("Value in field \"repository\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("repository"))); err != nil { + return err + } + if _, err := cw.WriteString(string("repository")); err != nil { + return err + } + + if len(t.Repository) > 8192 { + return xerrors.Errorf("Value in field t.Repository was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Repository))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Repository)); err != nil { + return err + } + + // t.ManifestDigest (string) (string) + if t.ManifestDigest != nil { + + if len("manifestDigest") > 8192 { + return xerrors.Errorf("Value in field \"manifestDigest\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("manifestDigest"))); err != nil { + return err + } + if _, err := cw.WriteString(string("manifestDigest")); err != nil { + return err + } + + if t.ManifestDigest == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.ManifestDigest) > 8192 { + return xerrors.Errorf("Value in field t.ManifestDigest was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.ManifestDigest))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.ManifestDigest)); err != nil { + return err + } + } + } + return nil +} + +func (t *Tag) UnmarshalCBOR(r io.Reader) (err error) { + *t = Tag{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("Tag: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 14) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.Tag (string) (string) + case "tag": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.Tag = string(sval) + } + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Manifest (string) (string) + case "manifest": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.Manifest = (*string)(&sval) + } + } + // t.CreatedAt (string) (string) + case "createdAt": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.CreatedAt = string(sval) + } + // t.Repository (string) (string) + case "repository": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.Repository = string(sval) + } + // t.ManifestDigest (string) (string) + case "manifestDigest": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.ManifestDigest = (*string)(&sval) + } + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *SailorProfile) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 4 + + if t.DefaultHold == nil { + fieldCount-- + } + + if t.UpdatedAt == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if len("$type") > 8192 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.sailor.profile"))); err != nil { + return err + } + if _, err := cw.WriteString(string("io.atcr.sailor.profile")); err != nil { + return err + } + + // t.CreatedAt (string) (string) + if len("createdAt") > 8192 { + return xerrors.Errorf("Value in field \"createdAt\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { + return err + } + if _, err := cw.WriteString(string("createdAt")); err != nil { + return err + } + + if len(t.CreatedAt) > 8192 { + return xerrors.Errorf("Value in field t.CreatedAt was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.CreatedAt)); err != nil { + return err + } + + // t.UpdatedAt (string) (string) + if t.UpdatedAt != nil { + + if len("updatedAt") > 8192 { + return xerrors.Errorf("Value in field \"updatedAt\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("updatedAt"))); err != nil { + return err + } + if _, err := cw.WriteString(string("updatedAt")); err != nil { + return err + } + + if t.UpdatedAt == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.UpdatedAt) > 8192 { + return xerrors.Errorf("Value in field t.UpdatedAt was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.UpdatedAt))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.UpdatedAt)); err != nil { + return err + } + } + } + + // t.DefaultHold (string) (string) + if t.DefaultHold != nil { + + if len("defaultHold") > 8192 { + return xerrors.Errorf("Value in field \"defaultHold\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("defaultHold"))); err != nil { + return err + } + if _, err := cw.WriteString(string("defaultHold")); err != nil { + return err + } + + if t.DefaultHold == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.DefaultHold) > 8192 { + return xerrors.Errorf("Value in field t.DefaultHold was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.DefaultHold))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.DefaultHold)); err != nil { + return err + } + } + } + return nil +} + +func (t *SailorProfile) UnmarshalCBOR(r io.Reader) (err error) { + *t = SailorProfile{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("SailorProfile: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 11) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.CreatedAt (string) (string) + case "createdAt": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.CreatedAt = string(sval) + } + // t.UpdatedAt (string) (string) + case "updatedAt": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.UpdatedAt = (*string)(&sval) + } + } + // t.DefaultHold (string) (string) + case "defaultHold": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.DefaultHold = (*string)(&sval) + } + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *SailorStar) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{163}); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if len("$type") > 8192 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.sailor.star"))); err != nil { + return err + } + if _, err := cw.WriteString(string("io.atcr.sailor.star")); err != nil { + return err + } + + // t.Subject (atproto.SailorStar_Subject) (struct) + if len("subject") > 8192 { + return xerrors.Errorf("Value in field \"subject\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("subject"))); err != nil { + return err + } + if _, err := cw.WriteString(string("subject")); err != nil { + return err + } + + if err := t.Subject.MarshalCBOR(cw); err != nil { + return err + } + + // t.CreatedAt (string) (string) + if len("createdAt") > 8192 { + return xerrors.Errorf("Value in field \"createdAt\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { + return err + } + if _, err := cw.WriteString(string("createdAt")); err != nil { + return err + } + + if len(t.CreatedAt) > 8192 { + return xerrors.Errorf("Value in field t.CreatedAt was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.CreatedAt)); err != nil { + return err + } + return nil +} + +func (t *SailorStar) UnmarshalCBOR(r io.Reader) (err error) { + *t = SailorStar{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("SailorStar: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 9) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Subject (atproto.SailorStar_Subject) (struct) + case "subject": + + { + + if err := t.Subject.UnmarshalCBOR(cr); err != nil { + return xerrors.Errorf("unmarshaling t.Subject: %w", err) + } + + } + // t.CreatedAt (string) (string) + case "createdAt": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.CreatedAt = string(sval) + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *SailorStar_Subject) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 3 + + if t.LexiconTypeID == "" { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.Did (string) (string) + if len("did") > 8192 { + return xerrors.Errorf("Value in field \"did\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("did"))); err != nil { + return err + } + if _, err := cw.WriteString(string("did")); err != nil { + return err + } + + if len(t.Did) > 8192 { + return xerrors.Errorf("Value in field t.Did was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Did))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Did)); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if t.LexiconTypeID != "" { + + if len("$type") > 8192 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.sailor.star#subject"))); err != nil { + return err + } + if _, err := cw.WriteString(string("io.atcr.sailor.star#subject")); err != nil { + return err + } + } + + // t.Repository (string) (string) + if len("repository") > 8192 { + return xerrors.Errorf("Value in field \"repository\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("repository"))); err != nil { + return err + } + if _, err := cw.WriteString(string("repository")); err != nil { + return err + } + + if len(t.Repository) > 8192 { + return xerrors.Errorf("Value in field t.Repository was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Repository))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Repository)); err != nil { + return err + } + return nil +} + +func (t *SailorStar_Subject) UnmarshalCBOR(r io.Reader) (err error) { + *t = SailorStar_Subject{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("SailorStar_Subject: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 10) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.Did (string) (string) + case "did": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.Did = string(sval) + } + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Repository (string) (string) + case "repository": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.Repository = string(sval) + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *HoldCaptain) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + fieldCount := 8 + + if t.Provider == nil { + fieldCount-- + } + + if t.Region == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { + return err + } + + // t.LexiconTypeID (string) (string) + if len("$type") > 8192 { + return xerrors.Errorf("Value in field \"$type\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { + return err + } + if _, err := cw.WriteString(string("$type")); err != nil { + return err + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.hold.captain"))); err != nil { + return err + } + if _, err := cw.WriteString(string("io.atcr.hold.captain")); err != nil { + return err + } + + // t.Owner (string) (string) + if len("owner") > 8192 { + return xerrors.Errorf("Value in field \"owner\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("owner"))); err != nil { + return err + } + if _, err := cw.WriteString(string("owner")); err != nil { + return err + } + + if len(t.Owner) > 8192 { + return xerrors.Errorf("Value in field t.Owner was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Owner))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.Owner)); err != nil { + return err + } + + // t.Public (bool) (bool) + if len("public") > 8192 { + return xerrors.Errorf("Value in field \"public\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("public"))); err != nil { + return err + } + if _, err := cw.WriteString(string("public")); err != nil { + return err + } + + if err := cbg.WriteBool(w, t.Public); err != nil { + return err + } + + // t.Region (string) (string) + if t.Region != nil { + + if len("region") > 8192 { + return xerrors.Errorf("Value in field \"region\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("region"))); err != nil { + return err + } + if _, err := cw.WriteString(string("region")); err != nil { + return err + } + + if t.Region == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.Region) > 8192 { + return xerrors.Errorf("Value in field t.Region was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Region))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.Region)); err != nil { + return err + } + } + } + + // t.Provider (string) (string) + if t.Provider != nil { + + if len("provider") > 8192 { + return xerrors.Errorf("Value in field \"provider\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("provider"))); err != nil { + return err + } + if _, err := cw.WriteString(string("provider")); err != nil { + return err + } + + if t.Provider == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.Provider) > 8192 { + return xerrors.Errorf("Value in field t.Provider was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Provider))); err != nil { + return err + } + if _, err := cw.WriteString(string(*t.Provider)); err != nil { + return err + } + } + } + + // t.DeployedAt (string) (string) + if len("deployedAt") > 8192 { + return xerrors.Errorf("Value in field \"deployedAt\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("deployedAt"))); err != nil { + return err + } + if _, err := cw.WriteString(string("deployedAt")); err != nil { + return err + } + + if len(t.DeployedAt) > 8192 { + return xerrors.Errorf("Value in field t.DeployedAt was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.DeployedAt))); err != nil { + return err + } + if _, err := cw.WriteString(string(t.DeployedAt)); err != nil { + return err + } + + // t.AllowAllCrew (bool) (bool) + if len("allowAllCrew") > 8192 { + return xerrors.Errorf("Value in field \"allowAllCrew\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("allowAllCrew"))); err != nil { + return err + } + if _, err := cw.WriteString(string("allowAllCrew")); err != nil { + return err + } + + if err := cbg.WriteBool(w, t.AllowAllCrew); err != nil { + return err + } + + // t.EnableBlueskyPosts (bool) (bool) + if len("enableBlueskyPosts") > 8192 { + return xerrors.Errorf("Value in field \"enableBlueskyPosts\" was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("enableBlueskyPosts"))); err != nil { + return err + } + if _, err := cw.WriteString(string("enableBlueskyPosts")); err != nil { + return err + } + + if err := cbg.WriteBool(w, t.EnableBlueskyPosts); err != nil { + return err + } + return nil +} + +func (t *HoldCaptain) UnmarshalCBOR(r io.Reader) (err error) { + *t = HoldCaptain{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") + } + + if extra > cbg.MaxLength { + return fmt.Errorf("HoldCaptain: map struct too large (%d)", extra) + } + + n := extra + + nameBuf := make([]byte, 18) + for i := uint64(0); i < n; i++ { + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) + if err != nil { + return err + } + + if !ok { + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { + return err + } + continue + } + + switch string(nameBuf[:nameLen]) { + // t.LexiconTypeID (string) (string) + case "$type": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.LexiconTypeID = string(sval) + } + // t.Owner (string) (string) + case "owner": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.Owner = string(sval) + } + // t.Public (bool) (bool) + case "public": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + if maj != cbg.MajOther { + return fmt.Errorf("booleans must be major type 7") + } + switch extra { + case 20: + t.Public = false + case 21: + t.Public = true + default: + return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) + } + // t.Region (string) (string) + case "region": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.Region = (*string)(&sval) + } + } + // t.Provider (string) (string) + case "provider": + + { + b, err := cr.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := cr.UnreadByte(); err != nil { + return err + } + + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.Provider = (*string)(&sval) + } + } + // t.DeployedAt (string) (string) + case "deployedAt": + + { + sval, err := cbg.ReadStringWithMax(cr, 8192) + if err != nil { + return err + } + + t.DeployedAt = string(sval) + } + // t.AllowAllCrew (bool) (bool) + case "allowAllCrew": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + if maj != cbg.MajOther { + return fmt.Errorf("booleans must be major type 7") + } + switch extra { + case 20: + t.AllowAllCrew = false + case 21: + t.AllowAllCrew = true + default: + return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) + } + // t.EnableBlueskyPosts (bool) (bool) + case "enableBlueskyPosts": + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + if maj != cbg.MajOther { + return fmt.Errorf("booleans must be major type 7") + } + switch extra { + case 20: + t.EnableBlueskyPosts = false + case 21: + t.EnableBlueskyPosts = true + default: + return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) + } + + default: + // Field doesn't exist on this type, so ignore it + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { + return err + } + } + } + + return nil +} +func (t *HoldCrew) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err @@ -53,7 +3246,7 @@ func (t *CrewRecord) MarshalCBOR(w io.Writer) error { return err } - // t.Type (string) (string) + // t.LexiconTypeID (string) (string) if len("$type") > 8192 { return xerrors.Errorf("Value in field \"$type\" was too long") } @@ -65,14 +3258,10 @@ func (t *CrewRecord) MarshalCBOR(w io.Writer) error { return err } - if len(t.Type) > 8192 { - return xerrors.Errorf("Value in field t.Type was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Type))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.hold.crew"))); err != nil { return err } - if _, err := cw.WriteString(string(t.Type)); err != nil { + if _, err := cw.WriteString(string("io.atcr.hold.crew")); err != nil { return err } @@ -157,8 +3346,8 @@ func (t *CrewRecord) MarshalCBOR(w io.Writer) error { return nil } -func (t *CrewRecord) UnmarshalCBOR(r io.Reader) (err error) { - *t = CrewRecord{} +func (t *HoldCrew) UnmarshalCBOR(r io.Reader) (err error) { + *t = HoldCrew{} cr := cbg.NewCborReader(r) @@ -177,7 +3366,7 @@ func (t *CrewRecord) UnmarshalCBOR(r io.Reader) (err error) { } if extra > cbg.MaxLength { - return fmt.Errorf("CrewRecord: map struct too large (%d)", extra) + return fmt.Errorf("HoldCrew: map struct too large (%d)", extra) } n := extra @@ -209,7 +3398,7 @@ func (t *CrewRecord) UnmarshalCBOR(r io.Reader) (err error) { t.Role = string(sval) } - // t.Type (string) (string) + // t.LexiconTypeID (string) (string) case "$type": { @@ -218,7 +3407,7 @@ func (t *CrewRecord) UnmarshalCBOR(r io.Reader) (err error) { return err } - t.Type = string(sval) + t.LexiconTypeID = string(sval) } // t.Member (string) (string) case "member": @@ -293,360 +3482,7 @@ func (t *CrewRecord) UnmarshalCBOR(r io.Reader) (err error) { return nil } -func (t *CaptainRecord) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - - cw := cbg.NewCborWriter(w) - fieldCount := 8 - - if t.Region == "" { - fieldCount-- - } - - if t.Provider == "" { - fieldCount-- - } - - if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { - return err - } - - // t.Type (string) (string) - if len("$type") > 8192 { - return xerrors.Errorf("Value in field \"$type\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { - return err - } - if _, err := cw.WriteString(string("$type")); err != nil { - return err - } - - if len(t.Type) > 8192 { - return xerrors.Errorf("Value in field t.Type was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Type))); err != nil { - return err - } - if _, err := cw.WriteString(string(t.Type)); err != nil { - return err - } - - // t.Owner (string) (string) - if len("owner") > 8192 { - return xerrors.Errorf("Value in field \"owner\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("owner"))); err != nil { - return err - } - if _, err := cw.WriteString(string("owner")); err != nil { - return err - } - - if len(t.Owner) > 8192 { - return xerrors.Errorf("Value in field t.Owner was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Owner))); err != nil { - return err - } - if _, err := cw.WriteString(string(t.Owner)); err != nil { - return err - } - - // t.Public (bool) (bool) - if len("public") > 8192 { - return xerrors.Errorf("Value in field \"public\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("public"))); err != nil { - return err - } - if _, err := cw.WriteString(string("public")); err != nil { - return err - } - - if err := cbg.WriteBool(w, t.Public); err != nil { - return err - } - - // t.Region (string) (string) - if t.Region != "" { - - if len("region") > 8192 { - return xerrors.Errorf("Value in field \"region\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("region"))); err != nil { - return err - } - if _, err := cw.WriteString(string("region")); err != nil { - return err - } - - if len(t.Region) > 8192 { - return xerrors.Errorf("Value in field t.Region was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Region))); err != nil { - return err - } - if _, err := cw.WriteString(string(t.Region)); err != nil { - return err - } - } - - // t.Provider (string) (string) - if t.Provider != "" { - - if len("provider") > 8192 { - return xerrors.Errorf("Value in field \"provider\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("provider"))); err != nil { - return err - } - if _, err := cw.WriteString(string("provider")); err != nil { - return err - } - - if len(t.Provider) > 8192 { - return xerrors.Errorf("Value in field t.Provider was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Provider))); err != nil { - return err - } - if _, err := cw.WriteString(string(t.Provider)); err != nil { - return err - } - } - - // t.DeployedAt (string) (string) - if len("deployedAt") > 8192 { - return xerrors.Errorf("Value in field \"deployedAt\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("deployedAt"))); err != nil { - return err - } - if _, err := cw.WriteString(string("deployedAt")); err != nil { - return err - } - - if len(t.DeployedAt) > 8192 { - return xerrors.Errorf("Value in field t.DeployedAt was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.DeployedAt))); err != nil { - return err - } - if _, err := cw.WriteString(string(t.DeployedAt)); err != nil { - return err - } - - // t.AllowAllCrew (bool) (bool) - if len("allowAllCrew") > 8192 { - return xerrors.Errorf("Value in field \"allowAllCrew\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("allowAllCrew"))); err != nil { - return err - } - if _, err := cw.WriteString(string("allowAllCrew")); err != nil { - return err - } - - if err := cbg.WriteBool(w, t.AllowAllCrew); err != nil { - return err - } - - // t.EnableBlueskyPosts (bool) (bool) - if len("enableBlueskyPosts") > 8192 { - return xerrors.Errorf("Value in field \"enableBlueskyPosts\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("enableBlueskyPosts"))); err != nil { - return err - } - if _, err := cw.WriteString(string("enableBlueskyPosts")); err != nil { - return err - } - - if err := cbg.WriteBool(w, t.EnableBlueskyPosts); err != nil { - return err - } - return nil -} - -func (t *CaptainRecord) UnmarshalCBOR(r io.Reader) (err error) { - *t = CaptainRecord{} - - cr := cbg.NewCborReader(r) - - maj, extra, err := cr.ReadHeader() - if err != nil { - return err - } - defer func() { - if err == io.EOF { - err = io.ErrUnexpectedEOF - } - }() - - if maj != cbg.MajMap { - return fmt.Errorf("cbor input should be of type map") - } - - if extra > cbg.MaxLength { - return fmt.Errorf("CaptainRecord: map struct too large (%d)", extra) - } - - n := extra - - nameBuf := make([]byte, 18) - for i := uint64(0); i < n; i++ { - nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) - if err != nil { - return err - } - - if !ok { - // Field doesn't exist on this type, so ignore it - if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { - return err - } - continue - } - - switch string(nameBuf[:nameLen]) { - // t.Type (string) (string) - case "$type": - - { - sval, err := cbg.ReadStringWithMax(cr, 8192) - if err != nil { - return err - } - - t.Type = string(sval) - } - // t.Owner (string) (string) - case "owner": - - { - sval, err := cbg.ReadStringWithMax(cr, 8192) - if err != nil { - return err - } - - t.Owner = string(sval) - } - // t.Public (bool) (bool) - case "public": - - maj, extra, err = cr.ReadHeader() - if err != nil { - return err - } - if maj != cbg.MajOther { - return fmt.Errorf("booleans must be major type 7") - } - switch extra { - case 20: - t.Public = false - case 21: - t.Public = true - default: - return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) - } - // t.Region (string) (string) - case "region": - - { - sval, err := cbg.ReadStringWithMax(cr, 8192) - if err != nil { - return err - } - - t.Region = string(sval) - } - // t.Provider (string) (string) - case "provider": - - { - sval, err := cbg.ReadStringWithMax(cr, 8192) - if err != nil { - return err - } - - t.Provider = string(sval) - } - // t.DeployedAt (string) (string) - case "deployedAt": - - { - sval, err := cbg.ReadStringWithMax(cr, 8192) - if err != nil { - return err - } - - t.DeployedAt = string(sval) - } - // t.AllowAllCrew (bool) (bool) - case "allowAllCrew": - - maj, extra, err = cr.ReadHeader() - if err != nil { - return err - } - if maj != cbg.MajOther { - return fmt.Errorf("booleans must be major type 7") - } - switch extra { - case 20: - t.AllowAllCrew = false - case 21: - t.AllowAllCrew = true - default: - return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) - } - // t.EnableBlueskyPosts (bool) (bool) - case "enableBlueskyPosts": - - maj, extra, err = cr.ReadHeader() - if err != nil { - return err - } - if maj != cbg.MajOther { - return fmt.Errorf("booleans must be major type 7") - } - switch extra { - case 20: - t.EnableBlueskyPosts = false - case 21: - t.EnableBlueskyPosts = true - default: - return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) - } - - default: - // Field doesn't exist on this type, so ignore it - if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { - return err - } - } - } - - return nil -} -func (t *LayerRecord) MarshalCBOR(w io.Writer) error { +func (t *HoldLayer) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err @@ -680,7 +3516,7 @@ func (t *LayerRecord) MarshalCBOR(w io.Writer) error { } } - // t.Type (string) (string) + // t.LexiconTypeID (string) (string) if len("$type") > 8192 { return xerrors.Errorf("Value in field \"$type\" was too long") } @@ -692,14 +3528,10 @@ func (t *LayerRecord) MarshalCBOR(w io.Writer) error { return err } - if len(t.Type) > 8192 { - return xerrors.Errorf("Value in field t.Type was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Type))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.hold.layer"))); err != nil { return err } - if _, err := cw.WriteString(string(t.Type)); err != nil { + if _, err := cw.WriteString(string("io.atcr.hold.layer")); err != nil { return err } @@ -726,7 +3558,7 @@ func (t *LayerRecord) MarshalCBOR(w io.Writer) error { return err } - // t.UserDID (string) (string) + // t.UserDid (string) (string) if len("userDid") > 8192 { return xerrors.Errorf("Value in field \"userDid\" was too long") } @@ -738,14 +3570,14 @@ func (t *LayerRecord) MarshalCBOR(w io.Writer) error { return err } - if len(t.UserDID) > 8192 { - return xerrors.Errorf("Value in field t.UserDID was too long") + if len(t.UserDid) > 8192 { + return xerrors.Errorf("Value in field t.UserDid was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.UserDID))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.UserDid))); err != nil { return err } - if _, err := cw.WriteString(string(t.UserDID)); err != nil { + if _, err := cw.WriteString(string(t.UserDid)); err != nil { return err } @@ -843,8 +3675,8 @@ func (t *LayerRecord) MarshalCBOR(w io.Writer) error { return nil } -func (t *LayerRecord) UnmarshalCBOR(r io.Reader) (err error) { - *t = LayerRecord{} +func (t *HoldLayer) UnmarshalCBOR(r io.Reader) (err error) { + *t = HoldLayer{} cr := cbg.NewCborReader(r) @@ -863,7 +3695,7 @@ func (t *LayerRecord) UnmarshalCBOR(r io.Reader) (err error) { } if extra > cbg.MaxLength { - return fmt.Errorf("LayerRecord: map struct too large (%d)", extra) + return fmt.Errorf("HoldLayer: map struct too large (%d)", extra) } n := extra @@ -910,7 +3742,7 @@ func (t *LayerRecord) UnmarshalCBOR(r io.Reader) (err error) { t.Size = int64(extraI) } - // t.Type (string) (string) + // t.LexiconTypeID (string) (string) case "$type": { @@ -919,7 +3751,7 @@ func (t *LayerRecord) UnmarshalCBOR(r io.Reader) (err error) { return err } - t.Type = string(sval) + t.LexiconTypeID = string(sval) } // t.Digest (string) (string) case "digest": @@ -932,7 +3764,7 @@ func (t *LayerRecord) UnmarshalCBOR(r io.Reader) (err error) { t.Digest = string(sval) } - // t.UserDID (string) (string) + // t.UserDid (string) (string) case "userDid": { @@ -941,7 +3773,7 @@ func (t *LayerRecord) UnmarshalCBOR(r io.Reader) (err error) { return err } - t.UserDID = string(sval) + t.UserDid = string(sval) } // t.CreatedAt (string) (string) case "createdAt": diff --git a/pkg/atproto/generate.go b/pkg/atproto/generate.go index c29fd79..7ee03ed 100644 --- a/pkg/atproto/generate.go +++ b/pkg/atproto/generate.go @@ -3,17 +3,194 @@ package main -// CBOR Code Generator +// Lexicon and CBOR Code Generator // -// This generates optimized CBOR marshaling code for ATProto records. +// This generates: +// 1. Go types from lexicon JSON files (via lex/lexgen library) +// 2. CBOR marshaling code for ATProto records (via cbor-gen) +// 3. Type registration for lexutil (register.go) // // Usage: // go generate ./pkg/atproto/... // -// This creates pkg/atproto/cbor_gen.go which should be committed to git. -// Only re-run when you modify types in pkg/atproto/types.go -// -// The //go:generate directive is in lexicon.go +// Key insight: We use RegisterLexiconTypeID: false to avoid generating init() +// blocks that require CBORMarshaler. This breaks the circular dependency between +// lexgen and cbor-gen. See: https://github.com/bluesky-social/indigo/issues/931 + +import ( + "bytes" + "encoding/json" + "fmt" + "os" + "os/exec" + "path/filepath" + "strings" + + "github.com/bluesky-social/indigo/atproto/lexicon" + "github.com/bluesky-social/indigo/lex/lexgen" + "golang.org/x/tools/imports" +) + +func main() { + // Find repo root + repoRoot, err := findRepoRoot() + if err != nil { + fmt.Printf("failed to find repo root: %v\n", err) + os.Exit(1) + } + + pkgDir := filepath.Join(repoRoot, "pkg/atproto") + lexDir := filepath.Join(repoRoot, "lexicons") + + // Step 0: Clean up old register.go to avoid conflicts + // (It will be regenerated at the end) + os.Remove(filepath.Join(pkgDir, "register.go")) + + // Step 1: Load all lexicon schemas into catalog (for cross-references) + fmt.Println("Loading lexicons...") + cat := lexicon.NewBaseCatalog() + if err := cat.LoadDirectory(lexDir); err != nil { + fmt.Printf("failed to load lexicons: %v\n", err) + os.Exit(1) + } + + // Step 2: Generate Go code for each lexicon file + fmt.Println("Running lexgen...") + config := &lexgen.GenConfig{ + RegisterLexiconTypeID: false, // KEY: no init() blocks generated + UnknownType: "map-string-any", + WarningText: "Code generated by generate.go; DO NOT EDIT.", + } + + // Track generated types for register.go + var registeredTypes []typeInfo + + // Walk lexicon directory and generate code for each file + err = filepath.Walk(lexDir, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if info.IsDir() || !strings.HasSuffix(path, ".json") { + return nil + } + + // Load and parse the schema file + data, err := os.ReadFile(path) + if err != nil { + return fmt.Errorf("failed to read %s: %w", path, err) + } + + var sf lexicon.SchemaFile + if err := json.Unmarshal(data, &sf); err != nil { + return fmt.Errorf("failed to parse %s: %w", path, err) + } + + if err := sf.FinishParse(); err != nil { + return fmt.Errorf("failed to finish parse %s: %w", path, err) + } + + // Flatten the schema + flat, err := lexgen.FlattenSchemaFile(&sf) + if err != nil { + return fmt.Errorf("failed to flatten schema %s: %w", path, err) + } + + // Generate code + var buf bytes.Buffer + gen := &lexgen.CodeGenerator{ + Config: config, + Lex: flat, + Cat: &cat, + Out: &buf, + } + + if err := gen.WriteLexicon(); err != nil { + return fmt.Errorf("failed to generate code for %s: %w", path, err) + } + + // Fix package name: lexgen generates "ioatcr" but we want "atproto" + code := bytes.Replace(buf.Bytes(), []byte("package ioatcr"), []byte("package atproto"), 1) + + // Format with goimports + fileName := gen.FileName() + formatted, err := imports.Process(fileName, code, nil) + if err != nil { + // Write unformatted for debugging + outPath := filepath.Join(pkgDir, fileName) + os.WriteFile(outPath+".broken", code, 0644) + return fmt.Errorf("failed to format %s: %w (wrote to %s.broken)", fileName, err, outPath) + } + + // Write output file + outPath := filepath.Join(pkgDir, fileName) + if err := os.WriteFile(outPath, formatted, 0644); err != nil { + return fmt.Errorf("failed to write %s: %w", outPath, err) + } + + fmt.Printf(" Generated %s\n", fileName) + + // Track type for registration - compute type name from NSID + typeName := nsidToTypeName(sf.ID) + registeredTypes = append(registeredTypes, typeInfo{ + NSID: sf.ID, + TypeName: typeName, + }) + + return nil + }) + if err != nil { + fmt.Printf("lexgen failed: %v\n", err) + os.Exit(1) + } + + // Step 3: Run cbor-gen via exec.Command + // This must be a separate process so it can compile the freshly generated types + fmt.Println("Running cbor-gen...") + if err := runCborGen(repoRoot, pkgDir); err != nil { + fmt.Printf("cbor-gen failed: %v\n", err) + os.Exit(1) + } + + // Step 4: Generate register.go + fmt.Println("Generating register.go...") + if err := generateRegisterFile(pkgDir, registeredTypes); err != nil { + fmt.Printf("failed to generate register.go: %v\n", err) + os.Exit(1) + } + + fmt.Println("Code generation complete!") +} + +type typeInfo struct { + NSID string + TypeName string +} + +// nsidToTypeName converts an NSID to a Go type name +// io.atcr.manifest → Manifest +// io.atcr.hold.captain → HoldCaptain +// io.atcr.sailor.profile → SailorProfile +func nsidToTypeName(nsid string) string { + parts := strings.Split(nsid, ".") + if len(parts) < 3 { + return "" + } + // Skip the first two parts (authority, e.g., "io.atcr") + // and capitalize each remaining part + var result string + for _, part := range parts[2:] { + if len(part) > 0 { + result += strings.ToUpper(part[:1]) + part[1:] + } + } + return result +} + +func runCborGen(repoRoot, pkgDir string) error { + // Create a temporary Go file that runs cbor-gen + cborGenCode := `//go:build ignore + +package main import ( "fmt" @@ -25,14 +202,81 @@ import ( ) func main() { - // Generate map-style encoders for CrewRecord, CaptainRecord, LayerRecord, and TangledProfileRecord if err := cbg.WriteMapEncodersToFile("cbor_gen.go", "atproto", - atproto.CrewRecord{}, - atproto.CaptainRecord{}, - atproto.LayerRecord{}, + // Manifest types + atproto.Manifest{}, + atproto.Manifest_BlobReference{}, + atproto.Manifest_ManifestReference{}, + atproto.Manifest_Platform{}, + atproto.Manifest_Annotations{}, + atproto.Manifest_BlobReference_Annotations{}, + atproto.Manifest_ManifestReference_Annotations{}, + // Tag + atproto.Tag{}, + // Sailor types + atproto.SailorProfile{}, + atproto.SailorStar{}, + atproto.SailorStar_Subject{}, + // Hold types + atproto.HoldCaptain{}, + atproto.HoldCrew{}, + atproto.HoldLayer{}, + // External types atproto.TangledProfileRecord{}, ); err != nil { - fmt.Printf("Failed to generate CBOR encoders: %v\n", err) + fmt.Printf("cbor-gen failed: %v\n", err) os.Exit(1) } } +` + + // Write temp file + tmpFile := filepath.Join(pkgDir, "cborgen_tmp.go") + if err := os.WriteFile(tmpFile, []byte(cborGenCode), 0644); err != nil { + return fmt.Errorf("failed to write temp cbor-gen file: %w", err) + } + defer os.Remove(tmpFile) + + // Run it + cmd := exec.Command("go", "run", tmpFile) + cmd.Dir = pkgDir + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + return cmd.Run() +} + +func generateRegisterFile(pkgDir string, types []typeInfo) error { + var buf bytes.Buffer + + buf.WriteString("// Code generated by generate.go; DO NOT EDIT.\n\n") + buf.WriteString("package atproto\n\n") + buf.WriteString("import lexutil \"github.com/bluesky-social/indigo/lex/util\"\n\n") + buf.WriteString("func init() {\n") + + for _, t := range types { + fmt.Fprintf(&buf, "\tlexutil.RegisterType(%q, &%s{})\n", t.NSID, t.TypeName) + } + + buf.WriteString("}\n") + + outPath := filepath.Join(pkgDir, "register.go") + return os.WriteFile(outPath, buf.Bytes(), 0644) +} + +func findRepoRoot() (string, error) { + dir, err := os.Getwd() + if err != nil { + return "", err + } + + for { + if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil { + return dir, nil + } + parent := filepath.Dir(dir) + if parent == dir { + return "", fmt.Errorf("go.mod not found") + } + dir = parent + } +} diff --git a/pkg/atproto/holdcaptain.go b/pkg/atproto/holdcaptain.go new file mode 100644 index 0000000..4533c65 --- /dev/null +++ b/pkg/atproto/holdcaptain.go @@ -0,0 +1,24 @@ +// Code generated by generate.go; DO NOT EDIT. + +// Lexicon schema: io.atcr.hold.captain + +package atproto + +// Represents the hold's ownership and metadata. Stored as a singleton record at rkey 'self' in the hold's embedded PDS. +type HoldCaptain struct { + LexiconTypeID string `json:"$type" cborgen:"$type,const=io.atcr.hold.captain"` + // allowAllCrew: Allow any authenticated user to register as crew + AllowAllCrew bool `json:"allowAllCrew" cborgen:"allowAllCrew"` + // deployedAt: RFC3339 timestamp of when the hold was deployed + DeployedAt string `json:"deployedAt" cborgen:"deployedAt"` + // enableBlueskyPosts: Enable Bluesky posts when manifests are pushed + EnableBlueskyPosts bool `json:"enableBlueskyPosts" cborgen:"enableBlueskyPosts"` + // owner: DID of the hold owner + Owner string `json:"owner" cborgen:"owner"` + // provider: Deployment provider (e.g., fly.io, aws, etc.) + Provider *string `json:"provider,omitempty" cborgen:"provider,omitempty"` + // public: Whether this hold allows public blob reads (pulls) without authentication + Public bool `json:"public" cborgen:"public"` + // region: S3 region where blobs are stored + Region *string `json:"region,omitempty" cborgen:"region,omitempty"` +} diff --git a/pkg/atproto/holdcrew.go b/pkg/atproto/holdcrew.go new file mode 100644 index 0000000..3a48eab --- /dev/null +++ b/pkg/atproto/holdcrew.go @@ -0,0 +1,18 @@ +// Code generated by generate.go; DO NOT EDIT. + +// Lexicon schema: io.atcr.hold.crew + +package atproto + +// Crew member in a hold's embedded PDS. Grants access permissions to push blobs to the hold. Stored in the hold's embedded PDS (one record per member). +type HoldCrew struct { + LexiconTypeID string `json:"$type" cborgen:"$type,const=io.atcr.hold.crew"` + // addedAt: RFC3339 timestamp of when the member was added + AddedAt string `json:"addedAt" cborgen:"addedAt"` + // member: DID of the crew member + Member string `json:"member" cborgen:"member"` + // permissions: Specific permissions granted to this member + Permissions []string `json:"permissions" cborgen:"permissions"` + // role: Member's role in the hold + Role string `json:"role" cborgen:"role"` +} diff --git a/pkg/atproto/holdlayer.go b/pkg/atproto/holdlayer.go new file mode 100644 index 0000000..2b51725 --- /dev/null +++ b/pkg/atproto/holdlayer.go @@ -0,0 +1,24 @@ +// Code generated by generate.go; DO NOT EDIT. + +// Lexicon schema: io.atcr.hold.layer + +package atproto + +// Represents metadata about a container layer stored in the hold. Stored in the hold's embedded PDS for tracking and analytics. +type HoldLayer struct { + LexiconTypeID string `json:"$type" cborgen:"$type,const=io.atcr.hold.layer"` + // createdAt: RFC3339 timestamp of when the layer was uploaded + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + // digest: Layer digest (e.g., sha256:abc123...) + Digest string `json:"digest" cborgen:"digest"` + // mediaType: Media type (e.g., application/vnd.oci.image.layer.v1.tar+gzip) + MediaType string `json:"mediaType" cborgen:"mediaType"` + // repository: Repository this layer belongs to + Repository string `json:"repository" cborgen:"repository"` + // size: Size in bytes + Size int64 `json:"size" cborgen:"size"` + // userDid: DID of user who uploaded this layer + UserDid string `json:"userDid" cborgen:"userDid"` + // userHandle: Handle of user (for display purposes) + UserHandle string `json:"userHandle" cborgen:"userHandle"` +} diff --git a/pkg/atproto/manifest.go b/pkg/atproto/manifest.go new file mode 100644 index 0000000..3f7fa87 --- /dev/null +++ b/pkg/atproto/manifest.go @@ -0,0 +1,103 @@ +// Code generated by generate.go; DO NOT EDIT. + +// Lexicon schema: io.atcr.manifest + +package atproto + +import ( + lexutil "github.com/bluesky-social/indigo/lex/util" +) + +// A container image manifest following OCI specification, stored in ATProto +type Manifest struct { + LexiconTypeID string `json:"$type" cborgen:"$type,const=io.atcr.manifest"` + // annotations: Optional metadata annotations + Annotations *Manifest_Annotations `json:"annotations,omitempty" cborgen:"annotations,omitempty"` + // config: Reference to image configuration blob + Config *Manifest_BlobReference `json:"config,omitempty" cborgen:"config,omitempty"` + // createdAt: Record creation timestamp + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + // digest: Content digest (e.g., 'sha256:abc123...') + Digest string `json:"digest" cborgen:"digest"` + // holdDid: DID of the hold service where blobs are stored (e.g., 'did:web:hold01.atcr.io'). Primary reference for hold resolution. + HoldDid *string `json:"holdDid,omitempty" cborgen:"holdDid,omitempty"` + // holdEndpoint: Hold service endpoint URL where blobs are stored. DEPRECATED: Use holdDid instead. Kept for backward compatibility. + HoldEndpoint *string `json:"holdEndpoint,omitempty" cborgen:"holdEndpoint,omitempty"` + // layers: Filesystem layers (for image manifests) + Layers []Manifest_BlobReference `json:"layers,omitempty" cborgen:"layers,omitempty"` + // manifestBlob: The full OCI manifest stored as a blob in ATProto. + ManifestBlob *lexutil.LexBlob `json:"manifestBlob,omitempty" cborgen:"manifestBlob,omitempty"` + // manifests: Referenced manifests (for manifest lists/indexes) + Manifests []Manifest_ManifestReference `json:"manifests,omitempty" cborgen:"manifests,omitempty"` + // mediaType: OCI media type + MediaType string `json:"mediaType" cborgen:"mediaType"` + // repository: Repository name (e.g., 'myapp'). Scoped to user's DID. + Repository string `json:"repository" cborgen:"repository"` + // schemaVersion: OCI schema version (typically 2) + SchemaVersion int64 `json:"schemaVersion" cborgen:"schemaVersion"` + // subject: Optional reference to another manifest (for attestations, signatures) + Subject *Manifest_BlobReference `json:"subject,omitempty" cborgen:"subject,omitempty"` +} + +// Optional metadata annotations +type Manifest_Annotations struct { +} + +// Manifest_BlobReference is a "blobReference" in the io.atcr.manifest schema. +// +// Reference to a blob stored in S3 or external storage +type Manifest_BlobReference struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,const=io.atcr.manifest#blobReference,omitempty"` + // annotations: Optional metadata + Annotations *Manifest_BlobReference_Annotations `json:"annotations,omitempty" cborgen:"annotations,omitempty"` + // digest: Content digest (e.g., 'sha256:...') + Digest string `json:"digest" cborgen:"digest"` + // mediaType: MIME type of the blob + MediaType string `json:"mediaType" cborgen:"mediaType"` + // size: Size in bytes + Size int64 `json:"size" cborgen:"size"` + // urls: Optional direct URLs to blob (for BYOS) + Urls []string `json:"urls,omitempty" cborgen:"urls,omitempty"` +} + +// Optional metadata +type Manifest_BlobReference_Annotations struct { +} + +// Manifest_ManifestReference is a "manifestReference" in the io.atcr.manifest schema. +// +// Reference to a manifest in a manifest list/index +type Manifest_ManifestReference struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,const=io.atcr.manifest#manifestReference,omitempty"` + // annotations: Optional metadata + Annotations *Manifest_ManifestReference_Annotations `json:"annotations,omitempty" cborgen:"annotations,omitempty"` + // digest: Content digest (e.g., 'sha256:...') + Digest string `json:"digest" cborgen:"digest"` + // mediaType: Media type of the referenced manifest + MediaType string `json:"mediaType" cborgen:"mediaType"` + // platform: Platform information for this manifest + Platform *Manifest_Platform `json:"platform,omitempty" cborgen:"platform,omitempty"` + // size: Size in bytes + Size int64 `json:"size" cborgen:"size"` +} + +// Optional metadata +type Manifest_ManifestReference_Annotations struct { +} + +// Manifest_Platform is a "platform" in the io.atcr.manifest schema. +// +// Platform information describing OS and architecture +type Manifest_Platform struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,const=io.atcr.manifest#platform,omitempty"` + // architecture: CPU architecture (e.g., 'amd64', 'arm64', 'arm') + Architecture string `json:"architecture" cborgen:"architecture"` + // os: Operating system (e.g., 'linux', 'windows', 'darwin') + Os string `json:"os" cborgen:"os"` + // osFeatures: Optional OS features + OsFeatures []string `json:"osFeatures,omitempty" cborgen:"osFeatures,omitempty"` + // osVersion: Optional OS version + OsVersion *string `json:"osVersion,omitempty" cborgen:"osVersion,omitempty"` + // variant: Optional CPU variant (e.g., 'v7' for ARM) + Variant *string `json:"variant,omitempty" cborgen:"variant,omitempty"` +} diff --git a/pkg/atproto/register.go b/pkg/atproto/register.go new file mode 100644 index 0000000..19850eb --- /dev/null +++ b/pkg/atproto/register.go @@ -0,0 +1,15 @@ +// Code generated by generate.go; DO NOT EDIT. + +package atproto + +import lexutil "github.com/bluesky-social/indigo/lex/util" + +func init() { + lexutil.RegisterType("io.atcr.hold.captain", &HoldCaptain{}) + lexutil.RegisterType("io.atcr.hold.crew", &HoldCrew{}) + lexutil.RegisterType("io.atcr.hold.layer", &HoldLayer{}) + lexutil.RegisterType("io.atcr.manifest", &Manifest{}) + lexutil.RegisterType("io.atcr.sailor.profile", &SailorProfile{}) + lexutil.RegisterType("io.atcr.sailor.star", &SailorStar{}) + lexutil.RegisterType("io.atcr.tag", &Tag{}) +} diff --git a/pkg/atproto/sailorprofile.go b/pkg/atproto/sailorprofile.go new file mode 100644 index 0000000..70e8f5d --- /dev/null +++ b/pkg/atproto/sailorprofile.go @@ -0,0 +1,16 @@ +// Code generated by generate.go; DO NOT EDIT. + +// Lexicon schema: io.atcr.sailor.profile + +package atproto + +// User profile for ATCR registry. Stores preferences like default hold for blob storage. +type SailorProfile struct { + LexiconTypeID string `json:"$type" cborgen:"$type,const=io.atcr.sailor.profile"` + // createdAt: Profile creation timestamp + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + // defaultHold: Default hold endpoint for blob storage. If null, user has opted out of defaults. + DefaultHold *string `json:"defaultHold,omitempty" cborgen:"defaultHold,omitempty"` + // updatedAt: Profile last updated timestamp + UpdatedAt *string `json:"updatedAt,omitempty" cborgen:"updatedAt,omitempty"` +} diff --git a/pkg/atproto/sailorstar.go b/pkg/atproto/sailorstar.go new file mode 100644 index 0000000..67570a1 --- /dev/null +++ b/pkg/atproto/sailorstar.go @@ -0,0 +1,25 @@ +// Code generated by generate.go; DO NOT EDIT. + +// Lexicon schema: io.atcr.sailor.star + +package atproto + +// A star (like) on a container image repository. Stored in the starrer's PDS, similar to Bluesky likes. +type SailorStar struct { + LexiconTypeID string `json:"$type" cborgen:"$type,const=io.atcr.sailor.star"` + // createdAt: Star creation timestamp + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + // subject: The repository being starred + Subject SailorStar_Subject `json:"subject" cborgen:"subject"` +} + +// SailorStar_Subject is a "subject" in the io.atcr.sailor.star schema. +// +// Reference to a repository owned by a user +type SailorStar_Subject struct { + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,const=io.atcr.sailor.star#subject,omitempty"` + // did: DID of the repository owner + Did string `json:"did" cborgen:"did"` + // repository: Repository name (e.g., 'myapp') + Repository string `json:"repository" cborgen:"repository"` +} diff --git a/pkg/atproto/tag.go b/pkg/atproto/tag.go new file mode 100644 index 0000000..7886d42 --- /dev/null +++ b/pkg/atproto/tag.go @@ -0,0 +1,20 @@ +// Code generated by generate.go; DO NOT EDIT. + +// Lexicon schema: io.atcr.tag + +package atproto + +// A named tag pointing to a specific manifest digest +type Tag struct { + LexiconTypeID string `json:"$type" cborgen:"$type,const=io.atcr.tag"` + // createdAt: Tag creation timestamp + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + // manifest: AT-URI of the manifest this tag points to (e.g., 'at://did:plc:xyz/io.atcr.manifest/abc123'). Preferred over manifestDigest for new records. + Manifest *string `json:"manifest,omitempty" cborgen:"manifest,omitempty"` + // manifestDigest: DEPRECATED: Digest of the manifest (e.g., 'sha256:...'). Kept for backward compatibility with old records. New records should use 'manifest' field instead. + ManifestDigest *string `json:"manifestDigest,omitempty" cborgen:"manifestDigest,omitempty"` + // repository: Repository name (e.g., 'myapp'). Scoped to user's DID. + Repository string `json:"repository" cborgen:"repository"` + // tag: Tag name (e.g., 'latest', 'v1.0.0', '12-slim') + Tag string `json:"tag" cborgen:"tag"` +}