A container registry that uses the AT Protocol for manifest storage and S3 for blob storage.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

lexgen

+3458 -137
+2958 -126
pkg/atproto/cbor_gen.go
··· 8 8 "math" 9 9 "sort" 10 10 11 + util "github.com/bluesky-social/indigo/lex/util" 11 12 cid "github.com/ipfs/go-cid" 12 13 cbg "github.com/whyrusleeping/cbor-gen" 13 14 xerrors "golang.org/x/xerrors" ··· 18 19 var _ = math.E 19 20 var _ = sort.Sort 20 21 21 - func (t *CrewRecord) MarshalCBOR(w io.Writer) error { 22 + func (t *Manifest) MarshalCBOR(w io.Writer) error { 22 23 if t == nil { 23 24 _, err := w.Write(cbg.CborNull) 24 25 return err 25 26 } 26 27 27 28 cw := cbg.NewCborWriter(w) 29 + fieldCount := 14 28 30 29 - if _, err := cw.Write([]byte{165}); err != nil { 30 - return err 31 + if t.Annotations == nil { 32 + fieldCount-- 33 + } 34 + 35 + if t.Config == nil { 36 + fieldCount-- 37 + } 38 + 39 + if t.HoldDid == nil { 40 + fieldCount-- 31 41 } 32 42 33 - // t.Role (string) (string) 34 - if len("role") > 8192 { 35 - return xerrors.Errorf("Value in field \"role\" was too long") 43 + if t.HoldEndpoint == nil { 44 + fieldCount-- 36 45 } 37 46 38 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("role"))); err != nil { 39 - return err 47 + if t.Layers == nil { 48 + fieldCount-- 40 49 } 41 - if _, err := cw.WriteString(string("role")); err != nil { 42 - return err 50 + 51 + if t.ManifestBlob == nil { 52 + fieldCount-- 43 53 } 44 54 45 - if len(t.Role) > 8192 { 46 - return xerrors.Errorf("Value in field t.Role was too long") 55 + if t.Manifests == nil { 56 + fieldCount-- 47 57 } 48 58 49 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Role))); err != nil { 50 - return err 59 + if t.Subject == nil { 60 + fieldCount-- 51 61 } 52 - if _, err := cw.WriteString(string(t.Role)); err != nil { 62 + 63 + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { 53 64 return err 54 65 } 55 66 56 - // t.Type (string) (string) 67 + // t.LexiconTypeID (string) (string) 57 68 if len("$type") > 8192 { 58 69 return xerrors.Errorf("Value in field \"$type\" was too long") 59 70 } ··· 65 76 return err 66 77 } 67 78 68 - if len(t.Type) > 8192 { 69 - return xerrors.Errorf("Value in field t.Type was too long") 79 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.manifest"))); err != nil { 80 + return err 81 + } 82 + if _, err := cw.WriteString(string("io.atcr.manifest")); err != nil { 83 + return err 84 + } 85 + 86 + // t.Config (atproto.Manifest_BlobReference) (struct) 87 + if t.Config != nil { 88 + 89 + if len("config") > 8192 { 90 + return xerrors.Errorf("Value in field \"config\" was too long") 91 + } 92 + 93 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("config"))); err != nil { 94 + return err 95 + } 96 + if _, err := cw.WriteString(string("config")); err != nil { 97 + return err 98 + } 99 + 100 + if err := t.Config.MarshalCBOR(cw); err != nil { 101 + return err 102 + } 70 103 } 71 104 72 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Type))); err != nil { 105 + // t.Digest (string) (string) 106 + if len("digest") > 8192 { 107 + return xerrors.Errorf("Value in field \"digest\" was too long") 108 + } 109 + 110 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("digest"))); err != nil { 73 111 return err 74 112 } 75 - if _, err := cw.WriteString(string(t.Type)); err != nil { 113 + if _, err := cw.WriteString(string("digest")); err != nil { 76 114 return err 77 115 } 78 116 79 - // t.Member (string) (string) 80 - if len("member") > 8192 { 81 - return xerrors.Errorf("Value in field \"member\" was too long") 117 + if len(t.Digest) > 8192 { 118 + return xerrors.Errorf("Value in field t.Digest was too long") 82 119 } 83 120 84 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("member"))); err != nil { 121 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Digest))); err != nil { 85 122 return err 86 123 } 87 - if _, err := cw.WriteString(string("member")); err != nil { 124 + if _, err := cw.WriteString(string(t.Digest)); err != nil { 88 125 return err 89 126 } 90 127 91 - if len(t.Member) > 8192 { 92 - return xerrors.Errorf("Value in field t.Member was too long") 128 + // t.Layers ([]atproto.Manifest_BlobReference) (slice) 129 + if t.Layers != nil { 130 + 131 + if len("layers") > 8192 { 132 + return xerrors.Errorf("Value in field \"layers\" was too long") 133 + } 134 + 135 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("layers"))); err != nil { 136 + return err 137 + } 138 + if _, err := cw.WriteString(string("layers")); err != nil { 139 + return err 140 + } 141 + 142 + if len(t.Layers) > 8192 { 143 + return xerrors.Errorf("Slice value in field t.Layers was too long") 144 + } 145 + 146 + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Layers))); err != nil { 147 + return err 148 + } 149 + for _, v := range t.Layers { 150 + if err := v.MarshalCBOR(cw); err != nil { 151 + return err 152 + } 153 + 154 + } 93 155 } 94 156 95 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Member))); err != nil { 157 + // t.HoldDid (string) (string) 158 + if t.HoldDid != nil { 159 + 160 + if len("holdDid") > 8192 { 161 + return xerrors.Errorf("Value in field \"holdDid\" was too long") 162 + } 163 + 164 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("holdDid"))); err != nil { 165 + return err 166 + } 167 + if _, err := cw.WriteString(string("holdDid")); err != nil { 168 + return err 169 + } 170 + 171 + if t.HoldDid == nil { 172 + if _, err := cw.Write(cbg.CborNull); err != nil { 173 + return err 174 + } 175 + } else { 176 + if len(*t.HoldDid) > 8192 { 177 + return xerrors.Errorf("Value in field t.HoldDid was too long") 178 + } 179 + 180 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.HoldDid))); err != nil { 181 + return err 182 + } 183 + if _, err := cw.WriteString(string(*t.HoldDid)); err != nil { 184 + return err 185 + } 186 + } 187 + } 188 + 189 + // t.Subject (atproto.Manifest_BlobReference) (struct) 190 + if t.Subject != nil { 191 + 192 + if len("subject") > 8192 { 193 + return xerrors.Errorf("Value in field \"subject\" was too long") 194 + } 195 + 196 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("subject"))); err != nil { 197 + return err 198 + } 199 + if _, err := cw.WriteString(string("subject")); err != nil { 200 + return err 201 + } 202 + 203 + if err := t.Subject.MarshalCBOR(cw); err != nil { 204 + return err 205 + } 206 + } 207 + 208 + // t.CreatedAt (string) (string) 209 + if len("createdAt") > 8192 { 210 + return xerrors.Errorf("Value in field \"createdAt\" was too long") 211 + } 212 + 213 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { 96 214 return err 97 215 } 98 - if _, err := cw.WriteString(string(t.Member)); err != nil { 216 + if _, err := cw.WriteString(string("createdAt")); err != nil { 99 217 return err 100 218 } 101 219 102 - // t.AddedAt (string) (string) 103 - if len("addedAt") > 8192 { 104 - return xerrors.Errorf("Value in field \"addedAt\" was too long") 220 + if len(t.CreatedAt) > 8192 { 221 + return xerrors.Errorf("Value in field t.CreatedAt was too long") 105 222 } 106 223 107 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("addedAt"))); err != nil { 224 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil { 108 225 return err 109 226 } 110 - if _, err := cw.WriteString(string("addedAt")); err != nil { 227 + if _, err := cw.WriteString(string(t.CreatedAt)); err != nil { 111 228 return err 112 229 } 113 230 114 - if len(t.AddedAt) > 8192 { 115 - return xerrors.Errorf("Value in field t.AddedAt was too long") 231 + // t.Manifests ([]atproto.Manifest_ManifestReference) (slice) 232 + if t.Manifests != nil { 233 + 234 + if len("manifests") > 8192 { 235 + return xerrors.Errorf("Value in field \"manifests\" was too long") 236 + } 237 + 238 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("manifests"))); err != nil { 239 + return err 240 + } 241 + if _, err := cw.WriteString(string("manifests")); err != nil { 242 + return err 243 + } 244 + 245 + if len(t.Manifests) > 8192 { 246 + return xerrors.Errorf("Slice value in field t.Manifests was too long") 247 + } 248 + 249 + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Manifests))); err != nil { 250 + return err 251 + } 252 + for _, v := range t.Manifests { 253 + if err := v.MarshalCBOR(cw); err != nil { 254 + return err 255 + } 256 + 257 + } 116 258 } 117 259 118 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.AddedAt))); err != nil { 260 + // t.MediaType (string) (string) 261 + if len("mediaType") > 8192 { 262 + return xerrors.Errorf("Value in field \"mediaType\" was too long") 263 + } 264 + 265 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("mediaType"))); err != nil { 119 266 return err 120 267 } 121 - if _, err := cw.WriteString(string(t.AddedAt)); err != nil { 268 + if _, err := cw.WriteString(string("mediaType")); err != nil { 122 269 return err 123 270 } 124 271 125 - // t.Permissions ([]string) (slice) 126 - if len("permissions") > 8192 { 127 - return xerrors.Errorf("Value in field \"permissions\" was too long") 272 + if len(t.MediaType) > 8192 { 273 + return xerrors.Errorf("Value in field t.MediaType was too long") 128 274 } 129 275 130 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("permissions"))); err != nil { 276 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.MediaType))); err != nil { 277 + return err 278 + } 279 + if _, err := cw.WriteString(string(t.MediaType)); err != nil { 280 + return err 281 + } 282 + 283 + // t.Repository (string) (string) 284 + if len("repository") > 8192 { 285 + return xerrors.Errorf("Value in field \"repository\" was too long") 286 + } 287 + 288 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("repository"))); err != nil { 131 289 return err 132 290 } 133 - if _, err := cw.WriteString(string("permissions")); err != nil { 291 + if _, err := cw.WriteString(string("repository")); err != nil { 134 292 return err 135 293 } 136 294 137 - if len(t.Permissions) > 8192 { 138 - return xerrors.Errorf("Slice value in field t.Permissions was too long") 295 + if len(t.Repository) > 8192 { 296 + return xerrors.Errorf("Value in field t.Repository was too long") 139 297 } 140 298 141 - if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Permissions))); err != nil { 299 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Repository))); err != nil { 142 300 return err 143 301 } 144 - for _, v := range t.Permissions { 145 - if len(v) > 8192 { 146 - return xerrors.Errorf("Value in field v was too long") 302 + if _, err := cw.WriteString(string(t.Repository)); err != nil { 303 + return err 304 + } 305 + 306 + // t.Annotations (atproto.Manifest_Annotations) (struct) 307 + if t.Annotations != nil { 308 + 309 + if len("annotations") > 8192 { 310 + return xerrors.Errorf("Value in field \"annotations\" was too long") 311 + } 312 + 313 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("annotations"))); err != nil { 314 + return err 315 + } 316 + if _, err := cw.WriteString(string("annotations")); err != nil { 317 + return err 318 + } 319 + 320 + if err := t.Annotations.MarshalCBOR(cw); err != nil { 321 + return err 322 + } 323 + } 324 + 325 + // t.HoldEndpoint (string) (string) 326 + if t.HoldEndpoint != nil { 327 + 328 + if len("holdEndpoint") > 8192 { 329 + return xerrors.Errorf("Value in field \"holdEndpoint\" was too long") 330 + } 331 + 332 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("holdEndpoint"))); err != nil { 333 + return err 334 + } 335 + if _, err := cw.WriteString(string("holdEndpoint")); err != nil { 336 + return err 337 + } 338 + 339 + if t.HoldEndpoint == nil { 340 + if _, err := cw.Write(cbg.CborNull); err != nil { 341 + return err 342 + } 343 + } else { 344 + if len(*t.HoldEndpoint) > 8192 { 345 + return xerrors.Errorf("Value in field t.HoldEndpoint was too long") 346 + } 347 + 348 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.HoldEndpoint))); err != nil { 349 + return err 350 + } 351 + if _, err := cw.WriteString(string(*t.HoldEndpoint)); err != nil { 352 + return err 353 + } 147 354 } 355 + } 148 356 149 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(v))); err != nil { 357 + // t.ManifestBlob (util.LexBlob) (struct) 358 + if t.ManifestBlob != nil { 359 + 360 + if len("manifestBlob") > 8192 { 361 + return xerrors.Errorf("Value in field \"manifestBlob\" was too long") 362 + } 363 + 364 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("manifestBlob"))); err != nil { 150 365 return err 151 366 } 152 - if _, err := cw.WriteString(string(v)); err != nil { 367 + if _, err := cw.WriteString(string("manifestBlob")); err != nil { 153 368 return err 154 369 } 155 370 371 + if err := t.ManifestBlob.MarshalCBOR(cw); err != nil { 372 + return err 373 + } 156 374 } 375 + 376 + // t.SchemaVersion (int64) (int64) 377 + if len("schemaVersion") > 8192 { 378 + return xerrors.Errorf("Value in field \"schemaVersion\" was too long") 379 + } 380 + 381 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("schemaVersion"))); err != nil { 382 + return err 383 + } 384 + if _, err := cw.WriteString(string("schemaVersion")); err != nil { 385 + return err 386 + } 387 + 388 + if t.SchemaVersion >= 0 { 389 + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.SchemaVersion)); err != nil { 390 + return err 391 + } 392 + } else { 393 + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.SchemaVersion-1)); err != nil { 394 + return err 395 + } 396 + } 397 + 157 398 return nil 158 399 } 159 400 160 - func (t *CrewRecord) UnmarshalCBOR(r io.Reader) (err error) { 161 - *t = CrewRecord{} 401 + func (t *Manifest) UnmarshalCBOR(r io.Reader) (err error) { 402 + *t = Manifest{} 162 403 163 404 cr := cbg.NewCborReader(r) 164 405 ··· 177 418 } 178 419 179 420 if extra > cbg.MaxLength { 180 - return fmt.Errorf("CrewRecord: map struct too large (%d)", extra) 421 + return fmt.Errorf("Manifest: map struct too large (%d)", extra) 422 + } 423 + 424 + n := extra 425 + 426 + nameBuf := make([]byte, 13) 427 + for i := uint64(0); i < n; i++ { 428 + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) 429 + if err != nil { 430 + return err 431 + } 432 + 433 + if !ok { 434 + // Field doesn't exist on this type, so ignore it 435 + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { 436 + return err 437 + } 438 + continue 439 + } 440 + 441 + switch string(nameBuf[:nameLen]) { 442 + // t.LexiconTypeID (string) (string) 443 + case "$type": 444 + 445 + { 446 + sval, err := cbg.ReadStringWithMax(cr, 8192) 447 + if err != nil { 448 + return err 449 + } 450 + 451 + t.LexiconTypeID = string(sval) 452 + } 453 + // t.Config (atproto.Manifest_BlobReference) (struct) 454 + case "config": 455 + 456 + { 457 + 458 + b, err := cr.ReadByte() 459 + if err != nil { 460 + return err 461 + } 462 + if b != cbg.CborNull[0] { 463 + if err := cr.UnreadByte(); err != nil { 464 + return err 465 + } 466 + t.Config = new(Manifest_BlobReference) 467 + if err := t.Config.UnmarshalCBOR(cr); err != nil { 468 + return xerrors.Errorf("unmarshaling t.Config pointer: %w", err) 469 + } 470 + } 471 + 472 + } 473 + // t.Digest (string) (string) 474 + case "digest": 475 + 476 + { 477 + sval, err := cbg.ReadStringWithMax(cr, 8192) 478 + if err != nil { 479 + return err 480 + } 481 + 482 + t.Digest = string(sval) 483 + } 484 + // t.Layers ([]atproto.Manifest_BlobReference) (slice) 485 + case "layers": 486 + 487 + maj, extra, err = cr.ReadHeader() 488 + if err != nil { 489 + return err 490 + } 491 + 492 + if extra > 8192 { 493 + return fmt.Errorf("t.Layers: array too large (%d)", extra) 494 + } 495 + 496 + if maj != cbg.MajArray { 497 + return fmt.Errorf("expected cbor array") 498 + } 499 + 500 + if extra > 0 { 501 + t.Layers = make([]Manifest_BlobReference, extra) 502 + } 503 + 504 + for i := 0; i < int(extra); i++ { 505 + { 506 + var maj byte 507 + var extra uint64 508 + var err error 509 + _ = maj 510 + _ = extra 511 + _ = err 512 + 513 + { 514 + 515 + if err := t.Layers[i].UnmarshalCBOR(cr); err != nil { 516 + return xerrors.Errorf("unmarshaling t.Layers[i]: %w", err) 517 + } 518 + 519 + } 520 + 521 + } 522 + } 523 + // t.HoldDid (string) (string) 524 + case "holdDid": 525 + 526 + { 527 + b, err := cr.ReadByte() 528 + if err != nil { 529 + return err 530 + } 531 + if b != cbg.CborNull[0] { 532 + if err := cr.UnreadByte(); err != nil { 533 + return err 534 + } 535 + 536 + sval, err := cbg.ReadStringWithMax(cr, 8192) 537 + if err != nil { 538 + return err 539 + } 540 + 541 + t.HoldDid = (*string)(&sval) 542 + } 543 + } 544 + // t.Subject (atproto.Manifest_BlobReference) (struct) 545 + case "subject": 546 + 547 + { 548 + 549 + b, err := cr.ReadByte() 550 + if err != nil { 551 + return err 552 + } 553 + if b != cbg.CborNull[0] { 554 + if err := cr.UnreadByte(); err != nil { 555 + return err 556 + } 557 + t.Subject = new(Manifest_BlobReference) 558 + if err := t.Subject.UnmarshalCBOR(cr); err != nil { 559 + return xerrors.Errorf("unmarshaling t.Subject pointer: %w", err) 560 + } 561 + } 562 + 563 + } 564 + // t.CreatedAt (string) (string) 565 + case "createdAt": 566 + 567 + { 568 + sval, err := cbg.ReadStringWithMax(cr, 8192) 569 + if err != nil { 570 + return err 571 + } 572 + 573 + t.CreatedAt = string(sval) 574 + } 575 + // t.Manifests ([]atproto.Manifest_ManifestReference) (slice) 576 + case "manifests": 577 + 578 + maj, extra, err = cr.ReadHeader() 579 + if err != nil { 580 + return err 581 + } 582 + 583 + if extra > 8192 { 584 + return fmt.Errorf("t.Manifests: array too large (%d)", extra) 585 + } 586 + 587 + if maj != cbg.MajArray { 588 + return fmt.Errorf("expected cbor array") 589 + } 590 + 591 + if extra > 0 { 592 + t.Manifests = make([]Manifest_ManifestReference, extra) 593 + } 594 + 595 + for i := 0; i < int(extra); i++ { 596 + { 597 + var maj byte 598 + var extra uint64 599 + var err error 600 + _ = maj 601 + _ = extra 602 + _ = err 603 + 604 + { 605 + 606 + if err := t.Manifests[i].UnmarshalCBOR(cr); err != nil { 607 + return xerrors.Errorf("unmarshaling t.Manifests[i]: %w", err) 608 + } 609 + 610 + } 611 + 612 + } 613 + } 614 + // t.MediaType (string) (string) 615 + case "mediaType": 616 + 617 + { 618 + sval, err := cbg.ReadStringWithMax(cr, 8192) 619 + if err != nil { 620 + return err 621 + } 622 + 623 + t.MediaType = string(sval) 624 + } 625 + // t.Repository (string) (string) 626 + case "repository": 627 + 628 + { 629 + sval, err := cbg.ReadStringWithMax(cr, 8192) 630 + if err != nil { 631 + return err 632 + } 633 + 634 + t.Repository = string(sval) 635 + } 636 + // t.Annotations (atproto.Manifest_Annotations) (struct) 637 + case "annotations": 638 + 639 + { 640 + 641 + b, err := cr.ReadByte() 642 + if err != nil { 643 + return err 644 + } 645 + if b != cbg.CborNull[0] { 646 + if err := cr.UnreadByte(); err != nil { 647 + return err 648 + } 649 + t.Annotations = new(Manifest_Annotations) 650 + if err := t.Annotations.UnmarshalCBOR(cr); err != nil { 651 + return xerrors.Errorf("unmarshaling t.Annotations pointer: %w", err) 652 + } 653 + } 654 + 655 + } 656 + // t.HoldEndpoint (string) (string) 657 + case "holdEndpoint": 658 + 659 + { 660 + b, err := cr.ReadByte() 661 + if err != nil { 662 + return err 663 + } 664 + if b != cbg.CborNull[0] { 665 + if err := cr.UnreadByte(); err != nil { 666 + return err 667 + } 668 + 669 + sval, err := cbg.ReadStringWithMax(cr, 8192) 670 + if err != nil { 671 + return err 672 + } 673 + 674 + t.HoldEndpoint = (*string)(&sval) 675 + } 676 + } 677 + // t.ManifestBlob (util.LexBlob) (struct) 678 + case "manifestBlob": 679 + 680 + { 681 + 682 + b, err := cr.ReadByte() 683 + if err != nil { 684 + return err 685 + } 686 + if b != cbg.CborNull[0] { 687 + if err := cr.UnreadByte(); err != nil { 688 + return err 689 + } 690 + t.ManifestBlob = new(util.LexBlob) 691 + if err := t.ManifestBlob.UnmarshalCBOR(cr); err != nil { 692 + return xerrors.Errorf("unmarshaling t.ManifestBlob pointer: %w", err) 693 + } 694 + } 695 + 696 + } 697 + // t.SchemaVersion (int64) (int64) 698 + case "schemaVersion": 699 + { 700 + maj, extra, err := cr.ReadHeader() 701 + if err != nil { 702 + return err 703 + } 704 + var extraI int64 705 + switch maj { 706 + case cbg.MajUnsignedInt: 707 + extraI = int64(extra) 708 + if extraI < 0 { 709 + return fmt.Errorf("int64 positive overflow") 710 + } 711 + case cbg.MajNegativeInt: 712 + extraI = int64(extra) 713 + if extraI < 0 { 714 + return fmt.Errorf("int64 negative overflow") 715 + } 716 + extraI = -1 - extraI 717 + default: 718 + return fmt.Errorf("wrong type for int64 field: %d", maj) 719 + } 720 + 721 + t.SchemaVersion = int64(extraI) 722 + } 723 + 724 + default: 725 + // Field doesn't exist on this type, so ignore it 726 + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { 727 + return err 728 + } 729 + } 730 + } 731 + 732 + return nil 733 + } 734 + func (t *Manifest_BlobReference) MarshalCBOR(w io.Writer) error { 735 + if t == nil { 736 + _, err := w.Write(cbg.CborNull) 737 + return err 738 + } 739 + 740 + cw := cbg.NewCborWriter(w) 741 + fieldCount := 6 742 + 743 + if t.LexiconTypeID == "" { 744 + fieldCount-- 745 + } 746 + 747 + if t.Annotations == nil { 748 + fieldCount-- 749 + } 750 + 751 + if t.Urls == nil { 752 + fieldCount-- 753 + } 754 + 755 + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { 756 + return err 757 + } 758 + 759 + // t.Size (int64) (int64) 760 + if len("size") > 8192 { 761 + return xerrors.Errorf("Value in field \"size\" was too long") 762 + } 763 + 764 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("size"))); err != nil { 765 + return err 766 + } 767 + if _, err := cw.WriteString(string("size")); err != nil { 768 + return err 769 + } 770 + 771 + if t.Size >= 0 { 772 + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Size)); err != nil { 773 + return err 774 + } 775 + } else { 776 + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Size-1)); err != nil { 777 + return err 778 + } 779 + } 780 + 781 + // t.Urls ([]string) (slice) 782 + if t.Urls != nil { 783 + 784 + if len("urls") > 8192 { 785 + return xerrors.Errorf("Value in field \"urls\" was too long") 786 + } 787 + 788 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("urls"))); err != nil { 789 + return err 790 + } 791 + if _, err := cw.WriteString(string("urls")); err != nil { 792 + return err 793 + } 794 + 795 + if len(t.Urls) > 8192 { 796 + return xerrors.Errorf("Slice value in field t.Urls was too long") 797 + } 798 + 799 + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Urls))); err != nil { 800 + return err 801 + } 802 + for _, v := range t.Urls { 803 + if len(v) > 8192 { 804 + return xerrors.Errorf("Value in field v was too long") 805 + } 806 + 807 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(v))); err != nil { 808 + return err 809 + } 810 + if _, err := cw.WriteString(string(v)); err != nil { 811 + return err 812 + } 813 + 814 + } 815 + } 816 + 817 + // t.LexiconTypeID (string) (string) 818 + if t.LexiconTypeID != "" { 819 + 820 + if len("$type") > 8192 { 821 + return xerrors.Errorf("Value in field \"$type\" was too long") 822 + } 823 + 824 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { 825 + return err 826 + } 827 + if _, err := cw.WriteString(string("$type")); err != nil { 828 + return err 829 + } 830 + 831 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.manifest#blobReference"))); err != nil { 832 + return err 833 + } 834 + if _, err := cw.WriteString(string("io.atcr.manifest#blobReference")); err != nil { 835 + return err 836 + } 837 + } 838 + 839 + // t.Digest (string) (string) 840 + if len("digest") > 8192 { 841 + return xerrors.Errorf("Value in field \"digest\" was too long") 842 + } 843 + 844 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("digest"))); err != nil { 845 + return err 846 + } 847 + if _, err := cw.WriteString(string("digest")); err != nil { 848 + return err 849 + } 850 + 851 + if len(t.Digest) > 8192 { 852 + return xerrors.Errorf("Value in field t.Digest was too long") 853 + } 854 + 855 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Digest))); err != nil { 856 + return err 857 + } 858 + if _, err := cw.WriteString(string(t.Digest)); err != nil { 859 + return err 860 + } 861 + 862 + // t.MediaType (string) (string) 863 + if len("mediaType") > 8192 { 864 + return xerrors.Errorf("Value in field \"mediaType\" was too long") 865 + } 866 + 867 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("mediaType"))); err != nil { 868 + return err 869 + } 870 + if _, err := cw.WriteString(string("mediaType")); err != nil { 871 + return err 872 + } 873 + 874 + if len(t.MediaType) > 8192 { 875 + return xerrors.Errorf("Value in field t.MediaType was too long") 876 + } 877 + 878 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.MediaType))); err != nil { 879 + return err 880 + } 881 + if _, err := cw.WriteString(string(t.MediaType)); err != nil { 882 + return err 883 + } 884 + 885 + // t.Annotations (atproto.Manifest_BlobReference_Annotations) (struct) 886 + if t.Annotations != nil { 887 + 888 + if len("annotations") > 8192 { 889 + return xerrors.Errorf("Value in field \"annotations\" was too long") 890 + } 891 + 892 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("annotations"))); err != nil { 893 + return err 894 + } 895 + if _, err := cw.WriteString(string("annotations")); err != nil { 896 + return err 897 + } 898 + 899 + if err := t.Annotations.MarshalCBOR(cw); err != nil { 900 + return err 901 + } 902 + } 903 + return nil 904 + } 905 + 906 + func (t *Manifest_BlobReference) UnmarshalCBOR(r io.Reader) (err error) { 907 + *t = Manifest_BlobReference{} 908 + 909 + cr := cbg.NewCborReader(r) 910 + 911 + maj, extra, err := cr.ReadHeader() 912 + if err != nil { 913 + return err 914 + } 915 + defer func() { 916 + if err == io.EOF { 917 + err = io.ErrUnexpectedEOF 918 + } 919 + }() 920 + 921 + if maj != cbg.MajMap { 922 + return fmt.Errorf("cbor input should be of type map") 923 + } 924 + 925 + if extra > cbg.MaxLength { 926 + return fmt.Errorf("Manifest_BlobReference: map struct too large (%d)", extra) 181 927 } 182 928 183 929 n := extra ··· 198 944 } 199 945 200 946 switch string(nameBuf[:nameLen]) { 201 - // t.Role (string) (string) 202 - case "role": 947 + // t.Size (int64) (int64) 948 + case "size": 949 + { 950 + maj, extra, err := cr.ReadHeader() 951 + if err != nil { 952 + return err 953 + } 954 + var extraI int64 955 + switch maj { 956 + case cbg.MajUnsignedInt: 957 + extraI = int64(extra) 958 + if extraI < 0 { 959 + return fmt.Errorf("int64 positive overflow") 960 + } 961 + case cbg.MajNegativeInt: 962 + extraI = int64(extra) 963 + if extraI < 0 { 964 + return fmt.Errorf("int64 negative overflow") 965 + } 966 + extraI = -1 - extraI 967 + default: 968 + return fmt.Errorf("wrong type for int64 field: %d", maj) 969 + } 970 + 971 + t.Size = int64(extraI) 972 + } 973 + // t.Urls ([]string) (slice) 974 + case "urls": 975 + 976 + maj, extra, err = cr.ReadHeader() 977 + if err != nil { 978 + return err 979 + } 980 + 981 + if extra > 8192 { 982 + return fmt.Errorf("t.Urls: array too large (%d)", extra) 983 + } 984 + 985 + if maj != cbg.MajArray { 986 + return fmt.Errorf("expected cbor array") 987 + } 988 + 989 + if extra > 0 { 990 + t.Urls = make([]string, extra) 991 + } 992 + 993 + for i := 0; i < int(extra); i++ { 994 + { 995 + var maj byte 996 + var extra uint64 997 + var err error 998 + _ = maj 999 + _ = extra 1000 + _ = err 1001 + 1002 + { 1003 + sval, err := cbg.ReadStringWithMax(cr, 8192) 1004 + if err != nil { 1005 + return err 1006 + } 1007 + 1008 + t.Urls[i] = string(sval) 1009 + } 1010 + 1011 + } 1012 + } 1013 + // t.LexiconTypeID (string) (string) 1014 + case "$type": 203 1015 204 1016 { 205 1017 sval, err := cbg.ReadStringWithMax(cr, 8192) ··· 207 1019 return err 208 1020 } 209 1021 210 - t.Role = string(sval) 1022 + t.LexiconTypeID = string(sval) 1023 + } 1024 + // t.Digest (string) (string) 1025 + case "digest": 1026 + 1027 + { 1028 + sval, err := cbg.ReadStringWithMax(cr, 8192) 1029 + if err != nil { 1030 + return err 1031 + } 1032 + 1033 + t.Digest = string(sval) 1034 + } 1035 + // t.MediaType (string) (string) 1036 + case "mediaType": 1037 + 1038 + { 1039 + sval, err := cbg.ReadStringWithMax(cr, 8192) 1040 + if err != nil { 1041 + return err 1042 + } 1043 + 1044 + t.MediaType = string(sval) 1045 + } 1046 + // t.Annotations (atproto.Manifest_BlobReference_Annotations) (struct) 1047 + case "annotations": 1048 + 1049 + { 1050 + 1051 + b, err := cr.ReadByte() 1052 + if err != nil { 1053 + return err 1054 + } 1055 + if b != cbg.CborNull[0] { 1056 + if err := cr.UnreadByte(); err != nil { 1057 + return err 1058 + } 1059 + t.Annotations = new(Manifest_BlobReference_Annotations) 1060 + if err := t.Annotations.UnmarshalCBOR(cr); err != nil { 1061 + return xerrors.Errorf("unmarshaling t.Annotations pointer: %w", err) 1062 + } 1063 + } 1064 + 1065 + } 1066 + 1067 + default: 1068 + // Field doesn't exist on this type, so ignore it 1069 + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { 1070 + return err 1071 + } 1072 + } 1073 + } 1074 + 1075 + return nil 1076 + } 1077 + func (t *Manifest_ManifestReference) MarshalCBOR(w io.Writer) error { 1078 + if t == nil { 1079 + _, err := w.Write(cbg.CborNull) 1080 + return err 1081 + } 1082 + 1083 + cw := cbg.NewCborWriter(w) 1084 + fieldCount := 6 1085 + 1086 + if t.LexiconTypeID == "" { 1087 + fieldCount-- 1088 + } 1089 + 1090 + if t.Annotations == nil { 1091 + fieldCount-- 1092 + } 1093 + 1094 + if t.Platform == nil { 1095 + fieldCount-- 1096 + } 1097 + 1098 + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { 1099 + return err 1100 + } 1101 + 1102 + // t.Size (int64) (int64) 1103 + if len("size") > 8192 { 1104 + return xerrors.Errorf("Value in field \"size\" was too long") 1105 + } 1106 + 1107 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("size"))); err != nil { 1108 + return err 1109 + } 1110 + if _, err := cw.WriteString(string("size")); err != nil { 1111 + return err 1112 + } 1113 + 1114 + if t.Size >= 0 { 1115 + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Size)); err != nil { 1116 + return err 1117 + } 1118 + } else { 1119 + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Size-1)); err != nil { 1120 + return err 1121 + } 1122 + } 1123 + 1124 + // t.LexiconTypeID (string) (string) 1125 + if t.LexiconTypeID != "" { 1126 + 1127 + if len("$type") > 8192 { 1128 + return xerrors.Errorf("Value in field \"$type\" was too long") 1129 + } 1130 + 1131 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { 1132 + return err 1133 + } 1134 + if _, err := cw.WriteString(string("$type")); err != nil { 1135 + return err 1136 + } 1137 + 1138 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.manifest#manifestReference"))); err != nil { 1139 + return err 1140 + } 1141 + if _, err := cw.WriteString(string("io.atcr.manifest#manifestReference")); err != nil { 1142 + return err 1143 + } 1144 + } 1145 + 1146 + // t.Digest (string) (string) 1147 + if len("digest") > 8192 { 1148 + return xerrors.Errorf("Value in field \"digest\" was too long") 1149 + } 1150 + 1151 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("digest"))); err != nil { 1152 + return err 1153 + } 1154 + if _, err := cw.WriteString(string("digest")); err != nil { 1155 + return err 1156 + } 1157 + 1158 + if len(t.Digest) > 8192 { 1159 + return xerrors.Errorf("Value in field t.Digest was too long") 1160 + } 1161 + 1162 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Digest))); err != nil { 1163 + return err 1164 + } 1165 + if _, err := cw.WriteString(string(t.Digest)); err != nil { 1166 + return err 1167 + } 1168 + 1169 + // t.Platform (atproto.Manifest_Platform) (struct) 1170 + if t.Platform != nil { 1171 + 1172 + if len("platform") > 8192 { 1173 + return xerrors.Errorf("Value in field \"platform\" was too long") 1174 + } 1175 + 1176 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("platform"))); err != nil { 1177 + return err 1178 + } 1179 + if _, err := cw.WriteString(string("platform")); err != nil { 1180 + return err 1181 + } 1182 + 1183 + if err := t.Platform.MarshalCBOR(cw); err != nil { 1184 + return err 1185 + } 1186 + } 1187 + 1188 + // t.MediaType (string) (string) 1189 + if len("mediaType") > 8192 { 1190 + return xerrors.Errorf("Value in field \"mediaType\" was too long") 1191 + } 1192 + 1193 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("mediaType"))); err != nil { 1194 + return err 1195 + } 1196 + if _, err := cw.WriteString(string("mediaType")); err != nil { 1197 + return err 1198 + } 1199 + 1200 + if len(t.MediaType) > 8192 { 1201 + return xerrors.Errorf("Value in field t.MediaType was too long") 1202 + } 1203 + 1204 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.MediaType))); err != nil { 1205 + return err 1206 + } 1207 + if _, err := cw.WriteString(string(t.MediaType)); err != nil { 1208 + return err 1209 + } 1210 + 1211 + // t.Annotations (atproto.Manifest_ManifestReference_Annotations) (struct) 1212 + if t.Annotations != nil { 1213 + 1214 + if len("annotations") > 8192 { 1215 + return xerrors.Errorf("Value in field \"annotations\" was too long") 1216 + } 1217 + 1218 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("annotations"))); err != nil { 1219 + return err 1220 + } 1221 + if _, err := cw.WriteString(string("annotations")); err != nil { 1222 + return err 1223 + } 1224 + 1225 + if err := t.Annotations.MarshalCBOR(cw); err != nil { 1226 + return err 1227 + } 1228 + } 1229 + return nil 1230 + } 1231 + 1232 + func (t *Manifest_ManifestReference) UnmarshalCBOR(r io.Reader) (err error) { 1233 + *t = Manifest_ManifestReference{} 1234 + 1235 + cr := cbg.NewCborReader(r) 1236 + 1237 + maj, extra, err := cr.ReadHeader() 1238 + if err != nil { 1239 + return err 1240 + } 1241 + defer func() { 1242 + if err == io.EOF { 1243 + err = io.ErrUnexpectedEOF 1244 + } 1245 + }() 1246 + 1247 + if maj != cbg.MajMap { 1248 + return fmt.Errorf("cbor input should be of type map") 1249 + } 1250 + 1251 + if extra > cbg.MaxLength { 1252 + return fmt.Errorf("Manifest_ManifestReference: map struct too large (%d)", extra) 1253 + } 1254 + 1255 + n := extra 1256 + 1257 + nameBuf := make([]byte, 11) 1258 + for i := uint64(0); i < n; i++ { 1259 + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) 1260 + if err != nil { 1261 + return err 1262 + } 1263 + 1264 + if !ok { 1265 + // Field doesn't exist on this type, so ignore it 1266 + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { 1267 + return err 1268 + } 1269 + continue 1270 + } 1271 + 1272 + switch string(nameBuf[:nameLen]) { 1273 + // t.Size (int64) (int64) 1274 + case "size": 1275 + { 1276 + maj, extra, err := cr.ReadHeader() 1277 + if err != nil { 1278 + return err 1279 + } 1280 + var extraI int64 1281 + switch maj { 1282 + case cbg.MajUnsignedInt: 1283 + extraI = int64(extra) 1284 + if extraI < 0 { 1285 + return fmt.Errorf("int64 positive overflow") 1286 + } 1287 + case cbg.MajNegativeInt: 1288 + extraI = int64(extra) 1289 + if extraI < 0 { 1290 + return fmt.Errorf("int64 negative overflow") 1291 + } 1292 + extraI = -1 - extraI 1293 + default: 1294 + return fmt.Errorf("wrong type for int64 field: %d", maj) 1295 + } 1296 + 1297 + t.Size = int64(extraI) 211 1298 } 212 - // t.Type (string) (string) 1299 + // t.LexiconTypeID (string) (string) 213 1300 case "$type": 214 1301 215 1302 { ··· 218 1305 return err 219 1306 } 220 1307 221 - t.Type = string(sval) 1308 + t.LexiconTypeID = string(sval) 1309 + } 1310 + // t.Digest (string) (string) 1311 + case "digest": 1312 + 1313 + { 1314 + sval, err := cbg.ReadStringWithMax(cr, 8192) 1315 + if err != nil { 1316 + return err 1317 + } 1318 + 1319 + t.Digest = string(sval) 1320 + } 1321 + // t.Platform (atproto.Manifest_Platform) (struct) 1322 + case "platform": 1323 + 1324 + { 1325 + 1326 + b, err := cr.ReadByte() 1327 + if err != nil { 1328 + return err 1329 + } 1330 + if b != cbg.CborNull[0] { 1331 + if err := cr.UnreadByte(); err != nil { 1332 + return err 1333 + } 1334 + t.Platform = new(Manifest_Platform) 1335 + if err := t.Platform.UnmarshalCBOR(cr); err != nil { 1336 + return xerrors.Errorf("unmarshaling t.Platform pointer: %w", err) 1337 + } 1338 + } 1339 + 1340 + } 1341 + // t.MediaType (string) (string) 1342 + case "mediaType": 1343 + 1344 + { 1345 + sval, err := cbg.ReadStringWithMax(cr, 8192) 1346 + if err != nil { 1347 + return err 1348 + } 1349 + 1350 + t.MediaType = string(sval) 1351 + } 1352 + // t.Annotations (atproto.Manifest_ManifestReference_Annotations) (struct) 1353 + case "annotations": 1354 + 1355 + { 1356 + 1357 + b, err := cr.ReadByte() 1358 + if err != nil { 1359 + return err 1360 + } 1361 + if b != cbg.CborNull[0] { 1362 + if err := cr.UnreadByte(); err != nil { 1363 + return err 1364 + } 1365 + t.Annotations = new(Manifest_ManifestReference_Annotations) 1366 + if err := t.Annotations.UnmarshalCBOR(cr); err != nil { 1367 + return xerrors.Errorf("unmarshaling t.Annotations pointer: %w", err) 1368 + } 1369 + } 1370 + 1371 + } 1372 + 1373 + default: 1374 + // Field doesn't exist on this type, so ignore it 1375 + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { 1376 + return err 1377 + } 1378 + } 1379 + } 1380 + 1381 + return nil 1382 + } 1383 + func (t *Manifest_Platform) MarshalCBOR(w io.Writer) error { 1384 + if t == nil { 1385 + _, err := w.Write(cbg.CborNull) 1386 + return err 1387 + } 1388 + 1389 + cw := cbg.NewCborWriter(w) 1390 + fieldCount := 6 1391 + 1392 + if t.LexiconTypeID == "" { 1393 + fieldCount-- 1394 + } 1395 + 1396 + if t.OsFeatures == nil { 1397 + fieldCount-- 1398 + } 1399 + 1400 + if t.OsVersion == nil { 1401 + fieldCount-- 1402 + } 1403 + 1404 + if t.Variant == nil { 1405 + fieldCount-- 1406 + } 1407 + 1408 + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { 1409 + return err 1410 + } 1411 + 1412 + // t.Os (string) (string) 1413 + if len("os") > 8192 { 1414 + return xerrors.Errorf("Value in field \"os\" was too long") 1415 + } 1416 + 1417 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("os"))); err != nil { 1418 + return err 1419 + } 1420 + if _, err := cw.WriteString(string("os")); err != nil { 1421 + return err 1422 + } 1423 + 1424 + if len(t.Os) > 8192 { 1425 + return xerrors.Errorf("Value in field t.Os was too long") 1426 + } 1427 + 1428 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Os))); err != nil { 1429 + return err 1430 + } 1431 + if _, err := cw.WriteString(string(t.Os)); err != nil { 1432 + return err 1433 + } 1434 + 1435 + // t.LexiconTypeID (string) (string) 1436 + if t.LexiconTypeID != "" { 1437 + 1438 + if len("$type") > 8192 { 1439 + return xerrors.Errorf("Value in field \"$type\" was too long") 1440 + } 1441 + 1442 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { 1443 + return err 1444 + } 1445 + if _, err := cw.WriteString(string("$type")); err != nil { 1446 + return err 1447 + } 1448 + 1449 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.manifest#platform"))); err != nil { 1450 + return err 1451 + } 1452 + if _, err := cw.WriteString(string("io.atcr.manifest#platform")); err != nil { 1453 + return err 1454 + } 1455 + } 1456 + 1457 + // t.Variant (string) (string) 1458 + if t.Variant != nil { 1459 + 1460 + if len("variant") > 8192 { 1461 + return xerrors.Errorf("Value in field \"variant\" was too long") 1462 + } 1463 + 1464 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("variant"))); err != nil { 1465 + return err 1466 + } 1467 + if _, err := cw.WriteString(string("variant")); err != nil { 1468 + return err 1469 + } 1470 + 1471 + if t.Variant == nil { 1472 + if _, err := cw.Write(cbg.CborNull); err != nil { 1473 + return err 222 1474 } 223 - // t.Member (string) (string) 224 - case "member": 1475 + } else { 1476 + if len(*t.Variant) > 8192 { 1477 + return xerrors.Errorf("Value in field t.Variant was too long") 1478 + } 1479 + 1480 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Variant))); err != nil { 1481 + return err 1482 + } 1483 + if _, err := cw.WriteString(string(*t.Variant)); err != nil { 1484 + return err 1485 + } 1486 + } 1487 + } 1488 + 1489 + // t.OsVersion (string) (string) 1490 + if t.OsVersion != nil { 1491 + 1492 + if len("osVersion") > 8192 { 1493 + return xerrors.Errorf("Value in field \"osVersion\" was too long") 1494 + } 1495 + 1496 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("osVersion"))); err != nil { 1497 + return err 1498 + } 1499 + if _, err := cw.WriteString(string("osVersion")); err != nil { 1500 + return err 1501 + } 1502 + 1503 + if t.OsVersion == nil { 1504 + if _, err := cw.Write(cbg.CborNull); err != nil { 1505 + return err 1506 + } 1507 + } else { 1508 + if len(*t.OsVersion) > 8192 { 1509 + return xerrors.Errorf("Value in field t.OsVersion was too long") 1510 + } 1511 + 1512 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.OsVersion))); err != nil { 1513 + return err 1514 + } 1515 + if _, err := cw.WriteString(string(*t.OsVersion)); err != nil { 1516 + return err 1517 + } 1518 + } 1519 + } 1520 + 1521 + // t.OsFeatures ([]string) (slice) 1522 + if t.OsFeatures != nil { 1523 + 1524 + if len("osFeatures") > 8192 { 1525 + return xerrors.Errorf("Value in field \"osFeatures\" was too long") 1526 + } 1527 + 1528 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("osFeatures"))); err != nil { 1529 + return err 1530 + } 1531 + if _, err := cw.WriteString(string("osFeatures")); err != nil { 1532 + return err 1533 + } 1534 + 1535 + if len(t.OsFeatures) > 8192 { 1536 + return xerrors.Errorf("Slice value in field t.OsFeatures was too long") 1537 + } 1538 + 1539 + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.OsFeatures))); err != nil { 1540 + return err 1541 + } 1542 + for _, v := range t.OsFeatures { 1543 + if len(v) > 8192 { 1544 + return xerrors.Errorf("Value in field v was too long") 1545 + } 1546 + 1547 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(v))); err != nil { 1548 + return err 1549 + } 1550 + if _, err := cw.WriteString(string(v)); err != nil { 1551 + return err 1552 + } 1553 + 1554 + } 1555 + } 1556 + 1557 + // t.Architecture (string) (string) 1558 + if len("architecture") > 8192 { 1559 + return xerrors.Errorf("Value in field \"architecture\" was too long") 1560 + } 1561 + 1562 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("architecture"))); err != nil { 1563 + return err 1564 + } 1565 + if _, err := cw.WriteString(string("architecture")); err != nil { 1566 + return err 1567 + } 1568 + 1569 + if len(t.Architecture) > 8192 { 1570 + return xerrors.Errorf("Value in field t.Architecture was too long") 1571 + } 1572 + 1573 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Architecture))); err != nil { 1574 + return err 1575 + } 1576 + if _, err := cw.WriteString(string(t.Architecture)); err != nil { 1577 + return err 1578 + } 1579 + return nil 1580 + } 1581 + 1582 + func (t *Manifest_Platform) UnmarshalCBOR(r io.Reader) (err error) { 1583 + *t = Manifest_Platform{} 1584 + 1585 + cr := cbg.NewCborReader(r) 1586 + 1587 + maj, extra, err := cr.ReadHeader() 1588 + if err != nil { 1589 + return err 1590 + } 1591 + defer func() { 1592 + if err == io.EOF { 1593 + err = io.ErrUnexpectedEOF 1594 + } 1595 + }() 1596 + 1597 + if maj != cbg.MajMap { 1598 + return fmt.Errorf("cbor input should be of type map") 1599 + } 1600 + 1601 + if extra > cbg.MaxLength { 1602 + return fmt.Errorf("Manifest_Platform: map struct too large (%d)", extra) 1603 + } 1604 + 1605 + n := extra 1606 + 1607 + nameBuf := make([]byte, 12) 1608 + for i := uint64(0); i < n; i++ { 1609 + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) 1610 + if err != nil { 1611 + return err 1612 + } 1613 + 1614 + if !ok { 1615 + // Field doesn't exist on this type, so ignore it 1616 + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { 1617 + return err 1618 + } 1619 + continue 1620 + } 1621 + 1622 + switch string(nameBuf[:nameLen]) { 1623 + // t.Os (string) (string) 1624 + case "os": 225 1625 226 1626 { 227 1627 sval, err := cbg.ReadStringWithMax(cr, 8192) ··· 229 1629 return err 230 1630 } 231 1631 232 - t.Member = string(sval) 1632 + t.Os = string(sval) 233 1633 } 234 - // t.AddedAt (string) (string) 235 - case "addedAt": 1634 + // t.LexiconTypeID (string) (string) 1635 + case "$type": 236 1636 237 1637 { 238 1638 sval, err := cbg.ReadStringWithMax(cr, 8192) ··· 240 1640 return err 241 1641 } 242 1642 243 - t.AddedAt = string(sval) 1643 + t.LexiconTypeID = string(sval) 244 1644 } 245 - // t.Permissions ([]string) (slice) 246 - case "permissions": 1645 + // t.Variant (string) (string) 1646 + case "variant": 1647 + 1648 + { 1649 + b, err := cr.ReadByte() 1650 + if err != nil { 1651 + return err 1652 + } 1653 + if b != cbg.CborNull[0] { 1654 + if err := cr.UnreadByte(); err != nil { 1655 + return err 1656 + } 1657 + 1658 + sval, err := cbg.ReadStringWithMax(cr, 8192) 1659 + if err != nil { 1660 + return err 1661 + } 1662 + 1663 + t.Variant = (*string)(&sval) 1664 + } 1665 + } 1666 + // t.OsVersion (string) (string) 1667 + case "osVersion": 1668 + 1669 + { 1670 + b, err := cr.ReadByte() 1671 + if err != nil { 1672 + return err 1673 + } 1674 + if b != cbg.CborNull[0] { 1675 + if err := cr.UnreadByte(); err != nil { 1676 + return err 1677 + } 1678 + 1679 + sval, err := cbg.ReadStringWithMax(cr, 8192) 1680 + if err != nil { 1681 + return err 1682 + } 1683 + 1684 + t.OsVersion = (*string)(&sval) 1685 + } 1686 + } 1687 + // t.OsFeatures ([]string) (slice) 1688 + case "osFeatures": 247 1689 248 1690 maj, extra, err = cr.ReadHeader() 249 1691 if err != nil { ··· 251 1693 } 252 1694 253 1695 if extra > 8192 { 254 - return fmt.Errorf("t.Permissions: array too large (%d)", extra) 1696 + return fmt.Errorf("t.OsFeatures: array too large (%d)", extra) 255 1697 } 256 1698 257 1699 if maj != cbg.MajArray { ··· 259 1701 } 260 1702 261 1703 if extra > 0 { 262 - t.Permissions = make([]string, extra) 1704 + t.OsFeatures = make([]string, extra) 263 1705 } 264 1706 265 1707 for i := 0; i < int(extra); i++ { ··· 277 1719 return err 278 1720 } 279 1721 280 - t.Permissions[i] = string(sval) 1722 + t.OsFeatures[i] = string(sval) 1723 + } 1724 + 1725 + } 1726 + } 1727 + // t.Architecture (string) (string) 1728 + case "architecture": 1729 + 1730 + { 1731 + sval, err := cbg.ReadStringWithMax(cr, 8192) 1732 + if err != nil { 1733 + return err 1734 + } 1735 + 1736 + t.Architecture = string(sval) 1737 + } 1738 + 1739 + default: 1740 + // Field doesn't exist on this type, so ignore it 1741 + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { 1742 + return err 1743 + } 1744 + } 1745 + } 1746 + 1747 + return nil 1748 + } 1749 + func (t *Manifest_Annotations) MarshalCBOR(w io.Writer) error { 1750 + if t == nil { 1751 + _, err := w.Write(cbg.CborNull) 1752 + return err 1753 + } 1754 + 1755 + cw := cbg.NewCborWriter(w) 1756 + 1757 + if _, err := cw.Write([]byte{160}); err != nil { 1758 + return err 1759 + } 1760 + return nil 1761 + } 1762 + 1763 + func (t *Manifest_Annotations) UnmarshalCBOR(r io.Reader) (err error) { 1764 + *t = Manifest_Annotations{} 1765 + 1766 + cr := cbg.NewCborReader(r) 1767 + 1768 + maj, extra, err := cr.ReadHeader() 1769 + if err != nil { 1770 + return err 1771 + } 1772 + defer func() { 1773 + if err == io.EOF { 1774 + err = io.ErrUnexpectedEOF 1775 + } 1776 + }() 1777 + 1778 + if maj != cbg.MajMap { 1779 + return fmt.Errorf("cbor input should be of type map") 1780 + } 1781 + 1782 + if extra > cbg.MaxLength { 1783 + return fmt.Errorf("Manifest_Annotations: map struct too large (%d)", extra) 1784 + } 1785 + 1786 + n := extra 1787 + 1788 + nameBuf := make([]byte, 0) 1789 + for i := uint64(0); i < n; i++ { 1790 + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) 1791 + if err != nil { 1792 + return err 1793 + } 1794 + 1795 + if !ok { 1796 + // Field doesn't exist on this type, so ignore it 1797 + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { 1798 + return err 1799 + } 1800 + continue 1801 + } 1802 + 1803 + switch string(nameBuf[:nameLen]) { 1804 + 1805 + default: 1806 + // Field doesn't exist on this type, so ignore it 1807 + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { 1808 + return err 1809 + } 1810 + } 1811 + } 1812 + 1813 + return nil 1814 + } 1815 + func (t *Manifest_BlobReference_Annotations) MarshalCBOR(w io.Writer) error { 1816 + if t == nil { 1817 + _, err := w.Write(cbg.CborNull) 1818 + return err 1819 + } 1820 + 1821 + cw := cbg.NewCborWriter(w) 1822 + 1823 + if _, err := cw.Write([]byte{160}); err != nil { 1824 + return err 1825 + } 1826 + return nil 1827 + } 1828 + 1829 + func (t *Manifest_BlobReference_Annotations) UnmarshalCBOR(r io.Reader) (err error) { 1830 + *t = Manifest_BlobReference_Annotations{} 1831 + 1832 + cr := cbg.NewCborReader(r) 1833 + 1834 + maj, extra, err := cr.ReadHeader() 1835 + if err != nil { 1836 + return err 1837 + } 1838 + defer func() { 1839 + if err == io.EOF { 1840 + err = io.ErrUnexpectedEOF 1841 + } 1842 + }() 1843 + 1844 + if maj != cbg.MajMap { 1845 + return fmt.Errorf("cbor input should be of type map") 1846 + } 1847 + 1848 + if extra > cbg.MaxLength { 1849 + return fmt.Errorf("Manifest_BlobReference_Annotations: map struct too large (%d)", extra) 1850 + } 1851 + 1852 + n := extra 1853 + 1854 + nameBuf := make([]byte, 0) 1855 + for i := uint64(0); i < n; i++ { 1856 + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) 1857 + if err != nil { 1858 + return err 1859 + } 1860 + 1861 + if !ok { 1862 + // Field doesn't exist on this type, so ignore it 1863 + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { 1864 + return err 1865 + } 1866 + continue 1867 + } 1868 + 1869 + switch string(nameBuf[:nameLen]) { 1870 + 1871 + default: 1872 + // Field doesn't exist on this type, so ignore it 1873 + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { 1874 + return err 1875 + } 1876 + } 1877 + } 1878 + 1879 + return nil 1880 + } 1881 + func (t *Manifest_ManifestReference_Annotations) MarshalCBOR(w io.Writer) error { 1882 + if t == nil { 1883 + _, err := w.Write(cbg.CborNull) 1884 + return err 1885 + } 1886 + 1887 + cw := cbg.NewCborWriter(w) 1888 + 1889 + if _, err := cw.Write([]byte{160}); err != nil { 1890 + return err 1891 + } 1892 + return nil 1893 + } 1894 + 1895 + func (t *Manifest_ManifestReference_Annotations) UnmarshalCBOR(r io.Reader) (err error) { 1896 + *t = Manifest_ManifestReference_Annotations{} 1897 + 1898 + cr := cbg.NewCborReader(r) 1899 + 1900 + maj, extra, err := cr.ReadHeader() 1901 + if err != nil { 1902 + return err 1903 + } 1904 + defer func() { 1905 + if err == io.EOF { 1906 + err = io.ErrUnexpectedEOF 1907 + } 1908 + }() 1909 + 1910 + if maj != cbg.MajMap { 1911 + return fmt.Errorf("cbor input should be of type map") 1912 + } 1913 + 1914 + if extra > cbg.MaxLength { 1915 + return fmt.Errorf("Manifest_ManifestReference_Annotations: map struct too large (%d)", extra) 1916 + } 1917 + 1918 + n := extra 1919 + 1920 + nameBuf := make([]byte, 0) 1921 + for i := uint64(0); i < n; i++ { 1922 + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) 1923 + if err != nil { 1924 + return err 1925 + } 1926 + 1927 + if !ok { 1928 + // Field doesn't exist on this type, so ignore it 1929 + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { 1930 + return err 1931 + } 1932 + continue 1933 + } 1934 + 1935 + switch string(nameBuf[:nameLen]) { 1936 + 1937 + default: 1938 + // Field doesn't exist on this type, so ignore it 1939 + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { 1940 + return err 1941 + } 1942 + } 1943 + } 1944 + 1945 + return nil 1946 + } 1947 + func (t *Tag) MarshalCBOR(w io.Writer) error { 1948 + if t == nil { 1949 + _, err := w.Write(cbg.CborNull) 1950 + return err 1951 + } 1952 + 1953 + cw := cbg.NewCborWriter(w) 1954 + fieldCount := 6 1955 + 1956 + if t.Manifest == nil { 1957 + fieldCount-- 1958 + } 1959 + 1960 + if t.ManifestDigest == nil { 1961 + fieldCount-- 1962 + } 1963 + 1964 + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { 1965 + return err 1966 + } 1967 + 1968 + // t.Tag (string) (string) 1969 + if len("tag") > 8192 { 1970 + return xerrors.Errorf("Value in field \"tag\" was too long") 1971 + } 1972 + 1973 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("tag"))); err != nil { 1974 + return err 1975 + } 1976 + if _, err := cw.WriteString(string("tag")); err != nil { 1977 + return err 1978 + } 1979 + 1980 + if len(t.Tag) > 8192 { 1981 + return xerrors.Errorf("Value in field t.Tag was too long") 1982 + } 1983 + 1984 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Tag))); err != nil { 1985 + return err 1986 + } 1987 + if _, err := cw.WriteString(string(t.Tag)); err != nil { 1988 + return err 1989 + } 1990 + 1991 + // t.LexiconTypeID (string) (string) 1992 + if len("$type") > 8192 { 1993 + return xerrors.Errorf("Value in field \"$type\" was too long") 1994 + } 1995 + 1996 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { 1997 + return err 1998 + } 1999 + if _, err := cw.WriteString(string("$type")); err != nil { 2000 + return err 2001 + } 2002 + 2003 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.tag"))); err != nil { 2004 + return err 2005 + } 2006 + if _, err := cw.WriteString(string("io.atcr.tag")); err != nil { 2007 + return err 2008 + } 2009 + 2010 + // t.Manifest (string) (string) 2011 + if t.Manifest != nil { 2012 + 2013 + if len("manifest") > 8192 { 2014 + return xerrors.Errorf("Value in field \"manifest\" was too long") 2015 + } 2016 + 2017 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("manifest"))); err != nil { 2018 + return err 2019 + } 2020 + if _, err := cw.WriteString(string("manifest")); err != nil { 2021 + return err 2022 + } 2023 + 2024 + if t.Manifest == nil { 2025 + if _, err := cw.Write(cbg.CborNull); err != nil { 2026 + return err 2027 + } 2028 + } else { 2029 + if len(*t.Manifest) > 8192 { 2030 + return xerrors.Errorf("Value in field t.Manifest was too long") 2031 + } 2032 + 2033 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Manifest))); err != nil { 2034 + return err 2035 + } 2036 + if _, err := cw.WriteString(string(*t.Manifest)); err != nil { 2037 + return err 2038 + } 2039 + } 2040 + } 2041 + 2042 + // t.CreatedAt (string) (string) 2043 + if len("createdAt") > 8192 { 2044 + return xerrors.Errorf("Value in field \"createdAt\" was too long") 2045 + } 2046 + 2047 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { 2048 + return err 2049 + } 2050 + if _, err := cw.WriteString(string("createdAt")); err != nil { 2051 + return err 2052 + } 2053 + 2054 + if len(t.CreatedAt) > 8192 { 2055 + return xerrors.Errorf("Value in field t.CreatedAt was too long") 2056 + } 2057 + 2058 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil { 2059 + return err 2060 + } 2061 + if _, err := cw.WriteString(string(t.CreatedAt)); err != nil { 2062 + return err 2063 + } 2064 + 2065 + // t.Repository (string) (string) 2066 + if len("repository") > 8192 { 2067 + return xerrors.Errorf("Value in field \"repository\" was too long") 2068 + } 2069 + 2070 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("repository"))); err != nil { 2071 + return err 2072 + } 2073 + if _, err := cw.WriteString(string("repository")); err != nil { 2074 + return err 2075 + } 2076 + 2077 + if len(t.Repository) > 8192 { 2078 + return xerrors.Errorf("Value in field t.Repository was too long") 2079 + } 2080 + 2081 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Repository))); err != nil { 2082 + return err 2083 + } 2084 + if _, err := cw.WriteString(string(t.Repository)); err != nil { 2085 + return err 2086 + } 2087 + 2088 + // t.ManifestDigest (string) (string) 2089 + if t.ManifestDigest != nil { 2090 + 2091 + if len("manifestDigest") > 8192 { 2092 + return xerrors.Errorf("Value in field \"manifestDigest\" was too long") 2093 + } 2094 + 2095 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("manifestDigest"))); err != nil { 2096 + return err 2097 + } 2098 + if _, err := cw.WriteString(string("manifestDigest")); err != nil { 2099 + return err 2100 + } 2101 + 2102 + if t.ManifestDigest == nil { 2103 + if _, err := cw.Write(cbg.CborNull); err != nil { 2104 + return err 2105 + } 2106 + } else { 2107 + if len(*t.ManifestDigest) > 8192 { 2108 + return xerrors.Errorf("Value in field t.ManifestDigest was too long") 2109 + } 2110 + 2111 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.ManifestDigest))); err != nil { 2112 + return err 2113 + } 2114 + if _, err := cw.WriteString(string(*t.ManifestDigest)); err != nil { 2115 + return err 2116 + } 2117 + } 2118 + } 2119 + return nil 2120 + } 2121 + 2122 + func (t *Tag) UnmarshalCBOR(r io.Reader) (err error) { 2123 + *t = Tag{} 2124 + 2125 + cr := cbg.NewCborReader(r) 2126 + 2127 + maj, extra, err := cr.ReadHeader() 2128 + if err != nil { 2129 + return err 2130 + } 2131 + defer func() { 2132 + if err == io.EOF { 2133 + err = io.ErrUnexpectedEOF 2134 + } 2135 + }() 2136 + 2137 + if maj != cbg.MajMap { 2138 + return fmt.Errorf("cbor input should be of type map") 2139 + } 2140 + 2141 + if extra > cbg.MaxLength { 2142 + return fmt.Errorf("Tag: map struct too large (%d)", extra) 2143 + } 2144 + 2145 + n := extra 2146 + 2147 + nameBuf := make([]byte, 14) 2148 + for i := uint64(0); i < n; i++ { 2149 + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) 2150 + if err != nil { 2151 + return err 2152 + } 2153 + 2154 + if !ok { 2155 + // Field doesn't exist on this type, so ignore it 2156 + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { 2157 + return err 2158 + } 2159 + continue 2160 + } 2161 + 2162 + switch string(nameBuf[:nameLen]) { 2163 + // t.Tag (string) (string) 2164 + case "tag": 2165 + 2166 + { 2167 + sval, err := cbg.ReadStringWithMax(cr, 8192) 2168 + if err != nil { 2169 + return err 2170 + } 2171 + 2172 + t.Tag = string(sval) 2173 + } 2174 + // t.LexiconTypeID (string) (string) 2175 + case "$type": 2176 + 2177 + { 2178 + sval, err := cbg.ReadStringWithMax(cr, 8192) 2179 + if err != nil { 2180 + return err 2181 + } 2182 + 2183 + t.LexiconTypeID = string(sval) 2184 + } 2185 + // t.Manifest (string) (string) 2186 + case "manifest": 2187 + 2188 + { 2189 + b, err := cr.ReadByte() 2190 + if err != nil { 2191 + return err 2192 + } 2193 + if b != cbg.CborNull[0] { 2194 + if err := cr.UnreadByte(); err != nil { 2195 + return err 281 2196 } 282 2197 2198 + sval, err := cbg.ReadStringWithMax(cr, 8192) 2199 + if err != nil { 2200 + return err 2201 + } 2202 + 2203 + t.Manifest = (*string)(&sval) 2204 + } 2205 + } 2206 + // t.CreatedAt (string) (string) 2207 + case "createdAt": 2208 + 2209 + { 2210 + sval, err := cbg.ReadStringWithMax(cr, 8192) 2211 + if err != nil { 2212 + return err 2213 + } 2214 + 2215 + t.CreatedAt = string(sval) 2216 + } 2217 + // t.Repository (string) (string) 2218 + case "repository": 2219 + 2220 + { 2221 + sval, err := cbg.ReadStringWithMax(cr, 8192) 2222 + if err != nil { 2223 + return err 2224 + } 2225 + 2226 + t.Repository = string(sval) 2227 + } 2228 + // t.ManifestDigest (string) (string) 2229 + case "manifestDigest": 2230 + 2231 + { 2232 + b, err := cr.ReadByte() 2233 + if err != nil { 2234 + return err 2235 + } 2236 + if b != cbg.CborNull[0] { 2237 + if err := cr.UnreadByte(); err != nil { 2238 + return err 2239 + } 2240 + 2241 + sval, err := cbg.ReadStringWithMax(cr, 8192) 2242 + if err != nil { 2243 + return err 2244 + } 2245 + 2246 + t.ManifestDigest = (*string)(&sval) 283 2247 } 284 2248 } 285 2249 ··· 293 2257 294 2258 return nil 295 2259 } 296 - func (t *CaptainRecord) MarshalCBOR(w io.Writer) error { 2260 + func (t *SailorProfile) MarshalCBOR(w io.Writer) error { 297 2261 if t == nil { 298 2262 _, err := w.Write(cbg.CborNull) 299 2263 return err 300 2264 } 301 2265 302 2266 cw := cbg.NewCborWriter(w) 303 - fieldCount := 8 2267 + fieldCount := 4 304 2268 305 - if t.Region == "" { 2269 + if t.DefaultHold == nil { 306 2270 fieldCount-- 307 2271 } 308 2272 309 - if t.Provider == "" { 2273 + if t.UpdatedAt == nil { 310 2274 fieldCount-- 311 2275 } 312 2276 ··· 314 2278 return err 315 2279 } 316 2280 317 - // t.Type (string) (string) 2281 + // t.LexiconTypeID (string) (string) 318 2282 if len("$type") > 8192 { 319 2283 return xerrors.Errorf("Value in field \"$type\" was too long") 320 2284 } ··· 326 2290 return err 327 2291 } 328 2292 329 - if len(t.Type) > 8192 { 330 - return xerrors.Errorf("Value in field t.Type was too long") 2293 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.sailor.profile"))); err != nil { 2294 + return err 2295 + } 2296 + if _, err := cw.WriteString(string("io.atcr.sailor.profile")); err != nil { 2297 + return err 2298 + } 2299 + 2300 + // t.CreatedAt (string) (string) 2301 + if len("createdAt") > 8192 { 2302 + return xerrors.Errorf("Value in field \"createdAt\" was too long") 331 2303 } 332 2304 333 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Type))); err != nil { 2305 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { 334 2306 return err 335 2307 } 336 - if _, err := cw.WriteString(string(t.Type)); err != nil { 2308 + if _, err := cw.WriteString(string("createdAt")); err != nil { 2309 + return err 2310 + } 2311 + 2312 + if len(t.CreatedAt) > 8192 { 2313 + return xerrors.Errorf("Value in field t.CreatedAt was too long") 2314 + } 2315 + 2316 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil { 2317 + return err 2318 + } 2319 + if _, err := cw.WriteString(string(t.CreatedAt)); err != nil { 2320 + return err 2321 + } 2322 + 2323 + // t.UpdatedAt (string) (string) 2324 + if t.UpdatedAt != nil { 2325 + 2326 + if len("updatedAt") > 8192 { 2327 + return xerrors.Errorf("Value in field \"updatedAt\" was too long") 2328 + } 2329 + 2330 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("updatedAt"))); err != nil { 2331 + return err 2332 + } 2333 + if _, err := cw.WriteString(string("updatedAt")); err != nil { 2334 + return err 2335 + } 2336 + 2337 + if t.UpdatedAt == nil { 2338 + if _, err := cw.Write(cbg.CborNull); err != nil { 2339 + return err 2340 + } 2341 + } else { 2342 + if len(*t.UpdatedAt) > 8192 { 2343 + return xerrors.Errorf("Value in field t.UpdatedAt was too long") 2344 + } 2345 + 2346 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.UpdatedAt))); err != nil { 2347 + return err 2348 + } 2349 + if _, err := cw.WriteString(string(*t.UpdatedAt)); err != nil { 2350 + return err 2351 + } 2352 + } 2353 + } 2354 + 2355 + // t.DefaultHold (string) (string) 2356 + if t.DefaultHold != nil { 2357 + 2358 + if len("defaultHold") > 8192 { 2359 + return xerrors.Errorf("Value in field \"defaultHold\" was too long") 2360 + } 2361 + 2362 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("defaultHold"))); err != nil { 2363 + return err 2364 + } 2365 + if _, err := cw.WriteString(string("defaultHold")); err != nil { 2366 + return err 2367 + } 2368 + 2369 + if t.DefaultHold == nil { 2370 + if _, err := cw.Write(cbg.CborNull); err != nil { 2371 + return err 2372 + } 2373 + } else { 2374 + if len(*t.DefaultHold) > 8192 { 2375 + return xerrors.Errorf("Value in field t.DefaultHold was too long") 2376 + } 2377 + 2378 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.DefaultHold))); err != nil { 2379 + return err 2380 + } 2381 + if _, err := cw.WriteString(string(*t.DefaultHold)); err != nil { 2382 + return err 2383 + } 2384 + } 2385 + } 2386 + return nil 2387 + } 2388 + 2389 + func (t *SailorProfile) UnmarshalCBOR(r io.Reader) (err error) { 2390 + *t = SailorProfile{} 2391 + 2392 + cr := cbg.NewCborReader(r) 2393 + 2394 + maj, extra, err := cr.ReadHeader() 2395 + if err != nil { 2396 + return err 2397 + } 2398 + defer func() { 2399 + if err == io.EOF { 2400 + err = io.ErrUnexpectedEOF 2401 + } 2402 + }() 2403 + 2404 + if maj != cbg.MajMap { 2405 + return fmt.Errorf("cbor input should be of type map") 2406 + } 2407 + 2408 + if extra > cbg.MaxLength { 2409 + return fmt.Errorf("SailorProfile: map struct too large (%d)", extra) 2410 + } 2411 + 2412 + n := extra 2413 + 2414 + nameBuf := make([]byte, 11) 2415 + for i := uint64(0); i < n; i++ { 2416 + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) 2417 + if err != nil { 2418 + return err 2419 + } 2420 + 2421 + if !ok { 2422 + // Field doesn't exist on this type, so ignore it 2423 + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { 2424 + return err 2425 + } 2426 + continue 2427 + } 2428 + 2429 + switch string(nameBuf[:nameLen]) { 2430 + // t.LexiconTypeID (string) (string) 2431 + case "$type": 2432 + 2433 + { 2434 + sval, err := cbg.ReadStringWithMax(cr, 8192) 2435 + if err != nil { 2436 + return err 2437 + } 2438 + 2439 + t.LexiconTypeID = string(sval) 2440 + } 2441 + // t.CreatedAt (string) (string) 2442 + case "createdAt": 2443 + 2444 + { 2445 + sval, err := cbg.ReadStringWithMax(cr, 8192) 2446 + if err != nil { 2447 + return err 2448 + } 2449 + 2450 + t.CreatedAt = string(sval) 2451 + } 2452 + // t.UpdatedAt (string) (string) 2453 + case "updatedAt": 2454 + 2455 + { 2456 + b, err := cr.ReadByte() 2457 + if err != nil { 2458 + return err 2459 + } 2460 + if b != cbg.CborNull[0] { 2461 + if err := cr.UnreadByte(); err != nil { 2462 + return err 2463 + } 2464 + 2465 + sval, err := cbg.ReadStringWithMax(cr, 8192) 2466 + if err != nil { 2467 + return err 2468 + } 2469 + 2470 + t.UpdatedAt = (*string)(&sval) 2471 + } 2472 + } 2473 + // t.DefaultHold (string) (string) 2474 + case "defaultHold": 2475 + 2476 + { 2477 + b, err := cr.ReadByte() 2478 + if err != nil { 2479 + return err 2480 + } 2481 + if b != cbg.CborNull[0] { 2482 + if err := cr.UnreadByte(); err != nil { 2483 + return err 2484 + } 2485 + 2486 + sval, err := cbg.ReadStringWithMax(cr, 8192) 2487 + if err != nil { 2488 + return err 2489 + } 2490 + 2491 + t.DefaultHold = (*string)(&sval) 2492 + } 2493 + } 2494 + 2495 + default: 2496 + // Field doesn't exist on this type, so ignore it 2497 + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { 2498 + return err 2499 + } 2500 + } 2501 + } 2502 + 2503 + return nil 2504 + } 2505 + func (t *SailorStar) MarshalCBOR(w io.Writer) error { 2506 + if t == nil { 2507 + _, err := w.Write(cbg.CborNull) 2508 + return err 2509 + } 2510 + 2511 + cw := cbg.NewCborWriter(w) 2512 + 2513 + if _, err := cw.Write([]byte{163}); err != nil { 2514 + return err 2515 + } 2516 + 2517 + // t.LexiconTypeID (string) (string) 2518 + if len("$type") > 8192 { 2519 + return xerrors.Errorf("Value in field \"$type\" was too long") 2520 + } 2521 + 2522 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { 2523 + return err 2524 + } 2525 + if _, err := cw.WriteString(string("$type")); err != nil { 2526 + return err 2527 + } 2528 + 2529 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.sailor.star"))); err != nil { 2530 + return err 2531 + } 2532 + if _, err := cw.WriteString(string("io.atcr.sailor.star")); err != nil { 2533 + return err 2534 + } 2535 + 2536 + // t.Subject (atproto.SailorStar_Subject) (struct) 2537 + if len("subject") > 8192 { 2538 + return xerrors.Errorf("Value in field \"subject\" was too long") 2539 + } 2540 + 2541 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("subject"))); err != nil { 2542 + return err 2543 + } 2544 + if _, err := cw.WriteString(string("subject")); err != nil { 2545 + return err 2546 + } 2547 + 2548 + if err := t.Subject.MarshalCBOR(cw); err != nil { 2549 + return err 2550 + } 2551 + 2552 + // t.CreatedAt (string) (string) 2553 + if len("createdAt") > 8192 { 2554 + return xerrors.Errorf("Value in field \"createdAt\" was too long") 2555 + } 2556 + 2557 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil { 2558 + return err 2559 + } 2560 + if _, err := cw.WriteString(string("createdAt")); err != nil { 2561 + return err 2562 + } 2563 + 2564 + if len(t.CreatedAt) > 8192 { 2565 + return xerrors.Errorf("Value in field t.CreatedAt was too long") 2566 + } 2567 + 2568 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil { 2569 + return err 2570 + } 2571 + if _, err := cw.WriteString(string(t.CreatedAt)); err != nil { 2572 + return err 2573 + } 2574 + return nil 2575 + } 2576 + 2577 + func (t *SailorStar) UnmarshalCBOR(r io.Reader) (err error) { 2578 + *t = SailorStar{} 2579 + 2580 + cr := cbg.NewCborReader(r) 2581 + 2582 + maj, extra, err := cr.ReadHeader() 2583 + if err != nil { 2584 + return err 2585 + } 2586 + defer func() { 2587 + if err == io.EOF { 2588 + err = io.ErrUnexpectedEOF 2589 + } 2590 + }() 2591 + 2592 + if maj != cbg.MajMap { 2593 + return fmt.Errorf("cbor input should be of type map") 2594 + } 2595 + 2596 + if extra > cbg.MaxLength { 2597 + return fmt.Errorf("SailorStar: map struct too large (%d)", extra) 2598 + } 2599 + 2600 + n := extra 2601 + 2602 + nameBuf := make([]byte, 9) 2603 + for i := uint64(0); i < n; i++ { 2604 + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) 2605 + if err != nil { 2606 + return err 2607 + } 2608 + 2609 + if !ok { 2610 + // Field doesn't exist on this type, so ignore it 2611 + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { 2612 + return err 2613 + } 2614 + continue 2615 + } 2616 + 2617 + switch string(nameBuf[:nameLen]) { 2618 + // t.LexiconTypeID (string) (string) 2619 + case "$type": 2620 + 2621 + { 2622 + sval, err := cbg.ReadStringWithMax(cr, 8192) 2623 + if err != nil { 2624 + return err 2625 + } 2626 + 2627 + t.LexiconTypeID = string(sval) 2628 + } 2629 + // t.Subject (atproto.SailorStar_Subject) (struct) 2630 + case "subject": 2631 + 2632 + { 2633 + 2634 + if err := t.Subject.UnmarshalCBOR(cr); err != nil { 2635 + return xerrors.Errorf("unmarshaling t.Subject: %w", err) 2636 + } 2637 + 2638 + } 2639 + // t.CreatedAt (string) (string) 2640 + case "createdAt": 2641 + 2642 + { 2643 + sval, err := cbg.ReadStringWithMax(cr, 8192) 2644 + if err != nil { 2645 + return err 2646 + } 2647 + 2648 + t.CreatedAt = string(sval) 2649 + } 2650 + 2651 + default: 2652 + // Field doesn't exist on this type, so ignore it 2653 + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { 2654 + return err 2655 + } 2656 + } 2657 + } 2658 + 2659 + return nil 2660 + } 2661 + func (t *SailorStar_Subject) MarshalCBOR(w io.Writer) error { 2662 + if t == nil { 2663 + _, err := w.Write(cbg.CborNull) 2664 + return err 2665 + } 2666 + 2667 + cw := cbg.NewCborWriter(w) 2668 + fieldCount := 3 2669 + 2670 + if t.LexiconTypeID == "" { 2671 + fieldCount-- 2672 + } 2673 + 2674 + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { 2675 + return err 2676 + } 2677 + 2678 + // t.Did (string) (string) 2679 + if len("did") > 8192 { 2680 + return xerrors.Errorf("Value in field \"did\" was too long") 2681 + } 2682 + 2683 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("did"))); err != nil { 2684 + return err 2685 + } 2686 + if _, err := cw.WriteString(string("did")); err != nil { 2687 + return err 2688 + } 2689 + 2690 + if len(t.Did) > 8192 { 2691 + return xerrors.Errorf("Value in field t.Did was too long") 2692 + } 2693 + 2694 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Did))); err != nil { 2695 + return err 2696 + } 2697 + if _, err := cw.WriteString(string(t.Did)); err != nil { 2698 + return err 2699 + } 2700 + 2701 + // t.LexiconTypeID (string) (string) 2702 + if t.LexiconTypeID != "" { 2703 + 2704 + if len("$type") > 8192 { 2705 + return xerrors.Errorf("Value in field \"$type\" was too long") 2706 + } 2707 + 2708 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { 2709 + return err 2710 + } 2711 + if _, err := cw.WriteString(string("$type")); err != nil { 2712 + return err 2713 + } 2714 + 2715 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.sailor.star#subject"))); err != nil { 2716 + return err 2717 + } 2718 + if _, err := cw.WriteString(string("io.atcr.sailor.star#subject")); err != nil { 2719 + return err 2720 + } 2721 + } 2722 + 2723 + // t.Repository (string) (string) 2724 + if len("repository") > 8192 { 2725 + return xerrors.Errorf("Value in field \"repository\" was too long") 2726 + } 2727 + 2728 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("repository"))); err != nil { 2729 + return err 2730 + } 2731 + if _, err := cw.WriteString(string("repository")); err != nil { 2732 + return err 2733 + } 2734 + 2735 + if len(t.Repository) > 8192 { 2736 + return xerrors.Errorf("Value in field t.Repository was too long") 2737 + } 2738 + 2739 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Repository))); err != nil { 2740 + return err 2741 + } 2742 + if _, err := cw.WriteString(string(t.Repository)); err != nil { 2743 + return err 2744 + } 2745 + return nil 2746 + } 2747 + 2748 + func (t *SailorStar_Subject) UnmarshalCBOR(r io.Reader) (err error) { 2749 + *t = SailorStar_Subject{} 2750 + 2751 + cr := cbg.NewCborReader(r) 2752 + 2753 + maj, extra, err := cr.ReadHeader() 2754 + if err != nil { 2755 + return err 2756 + } 2757 + defer func() { 2758 + if err == io.EOF { 2759 + err = io.ErrUnexpectedEOF 2760 + } 2761 + }() 2762 + 2763 + if maj != cbg.MajMap { 2764 + return fmt.Errorf("cbor input should be of type map") 2765 + } 2766 + 2767 + if extra > cbg.MaxLength { 2768 + return fmt.Errorf("SailorStar_Subject: map struct too large (%d)", extra) 2769 + } 2770 + 2771 + n := extra 2772 + 2773 + nameBuf := make([]byte, 10) 2774 + for i := uint64(0); i < n; i++ { 2775 + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) 2776 + if err != nil { 2777 + return err 2778 + } 2779 + 2780 + if !ok { 2781 + // Field doesn't exist on this type, so ignore it 2782 + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { 2783 + return err 2784 + } 2785 + continue 2786 + } 2787 + 2788 + switch string(nameBuf[:nameLen]) { 2789 + // t.Did (string) (string) 2790 + case "did": 2791 + 2792 + { 2793 + sval, err := cbg.ReadStringWithMax(cr, 8192) 2794 + if err != nil { 2795 + return err 2796 + } 2797 + 2798 + t.Did = string(sval) 2799 + } 2800 + // t.LexiconTypeID (string) (string) 2801 + case "$type": 2802 + 2803 + { 2804 + sval, err := cbg.ReadStringWithMax(cr, 8192) 2805 + if err != nil { 2806 + return err 2807 + } 2808 + 2809 + t.LexiconTypeID = string(sval) 2810 + } 2811 + // t.Repository (string) (string) 2812 + case "repository": 2813 + 2814 + { 2815 + sval, err := cbg.ReadStringWithMax(cr, 8192) 2816 + if err != nil { 2817 + return err 2818 + } 2819 + 2820 + t.Repository = string(sval) 2821 + } 2822 + 2823 + default: 2824 + // Field doesn't exist on this type, so ignore it 2825 + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { 2826 + return err 2827 + } 2828 + } 2829 + } 2830 + 2831 + return nil 2832 + } 2833 + func (t *HoldCaptain) MarshalCBOR(w io.Writer) error { 2834 + if t == nil { 2835 + _, err := w.Write(cbg.CborNull) 2836 + return err 2837 + } 2838 + 2839 + cw := cbg.NewCborWriter(w) 2840 + fieldCount := 8 2841 + 2842 + if t.Provider == nil { 2843 + fieldCount-- 2844 + } 2845 + 2846 + if t.Region == nil { 2847 + fieldCount-- 2848 + } 2849 + 2850 + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { 2851 + return err 2852 + } 2853 + 2854 + // t.LexiconTypeID (string) (string) 2855 + if len("$type") > 8192 { 2856 + return xerrors.Errorf("Value in field \"$type\" was too long") 2857 + } 2858 + 2859 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { 2860 + return err 2861 + } 2862 + if _, err := cw.WriteString(string("$type")); err != nil { 2863 + return err 2864 + } 2865 + 2866 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.hold.captain"))); err != nil { 2867 + return err 2868 + } 2869 + if _, err := cw.WriteString(string("io.atcr.hold.captain")); err != nil { 337 2870 return err 338 2871 } 339 2872 ··· 377 2910 } 378 2911 379 2912 // t.Region (string) (string) 380 - if t.Region != "" { 2913 + if t.Region != nil { 381 2914 382 2915 if len("region") > 8192 { 383 2916 return xerrors.Errorf("Value in field \"region\" was too long") ··· 390 2923 return err 391 2924 } 392 2925 393 - if len(t.Region) > 8192 { 394 - return xerrors.Errorf("Value in field t.Region was too long") 395 - } 2926 + if t.Region == nil { 2927 + if _, err := cw.Write(cbg.CborNull); err != nil { 2928 + return err 2929 + } 2930 + } else { 2931 + if len(*t.Region) > 8192 { 2932 + return xerrors.Errorf("Value in field t.Region was too long") 2933 + } 396 2934 397 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Region))); err != nil { 398 - return err 399 - } 400 - if _, err := cw.WriteString(string(t.Region)); err != nil { 401 - return err 2935 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Region))); err != nil { 2936 + return err 2937 + } 2938 + if _, err := cw.WriteString(string(*t.Region)); err != nil { 2939 + return err 2940 + } 402 2941 } 403 2942 } 404 2943 405 2944 // t.Provider (string) (string) 406 - if t.Provider != "" { 2945 + if t.Provider != nil { 407 2946 408 2947 if len("provider") > 8192 { 409 2948 return xerrors.Errorf("Value in field \"provider\" was too long") ··· 416 2955 return err 417 2956 } 418 2957 419 - if len(t.Provider) > 8192 { 420 - return xerrors.Errorf("Value in field t.Provider was too long") 421 - } 2958 + if t.Provider == nil { 2959 + if _, err := cw.Write(cbg.CborNull); err != nil { 2960 + return err 2961 + } 2962 + } else { 2963 + if len(*t.Provider) > 8192 { 2964 + return xerrors.Errorf("Value in field t.Provider was too long") 2965 + } 422 2966 423 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Provider))); err != nil { 424 - return err 425 - } 426 - if _, err := cw.WriteString(string(t.Provider)); err != nil { 427 - return err 2967 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Provider))); err != nil { 2968 + return err 2969 + } 2970 + if _, err := cw.WriteString(string(*t.Provider)); err != nil { 2971 + return err 2972 + } 428 2973 } 429 2974 } 430 2975 ··· 485 3030 return nil 486 3031 } 487 3032 488 - func (t *CaptainRecord) UnmarshalCBOR(r io.Reader) (err error) { 489 - *t = CaptainRecord{} 3033 + func (t *HoldCaptain) UnmarshalCBOR(r io.Reader) (err error) { 3034 + *t = HoldCaptain{} 490 3035 491 3036 cr := cbg.NewCborReader(r) 492 3037 ··· 505 3050 } 506 3051 507 3052 if extra > cbg.MaxLength { 508 - return fmt.Errorf("CaptainRecord: map struct too large (%d)", extra) 3053 + return fmt.Errorf("HoldCaptain: map struct too large (%d)", extra) 509 3054 } 510 3055 511 3056 n := extra ··· 526 3071 } 527 3072 528 3073 switch string(nameBuf[:nameLen]) { 529 - // t.Type (string) (string) 3074 + // t.LexiconTypeID (string) (string) 530 3075 case "$type": 531 3076 532 3077 { ··· 535 3080 return err 536 3081 } 537 3082 538 - t.Type = string(sval) 3083 + t.LexiconTypeID = string(sval) 539 3084 } 540 3085 // t.Owner (string) (string) 541 3086 case "owner": ··· 570 3115 case "region": 571 3116 572 3117 { 573 - sval, err := cbg.ReadStringWithMax(cr, 8192) 3118 + b, err := cr.ReadByte() 574 3119 if err != nil { 575 3120 return err 576 3121 } 3122 + if b != cbg.CborNull[0] { 3123 + if err := cr.UnreadByte(); err != nil { 3124 + return err 3125 + } 577 3126 578 - t.Region = string(sval) 3127 + sval, err := cbg.ReadStringWithMax(cr, 8192) 3128 + if err != nil { 3129 + return err 3130 + } 3131 + 3132 + t.Region = (*string)(&sval) 3133 + } 579 3134 } 580 3135 // t.Provider (string) (string) 581 3136 case "provider": 582 3137 583 3138 { 584 - sval, err := cbg.ReadStringWithMax(cr, 8192) 3139 + b, err := cr.ReadByte() 585 3140 if err != nil { 586 3141 return err 587 3142 } 3143 + if b != cbg.CborNull[0] { 3144 + if err := cr.UnreadByte(); err != nil { 3145 + return err 3146 + } 588 3147 589 - t.Provider = string(sval) 3148 + sval, err := cbg.ReadStringWithMax(cr, 8192) 3149 + if err != nil { 3150 + return err 3151 + } 3152 + 3153 + t.Provider = (*string)(&sval) 3154 + } 590 3155 } 591 3156 // t.DeployedAt (string) (string) 592 3157 case "deployedAt": ··· 646 3211 647 3212 return nil 648 3213 } 649 - func (t *LayerRecord) MarshalCBOR(w io.Writer) error { 3214 + func (t *HoldCrew) MarshalCBOR(w io.Writer) error { 3215 + if t == nil { 3216 + _, err := w.Write(cbg.CborNull) 3217 + return err 3218 + } 3219 + 3220 + cw := cbg.NewCborWriter(w) 3221 + 3222 + if _, err := cw.Write([]byte{165}); err != nil { 3223 + return err 3224 + } 3225 + 3226 + // t.Role (string) (string) 3227 + if len("role") > 8192 { 3228 + return xerrors.Errorf("Value in field \"role\" was too long") 3229 + } 3230 + 3231 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("role"))); err != nil { 3232 + return err 3233 + } 3234 + if _, err := cw.WriteString(string("role")); err != nil { 3235 + return err 3236 + } 3237 + 3238 + if len(t.Role) > 8192 { 3239 + return xerrors.Errorf("Value in field t.Role was too long") 3240 + } 3241 + 3242 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Role))); err != nil { 3243 + return err 3244 + } 3245 + if _, err := cw.WriteString(string(t.Role)); err != nil { 3246 + return err 3247 + } 3248 + 3249 + // t.LexiconTypeID (string) (string) 3250 + if len("$type") > 8192 { 3251 + return xerrors.Errorf("Value in field \"$type\" was too long") 3252 + } 3253 + 3254 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil { 3255 + return err 3256 + } 3257 + if _, err := cw.WriteString(string("$type")); err != nil { 3258 + return err 3259 + } 3260 + 3261 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.hold.crew"))); err != nil { 3262 + return err 3263 + } 3264 + if _, err := cw.WriteString(string("io.atcr.hold.crew")); err != nil { 3265 + return err 3266 + } 3267 + 3268 + // t.Member (string) (string) 3269 + if len("member") > 8192 { 3270 + return xerrors.Errorf("Value in field \"member\" was too long") 3271 + } 3272 + 3273 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("member"))); err != nil { 3274 + return err 3275 + } 3276 + if _, err := cw.WriteString(string("member")); err != nil { 3277 + return err 3278 + } 3279 + 3280 + if len(t.Member) > 8192 { 3281 + return xerrors.Errorf("Value in field t.Member was too long") 3282 + } 3283 + 3284 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Member))); err != nil { 3285 + return err 3286 + } 3287 + if _, err := cw.WriteString(string(t.Member)); err != nil { 3288 + return err 3289 + } 3290 + 3291 + // t.AddedAt (string) (string) 3292 + if len("addedAt") > 8192 { 3293 + return xerrors.Errorf("Value in field \"addedAt\" was too long") 3294 + } 3295 + 3296 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("addedAt"))); err != nil { 3297 + return err 3298 + } 3299 + if _, err := cw.WriteString(string("addedAt")); err != nil { 3300 + return err 3301 + } 3302 + 3303 + if len(t.AddedAt) > 8192 { 3304 + return xerrors.Errorf("Value in field t.AddedAt was too long") 3305 + } 3306 + 3307 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.AddedAt))); err != nil { 3308 + return err 3309 + } 3310 + if _, err := cw.WriteString(string(t.AddedAt)); err != nil { 3311 + return err 3312 + } 3313 + 3314 + // t.Permissions ([]string) (slice) 3315 + if len("permissions") > 8192 { 3316 + return xerrors.Errorf("Value in field \"permissions\" was too long") 3317 + } 3318 + 3319 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("permissions"))); err != nil { 3320 + return err 3321 + } 3322 + if _, err := cw.WriteString(string("permissions")); err != nil { 3323 + return err 3324 + } 3325 + 3326 + if len(t.Permissions) > 8192 { 3327 + return xerrors.Errorf("Slice value in field t.Permissions was too long") 3328 + } 3329 + 3330 + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Permissions))); err != nil { 3331 + return err 3332 + } 3333 + for _, v := range t.Permissions { 3334 + if len(v) > 8192 { 3335 + return xerrors.Errorf("Value in field v was too long") 3336 + } 3337 + 3338 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(v))); err != nil { 3339 + return err 3340 + } 3341 + if _, err := cw.WriteString(string(v)); err != nil { 3342 + return err 3343 + } 3344 + 3345 + } 3346 + return nil 3347 + } 3348 + 3349 + func (t *HoldCrew) UnmarshalCBOR(r io.Reader) (err error) { 3350 + *t = HoldCrew{} 3351 + 3352 + cr := cbg.NewCborReader(r) 3353 + 3354 + maj, extra, err := cr.ReadHeader() 3355 + if err != nil { 3356 + return err 3357 + } 3358 + defer func() { 3359 + if err == io.EOF { 3360 + err = io.ErrUnexpectedEOF 3361 + } 3362 + }() 3363 + 3364 + if maj != cbg.MajMap { 3365 + return fmt.Errorf("cbor input should be of type map") 3366 + } 3367 + 3368 + if extra > cbg.MaxLength { 3369 + return fmt.Errorf("HoldCrew: map struct too large (%d)", extra) 3370 + } 3371 + 3372 + n := extra 3373 + 3374 + nameBuf := make([]byte, 11) 3375 + for i := uint64(0); i < n; i++ { 3376 + nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 8192) 3377 + if err != nil { 3378 + return err 3379 + } 3380 + 3381 + if !ok { 3382 + // Field doesn't exist on this type, so ignore it 3383 + if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil { 3384 + return err 3385 + } 3386 + continue 3387 + } 3388 + 3389 + switch string(nameBuf[:nameLen]) { 3390 + // t.Role (string) (string) 3391 + case "role": 3392 + 3393 + { 3394 + sval, err := cbg.ReadStringWithMax(cr, 8192) 3395 + if err != nil { 3396 + return err 3397 + } 3398 + 3399 + t.Role = string(sval) 3400 + } 3401 + // t.LexiconTypeID (string) (string) 3402 + case "$type": 3403 + 3404 + { 3405 + sval, err := cbg.ReadStringWithMax(cr, 8192) 3406 + if err != nil { 3407 + return err 3408 + } 3409 + 3410 + t.LexiconTypeID = string(sval) 3411 + } 3412 + // t.Member (string) (string) 3413 + case "member": 3414 + 3415 + { 3416 + sval, err := cbg.ReadStringWithMax(cr, 8192) 3417 + if err != nil { 3418 + return err 3419 + } 3420 + 3421 + t.Member = string(sval) 3422 + } 3423 + // t.AddedAt (string) (string) 3424 + case "addedAt": 3425 + 3426 + { 3427 + sval, err := cbg.ReadStringWithMax(cr, 8192) 3428 + if err != nil { 3429 + return err 3430 + } 3431 + 3432 + t.AddedAt = string(sval) 3433 + } 3434 + // t.Permissions ([]string) (slice) 3435 + case "permissions": 3436 + 3437 + maj, extra, err = cr.ReadHeader() 3438 + if err != nil { 3439 + return err 3440 + } 3441 + 3442 + if extra > 8192 { 3443 + return fmt.Errorf("t.Permissions: array too large (%d)", extra) 3444 + } 3445 + 3446 + if maj != cbg.MajArray { 3447 + return fmt.Errorf("expected cbor array") 3448 + } 3449 + 3450 + if extra > 0 { 3451 + t.Permissions = make([]string, extra) 3452 + } 3453 + 3454 + for i := 0; i < int(extra); i++ { 3455 + { 3456 + var maj byte 3457 + var extra uint64 3458 + var err error 3459 + _ = maj 3460 + _ = extra 3461 + _ = err 3462 + 3463 + { 3464 + sval, err := cbg.ReadStringWithMax(cr, 8192) 3465 + if err != nil { 3466 + return err 3467 + } 3468 + 3469 + t.Permissions[i] = string(sval) 3470 + } 3471 + 3472 + } 3473 + } 3474 + 3475 + default: 3476 + // Field doesn't exist on this type, so ignore it 3477 + if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil { 3478 + return err 3479 + } 3480 + } 3481 + } 3482 + 3483 + return nil 3484 + } 3485 + func (t *HoldLayer) MarshalCBOR(w io.Writer) error { 650 3486 if t == nil { 651 3487 _, err := w.Write(cbg.CborNull) 652 3488 return err ··· 680 3516 } 681 3517 } 682 3518 683 - // t.Type (string) (string) 3519 + // t.LexiconTypeID (string) (string) 684 3520 if len("$type") > 8192 { 685 3521 return xerrors.Errorf("Value in field \"$type\" was too long") 686 3522 } ··· 692 3528 return err 693 3529 } 694 3530 695 - if len(t.Type) > 8192 { 696 - return xerrors.Errorf("Value in field t.Type was too long") 697 - } 698 - 699 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Type))); err != nil { 3531 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("io.atcr.hold.layer"))); err != nil { 700 3532 return err 701 3533 } 702 - if _, err := cw.WriteString(string(t.Type)); err != nil { 3534 + if _, err := cw.WriteString(string("io.atcr.hold.layer")); err != nil { 703 3535 return err 704 3536 } 705 3537 ··· 726 3558 return err 727 3559 } 728 3560 729 - // t.UserDID (string) (string) 3561 + // t.UserDid (string) (string) 730 3562 if len("userDid") > 8192 { 731 3563 return xerrors.Errorf("Value in field \"userDid\" was too long") 732 3564 } ··· 738 3570 return err 739 3571 } 740 3572 741 - if len(t.UserDID) > 8192 { 742 - return xerrors.Errorf("Value in field t.UserDID was too long") 3573 + if len(t.UserDid) > 8192 { 3574 + return xerrors.Errorf("Value in field t.UserDid was too long") 743 3575 } 744 3576 745 - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.UserDID))); err != nil { 3577 + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.UserDid))); err != nil { 746 3578 return err 747 3579 } 748 - if _, err := cw.WriteString(string(t.UserDID)); err != nil { 3580 + if _, err := cw.WriteString(string(t.UserDid)); err != nil { 749 3581 return err 750 3582 } 751 3583 ··· 843 3675 return nil 844 3676 } 845 3677 846 - func (t *LayerRecord) UnmarshalCBOR(r io.Reader) (err error) { 847 - *t = LayerRecord{} 3678 + func (t *HoldLayer) UnmarshalCBOR(r io.Reader) (err error) { 3679 + *t = HoldLayer{} 848 3680 849 3681 cr := cbg.NewCborReader(r) 850 3682 ··· 863 3695 } 864 3696 865 3697 if extra > cbg.MaxLength { 866 - return fmt.Errorf("LayerRecord: map struct too large (%d)", extra) 3698 + return fmt.Errorf("HoldLayer: map struct too large (%d)", extra) 867 3699 } 868 3700 869 3701 n := extra ··· 910 3742 911 3743 t.Size = int64(extraI) 912 3744 } 913 - // t.Type (string) (string) 3745 + // t.LexiconTypeID (string) (string) 914 3746 case "$type": 915 3747 916 3748 { ··· 919 3751 return err 920 3752 } 921 3753 922 - t.Type = string(sval) 3754 + t.LexiconTypeID = string(sval) 923 3755 } 924 3756 // t.Digest (string) (string) 925 3757 case "digest": ··· 932 3764 933 3765 t.Digest = string(sval) 934 3766 } 935 - // t.UserDID (string) (string) 3767 + // t.UserDid (string) (string) 936 3768 case "userDid": 937 3769 938 3770 { ··· 941 3773 return err 942 3774 } 943 3775 944 - t.UserDID = string(sval) 3776 + t.UserDid = string(sval) 945 3777 } 946 3778 // t.CreatedAt (string) (string) 947 3779 case "createdAt":
+255 -11
pkg/atproto/generate.go
··· 3 3 4 4 package main 5 5 6 - // CBOR Code Generator 6 + // Lexicon and CBOR Code Generator 7 7 // 8 - // This generates optimized CBOR marshaling code for ATProto records. 8 + // This generates: 9 + // 1. Go types from lexicon JSON files (via lex/lexgen library) 10 + // 2. CBOR marshaling code for ATProto records (via cbor-gen) 11 + // 3. Type registration for lexutil (register.go) 9 12 // 10 13 // Usage: 11 14 // go generate ./pkg/atproto/... 12 15 // 13 - // This creates pkg/atproto/cbor_gen.go which should be committed to git. 14 - // Only re-run when you modify types in pkg/atproto/types.go 15 - // 16 - // The //go:generate directive is in lexicon.go 16 + // Key insight: We use RegisterLexiconTypeID: false to avoid generating init() 17 + // blocks that require CBORMarshaler. This breaks the circular dependency between 18 + // lexgen and cbor-gen. See: https://github.com/bluesky-social/indigo/issues/931 19 + 20 + import ( 21 + "bytes" 22 + "encoding/json" 23 + "fmt" 24 + "os" 25 + "os/exec" 26 + "path/filepath" 27 + "strings" 28 + 29 + "github.com/bluesky-social/indigo/atproto/lexicon" 30 + "github.com/bluesky-social/indigo/lex/lexgen" 31 + "golang.org/x/tools/imports" 32 + ) 33 + 34 + func main() { 35 + // Find repo root 36 + repoRoot, err := findRepoRoot() 37 + if err != nil { 38 + fmt.Printf("failed to find repo root: %v\n", err) 39 + os.Exit(1) 40 + } 41 + 42 + pkgDir := filepath.Join(repoRoot, "pkg/atproto") 43 + lexDir := filepath.Join(repoRoot, "lexicons") 44 + 45 + // Step 0: Clean up old register.go to avoid conflicts 46 + // (It will be regenerated at the end) 47 + os.Remove(filepath.Join(pkgDir, "register.go")) 48 + 49 + // Step 1: Load all lexicon schemas into catalog (for cross-references) 50 + fmt.Println("Loading lexicons...") 51 + cat := lexicon.NewBaseCatalog() 52 + if err := cat.LoadDirectory(lexDir); err != nil { 53 + fmt.Printf("failed to load lexicons: %v\n", err) 54 + os.Exit(1) 55 + } 56 + 57 + // Step 2: Generate Go code for each lexicon file 58 + fmt.Println("Running lexgen...") 59 + config := &lexgen.GenConfig{ 60 + RegisterLexiconTypeID: false, // KEY: no init() blocks generated 61 + UnknownType: "map-string-any", 62 + WarningText: "Code generated by generate.go; DO NOT EDIT.", 63 + } 64 + 65 + // Track generated types for register.go 66 + var registeredTypes []typeInfo 67 + 68 + // Walk lexicon directory and generate code for each file 69 + err = filepath.Walk(lexDir, func(path string, info os.FileInfo, err error) error { 70 + if err != nil { 71 + return err 72 + } 73 + if info.IsDir() || !strings.HasSuffix(path, ".json") { 74 + return nil 75 + } 76 + 77 + // Load and parse the schema file 78 + data, err := os.ReadFile(path) 79 + if err != nil { 80 + return fmt.Errorf("failed to read %s: %w", path, err) 81 + } 82 + 83 + var sf lexicon.SchemaFile 84 + if err := json.Unmarshal(data, &sf); err != nil { 85 + return fmt.Errorf("failed to parse %s: %w", path, err) 86 + } 87 + 88 + if err := sf.FinishParse(); err != nil { 89 + return fmt.Errorf("failed to finish parse %s: %w", path, err) 90 + } 91 + 92 + // Flatten the schema 93 + flat, err := lexgen.FlattenSchemaFile(&sf) 94 + if err != nil { 95 + return fmt.Errorf("failed to flatten schema %s: %w", path, err) 96 + } 97 + 98 + // Generate code 99 + var buf bytes.Buffer 100 + gen := &lexgen.CodeGenerator{ 101 + Config: config, 102 + Lex: flat, 103 + Cat: &cat, 104 + Out: &buf, 105 + } 106 + 107 + if err := gen.WriteLexicon(); err != nil { 108 + return fmt.Errorf("failed to generate code for %s: %w", path, err) 109 + } 110 + 111 + // Fix package name: lexgen generates "ioatcr" but we want "atproto" 112 + code := bytes.Replace(buf.Bytes(), []byte("package ioatcr"), []byte("package atproto"), 1) 113 + 114 + // Format with goimports 115 + fileName := gen.FileName() 116 + formatted, err := imports.Process(fileName, code, nil) 117 + if err != nil { 118 + // Write unformatted for debugging 119 + outPath := filepath.Join(pkgDir, fileName) 120 + os.WriteFile(outPath+".broken", code, 0644) 121 + return fmt.Errorf("failed to format %s: %w (wrote to %s.broken)", fileName, err, outPath) 122 + } 123 + 124 + // Write output file 125 + outPath := filepath.Join(pkgDir, fileName) 126 + if err := os.WriteFile(outPath, formatted, 0644); err != nil { 127 + return fmt.Errorf("failed to write %s: %w", outPath, err) 128 + } 129 + 130 + fmt.Printf(" Generated %s\n", fileName) 131 + 132 + // Track type for registration - compute type name from NSID 133 + typeName := nsidToTypeName(sf.ID) 134 + registeredTypes = append(registeredTypes, typeInfo{ 135 + NSID: sf.ID, 136 + TypeName: typeName, 137 + }) 138 + 139 + return nil 140 + }) 141 + if err != nil { 142 + fmt.Printf("lexgen failed: %v\n", err) 143 + os.Exit(1) 144 + } 145 + 146 + // Step 3: Run cbor-gen via exec.Command 147 + // This must be a separate process so it can compile the freshly generated types 148 + fmt.Println("Running cbor-gen...") 149 + if err := runCborGen(repoRoot, pkgDir); err != nil { 150 + fmt.Printf("cbor-gen failed: %v\n", err) 151 + os.Exit(1) 152 + } 153 + 154 + // Step 4: Generate register.go 155 + fmt.Println("Generating register.go...") 156 + if err := generateRegisterFile(pkgDir, registeredTypes); err != nil { 157 + fmt.Printf("failed to generate register.go: %v\n", err) 158 + os.Exit(1) 159 + } 160 + 161 + fmt.Println("Code generation complete!") 162 + } 163 + 164 + type typeInfo struct { 165 + NSID string 166 + TypeName string 167 + } 168 + 169 + // nsidToTypeName converts an NSID to a Go type name 170 + // io.atcr.manifest → Manifest 171 + // io.atcr.hold.captain → HoldCaptain 172 + // io.atcr.sailor.profile → SailorProfile 173 + func nsidToTypeName(nsid string) string { 174 + parts := strings.Split(nsid, ".") 175 + if len(parts) < 3 { 176 + return "" 177 + } 178 + // Skip the first two parts (authority, e.g., "io.atcr") 179 + // and capitalize each remaining part 180 + var result string 181 + for _, part := range parts[2:] { 182 + if len(part) > 0 { 183 + result += strings.ToUpper(part[:1]) + part[1:] 184 + } 185 + } 186 + return result 187 + } 188 + 189 + func runCborGen(repoRoot, pkgDir string) error { 190 + // Create a temporary Go file that runs cbor-gen 191 + cborGenCode := `//go:build ignore 192 + 193 + package main 17 194 18 195 import ( 19 196 "fmt" ··· 25 202 ) 26 203 27 204 func main() { 28 - // Generate map-style encoders for CrewRecord, CaptainRecord, LayerRecord, and TangledProfileRecord 29 205 if err := cbg.WriteMapEncodersToFile("cbor_gen.go", "atproto", 30 - atproto.CrewRecord{}, 31 - atproto.CaptainRecord{}, 32 - atproto.LayerRecord{}, 206 + // Manifest types 207 + atproto.Manifest{}, 208 + atproto.Manifest_BlobReference{}, 209 + atproto.Manifest_ManifestReference{}, 210 + atproto.Manifest_Platform{}, 211 + atproto.Manifest_Annotations{}, 212 + atproto.Manifest_BlobReference_Annotations{}, 213 + atproto.Manifest_ManifestReference_Annotations{}, 214 + // Tag 215 + atproto.Tag{}, 216 + // Sailor types 217 + atproto.SailorProfile{}, 218 + atproto.SailorStar{}, 219 + atproto.SailorStar_Subject{}, 220 + // Hold types 221 + atproto.HoldCaptain{}, 222 + atproto.HoldCrew{}, 223 + atproto.HoldLayer{}, 224 + // External types 33 225 atproto.TangledProfileRecord{}, 34 226 ); err != nil { 35 - fmt.Printf("Failed to generate CBOR encoders: %v\n", err) 227 + fmt.Printf("cbor-gen failed: %v\n", err) 36 228 os.Exit(1) 37 229 } 38 230 } 231 + ` 232 + 233 + // Write temp file 234 + tmpFile := filepath.Join(pkgDir, "cborgen_tmp.go") 235 + if err := os.WriteFile(tmpFile, []byte(cborGenCode), 0644); err != nil { 236 + return fmt.Errorf("failed to write temp cbor-gen file: %w", err) 237 + } 238 + defer os.Remove(tmpFile) 239 + 240 + // Run it 241 + cmd := exec.Command("go", "run", tmpFile) 242 + cmd.Dir = pkgDir 243 + cmd.Stdout = os.Stdout 244 + cmd.Stderr = os.Stderr 245 + return cmd.Run() 246 + } 247 + 248 + func generateRegisterFile(pkgDir string, types []typeInfo) error { 249 + var buf bytes.Buffer 250 + 251 + buf.WriteString("// Code generated by generate.go; DO NOT EDIT.\n\n") 252 + buf.WriteString("package atproto\n\n") 253 + buf.WriteString("import lexutil \"github.com/bluesky-social/indigo/lex/util\"\n\n") 254 + buf.WriteString("func init() {\n") 255 + 256 + for _, t := range types { 257 + fmt.Fprintf(&buf, "\tlexutil.RegisterType(%q, &%s{})\n", t.NSID, t.TypeName) 258 + } 259 + 260 + buf.WriteString("}\n") 261 + 262 + outPath := filepath.Join(pkgDir, "register.go") 263 + return os.WriteFile(outPath, buf.Bytes(), 0644) 264 + } 265 + 266 + func findRepoRoot() (string, error) { 267 + dir, err := os.Getwd() 268 + if err != nil { 269 + return "", err 270 + } 271 + 272 + for { 273 + if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil { 274 + return dir, nil 275 + } 276 + parent := filepath.Dir(dir) 277 + if parent == dir { 278 + return "", fmt.Errorf("go.mod not found") 279 + } 280 + dir = parent 281 + } 282 + }
+24
pkg/atproto/holdcaptain.go
··· 1 + // Code generated by generate.go; DO NOT EDIT. 2 + 3 + // Lexicon schema: io.atcr.hold.captain 4 + 5 + package atproto 6 + 7 + // Represents the hold's ownership and metadata. Stored as a singleton record at rkey 'self' in the hold's embedded PDS. 8 + type HoldCaptain struct { 9 + LexiconTypeID string `json:"$type" cborgen:"$type,const=io.atcr.hold.captain"` 10 + // allowAllCrew: Allow any authenticated user to register as crew 11 + AllowAllCrew bool `json:"allowAllCrew" cborgen:"allowAllCrew"` 12 + // deployedAt: RFC3339 timestamp of when the hold was deployed 13 + DeployedAt string `json:"deployedAt" cborgen:"deployedAt"` 14 + // enableBlueskyPosts: Enable Bluesky posts when manifests are pushed 15 + EnableBlueskyPosts bool `json:"enableBlueskyPosts" cborgen:"enableBlueskyPosts"` 16 + // owner: DID of the hold owner 17 + Owner string `json:"owner" cborgen:"owner"` 18 + // provider: Deployment provider (e.g., fly.io, aws, etc.) 19 + Provider *string `json:"provider,omitempty" cborgen:"provider,omitempty"` 20 + // public: Whether this hold allows public blob reads (pulls) without authentication 21 + Public bool `json:"public" cborgen:"public"` 22 + // region: S3 region where blobs are stored 23 + Region *string `json:"region,omitempty" cborgen:"region,omitempty"` 24 + }
+18
pkg/atproto/holdcrew.go
··· 1 + // Code generated by generate.go; DO NOT EDIT. 2 + 3 + // Lexicon schema: io.atcr.hold.crew 4 + 5 + package atproto 6 + 7 + // 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). 8 + type HoldCrew struct { 9 + LexiconTypeID string `json:"$type" cborgen:"$type,const=io.atcr.hold.crew"` 10 + // addedAt: RFC3339 timestamp of when the member was added 11 + AddedAt string `json:"addedAt" cborgen:"addedAt"` 12 + // member: DID of the crew member 13 + Member string `json:"member" cborgen:"member"` 14 + // permissions: Specific permissions granted to this member 15 + Permissions []string `json:"permissions" cborgen:"permissions"` 16 + // role: Member's role in the hold 17 + Role string `json:"role" cborgen:"role"` 18 + }
+24
pkg/atproto/holdlayer.go
··· 1 + // Code generated by generate.go; DO NOT EDIT. 2 + 3 + // Lexicon schema: io.atcr.hold.layer 4 + 5 + package atproto 6 + 7 + // Represents metadata about a container layer stored in the hold. Stored in the hold's embedded PDS for tracking and analytics. 8 + type HoldLayer struct { 9 + LexiconTypeID string `json:"$type" cborgen:"$type,const=io.atcr.hold.layer"` 10 + // createdAt: RFC3339 timestamp of when the layer was uploaded 11 + CreatedAt string `json:"createdAt" cborgen:"createdAt"` 12 + // digest: Layer digest (e.g., sha256:abc123...) 13 + Digest string `json:"digest" cborgen:"digest"` 14 + // mediaType: Media type (e.g., application/vnd.oci.image.layer.v1.tar+gzip) 15 + MediaType string `json:"mediaType" cborgen:"mediaType"` 16 + // repository: Repository this layer belongs to 17 + Repository string `json:"repository" cborgen:"repository"` 18 + // size: Size in bytes 19 + Size int64 `json:"size" cborgen:"size"` 20 + // userDid: DID of user who uploaded this layer 21 + UserDid string `json:"userDid" cborgen:"userDid"` 22 + // userHandle: Handle of user (for display purposes) 23 + UserHandle string `json:"userHandle" cborgen:"userHandle"` 24 + }
+103
pkg/atproto/manifest.go
··· 1 + // Code generated by generate.go; DO NOT EDIT. 2 + 3 + // Lexicon schema: io.atcr.manifest 4 + 5 + package atproto 6 + 7 + import ( 8 + lexutil "github.com/bluesky-social/indigo/lex/util" 9 + ) 10 + 11 + // A container image manifest following OCI specification, stored in ATProto 12 + type Manifest struct { 13 + LexiconTypeID string `json:"$type" cborgen:"$type,const=io.atcr.manifest"` 14 + // annotations: Optional metadata annotations 15 + Annotations *Manifest_Annotations `json:"annotations,omitempty" cborgen:"annotations,omitempty"` 16 + // config: Reference to image configuration blob 17 + Config *Manifest_BlobReference `json:"config,omitempty" cborgen:"config,omitempty"` 18 + // createdAt: Record creation timestamp 19 + CreatedAt string `json:"createdAt" cborgen:"createdAt"` 20 + // digest: Content digest (e.g., 'sha256:abc123...') 21 + Digest string `json:"digest" cborgen:"digest"` 22 + // holdDid: DID of the hold service where blobs are stored (e.g., 'did:web:hold01.atcr.io'). Primary reference for hold resolution. 23 + HoldDid *string `json:"holdDid,omitempty" cborgen:"holdDid,omitempty"` 24 + // holdEndpoint: Hold service endpoint URL where blobs are stored. DEPRECATED: Use holdDid instead. Kept for backward compatibility. 25 + HoldEndpoint *string `json:"holdEndpoint,omitempty" cborgen:"holdEndpoint,omitempty"` 26 + // layers: Filesystem layers (for image manifests) 27 + Layers []Manifest_BlobReference `json:"layers,omitempty" cborgen:"layers,omitempty"` 28 + // manifestBlob: The full OCI manifest stored as a blob in ATProto. 29 + ManifestBlob *lexutil.LexBlob `json:"manifestBlob,omitempty" cborgen:"manifestBlob,omitempty"` 30 + // manifests: Referenced manifests (for manifest lists/indexes) 31 + Manifests []Manifest_ManifestReference `json:"manifests,omitempty" cborgen:"manifests,omitempty"` 32 + // mediaType: OCI media type 33 + MediaType string `json:"mediaType" cborgen:"mediaType"` 34 + // repository: Repository name (e.g., 'myapp'). Scoped to user's DID. 35 + Repository string `json:"repository" cborgen:"repository"` 36 + // schemaVersion: OCI schema version (typically 2) 37 + SchemaVersion int64 `json:"schemaVersion" cborgen:"schemaVersion"` 38 + // subject: Optional reference to another manifest (for attestations, signatures) 39 + Subject *Manifest_BlobReference `json:"subject,omitempty" cborgen:"subject,omitempty"` 40 + } 41 + 42 + // Optional metadata annotations 43 + type Manifest_Annotations struct { 44 + } 45 + 46 + // Manifest_BlobReference is a "blobReference" in the io.atcr.manifest schema. 47 + // 48 + // Reference to a blob stored in S3 or external storage 49 + type Manifest_BlobReference struct { 50 + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,const=io.atcr.manifest#blobReference,omitempty"` 51 + // annotations: Optional metadata 52 + Annotations *Manifest_BlobReference_Annotations `json:"annotations,omitempty" cborgen:"annotations,omitempty"` 53 + // digest: Content digest (e.g., 'sha256:...') 54 + Digest string `json:"digest" cborgen:"digest"` 55 + // mediaType: MIME type of the blob 56 + MediaType string `json:"mediaType" cborgen:"mediaType"` 57 + // size: Size in bytes 58 + Size int64 `json:"size" cborgen:"size"` 59 + // urls: Optional direct URLs to blob (for BYOS) 60 + Urls []string `json:"urls,omitempty" cborgen:"urls,omitempty"` 61 + } 62 + 63 + // Optional metadata 64 + type Manifest_BlobReference_Annotations struct { 65 + } 66 + 67 + // Manifest_ManifestReference is a "manifestReference" in the io.atcr.manifest schema. 68 + // 69 + // Reference to a manifest in a manifest list/index 70 + type Manifest_ManifestReference struct { 71 + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,const=io.atcr.manifest#manifestReference,omitempty"` 72 + // annotations: Optional metadata 73 + Annotations *Manifest_ManifestReference_Annotations `json:"annotations,omitempty" cborgen:"annotations,omitempty"` 74 + // digest: Content digest (e.g., 'sha256:...') 75 + Digest string `json:"digest" cborgen:"digest"` 76 + // mediaType: Media type of the referenced manifest 77 + MediaType string `json:"mediaType" cborgen:"mediaType"` 78 + // platform: Platform information for this manifest 79 + Platform *Manifest_Platform `json:"platform,omitempty" cborgen:"platform,omitempty"` 80 + // size: Size in bytes 81 + Size int64 `json:"size" cborgen:"size"` 82 + } 83 + 84 + // Optional metadata 85 + type Manifest_ManifestReference_Annotations struct { 86 + } 87 + 88 + // Manifest_Platform is a "platform" in the io.atcr.manifest schema. 89 + // 90 + // Platform information describing OS and architecture 91 + type Manifest_Platform struct { 92 + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,const=io.atcr.manifest#platform,omitempty"` 93 + // architecture: CPU architecture (e.g., 'amd64', 'arm64', 'arm') 94 + Architecture string `json:"architecture" cborgen:"architecture"` 95 + // os: Operating system (e.g., 'linux', 'windows', 'darwin') 96 + Os string `json:"os" cborgen:"os"` 97 + // osFeatures: Optional OS features 98 + OsFeatures []string `json:"osFeatures,omitempty" cborgen:"osFeatures,omitempty"` 99 + // osVersion: Optional OS version 100 + OsVersion *string `json:"osVersion,omitempty" cborgen:"osVersion,omitempty"` 101 + // variant: Optional CPU variant (e.g., 'v7' for ARM) 102 + Variant *string `json:"variant,omitempty" cborgen:"variant,omitempty"` 103 + }
+15
pkg/atproto/register.go
··· 1 + // Code generated by generate.go; DO NOT EDIT. 2 + 3 + package atproto 4 + 5 + import lexutil "github.com/bluesky-social/indigo/lex/util" 6 + 7 + func init() { 8 + lexutil.RegisterType("io.atcr.hold.captain", &HoldCaptain{}) 9 + lexutil.RegisterType("io.atcr.hold.crew", &HoldCrew{}) 10 + lexutil.RegisterType("io.atcr.hold.layer", &HoldLayer{}) 11 + lexutil.RegisterType("io.atcr.manifest", &Manifest{}) 12 + lexutil.RegisterType("io.atcr.sailor.profile", &SailorProfile{}) 13 + lexutil.RegisterType("io.atcr.sailor.star", &SailorStar{}) 14 + lexutil.RegisterType("io.atcr.tag", &Tag{}) 15 + }
+16
pkg/atproto/sailorprofile.go
··· 1 + // Code generated by generate.go; DO NOT EDIT. 2 + 3 + // Lexicon schema: io.atcr.sailor.profile 4 + 5 + package atproto 6 + 7 + // User profile for ATCR registry. Stores preferences like default hold for blob storage. 8 + type SailorProfile struct { 9 + LexiconTypeID string `json:"$type" cborgen:"$type,const=io.atcr.sailor.profile"` 10 + // createdAt: Profile creation timestamp 11 + CreatedAt string `json:"createdAt" cborgen:"createdAt"` 12 + // defaultHold: Default hold endpoint for blob storage. If null, user has opted out of defaults. 13 + DefaultHold *string `json:"defaultHold,omitempty" cborgen:"defaultHold,omitempty"` 14 + // updatedAt: Profile last updated timestamp 15 + UpdatedAt *string `json:"updatedAt,omitempty" cborgen:"updatedAt,omitempty"` 16 + }
+25
pkg/atproto/sailorstar.go
··· 1 + // Code generated by generate.go; DO NOT EDIT. 2 + 3 + // Lexicon schema: io.atcr.sailor.star 4 + 5 + package atproto 6 + 7 + // A star (like) on a container image repository. Stored in the starrer's PDS, similar to Bluesky likes. 8 + type SailorStar struct { 9 + LexiconTypeID string `json:"$type" cborgen:"$type,const=io.atcr.sailor.star"` 10 + // createdAt: Star creation timestamp 11 + CreatedAt string `json:"createdAt" cborgen:"createdAt"` 12 + // subject: The repository being starred 13 + Subject SailorStar_Subject `json:"subject" cborgen:"subject"` 14 + } 15 + 16 + // SailorStar_Subject is a "subject" in the io.atcr.sailor.star schema. 17 + // 18 + // Reference to a repository owned by a user 19 + type SailorStar_Subject struct { 20 + LexiconTypeID string `json:"$type,omitempty" cborgen:"$type,const=io.atcr.sailor.star#subject,omitempty"` 21 + // did: DID of the repository owner 22 + Did string `json:"did" cborgen:"did"` 23 + // repository: Repository name (e.g., 'myapp') 24 + Repository string `json:"repository" cborgen:"repository"` 25 + }
+20
pkg/atproto/tag.go
··· 1 + // Code generated by generate.go; DO NOT EDIT. 2 + 3 + // Lexicon schema: io.atcr.tag 4 + 5 + package atproto 6 + 7 + // A named tag pointing to a specific manifest digest 8 + type Tag struct { 9 + LexiconTypeID string `json:"$type" cborgen:"$type,const=io.atcr.tag"` 10 + // createdAt: Tag creation timestamp 11 + CreatedAt string `json:"createdAt" cborgen:"createdAt"` 12 + // 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. 13 + Manifest *string `json:"manifest,omitempty" cborgen:"manifest,omitempty"` 14 + // manifestDigest: DEPRECATED: Digest of the manifest (e.g., 'sha256:...'). Kept for backward compatibility with old records. New records should use 'manifest' field instead. 15 + ManifestDigest *string `json:"manifestDigest,omitempty" cborgen:"manifestDigest,omitempty"` 16 + // repository: Repository name (e.g., 'myapp'). Scoped to user's DID. 17 + Repository string `json:"repository" cborgen:"repository"` 18 + // tag: Tag name (e.g., 'latest', 'v1.0.0', '12-slim') 19 + Tag string `json:"tag" cborgen:"tag"` 20 + }