···
564
+
func (t *Comment) MarshalCBOR(w io.Writer) error {
566
+
_, err := w.Write(cbg.CborNull)
570
+
cw := cbg.NewCborWriter(w)
573
+
if t.Mentions == nil {
577
+
if t.References == nil {
581
+
if t.ReplyTo == nil {
585
+
if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil {
589
+
// t.Body (string) (string)
590
+
if len("body") > 1000000 {
591
+
return xerrors.Errorf("Value in field \"body\" was too long")
594
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("body"))); err != nil {
597
+
if _, err := cw.WriteString(string("body")); err != nil {
601
+
if len(t.Body) > 1000000 {
602
+
return xerrors.Errorf("Value in field t.Body was too long")
605
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Body))); err != nil {
608
+
if _, err := cw.WriteString(string(t.Body)); err != nil {
612
+
// t.LexiconTypeID (string) (string)
613
+
if len("$type") > 1000000 {
614
+
return xerrors.Errorf("Value in field \"$type\" was too long")
617
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("$type"))); err != nil {
620
+
if _, err := cw.WriteString(string("$type")); err != nil {
624
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("sh.tangled.comment"))); err != nil {
627
+
if _, err := cw.WriteString(string("sh.tangled.comment")); err != nil {
631
+
// t.ReplyTo (string) (string)
632
+
if t.ReplyTo != nil {
634
+
if len("replyTo") > 1000000 {
635
+
return xerrors.Errorf("Value in field \"replyTo\" was too long")
638
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("replyTo"))); err != nil {
641
+
if _, err := cw.WriteString(string("replyTo")); err != nil {
645
+
if t.ReplyTo == nil {
646
+
if _, err := cw.Write(cbg.CborNull); err != nil {
650
+
if len(*t.ReplyTo) > 1000000 {
651
+
return xerrors.Errorf("Value in field t.ReplyTo was too long")
654
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.ReplyTo))); err != nil {
657
+
if _, err := cw.WriteString(string(*t.ReplyTo)); err != nil {
663
+
// t.Subject (string) (string)
664
+
if len("subject") > 1000000 {
665
+
return xerrors.Errorf("Value in field \"subject\" was too long")
668
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("subject"))); err != nil {
671
+
if _, err := cw.WriteString(string("subject")); err != nil {
675
+
if len(t.Subject) > 1000000 {
676
+
return xerrors.Errorf("Value in field t.Subject was too long")
679
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Subject))); err != nil {
682
+
if _, err := cw.WriteString(string(t.Subject)); err != nil {
686
+
// t.Mentions ([]string) (slice)
687
+
if t.Mentions != nil {
689
+
if len("mentions") > 1000000 {
690
+
return xerrors.Errorf("Value in field \"mentions\" was too long")
693
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("mentions"))); err != nil {
696
+
if _, err := cw.WriteString(string("mentions")); err != nil {
700
+
if len(t.Mentions) > 8192 {
701
+
return xerrors.Errorf("Slice value in field t.Mentions was too long")
704
+
if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Mentions))); err != nil {
707
+
for _, v := range t.Mentions {
708
+
if len(v) > 1000000 {
709
+
return xerrors.Errorf("Value in field v was too long")
712
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(v))); err != nil {
715
+
if _, err := cw.WriteString(string(v)); err != nil {
722
+
// t.CreatedAt (string) (string)
723
+
if len("createdAt") > 1000000 {
724
+
return xerrors.Errorf("Value in field \"createdAt\" was too long")
727
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("createdAt"))); err != nil {
730
+
if _, err := cw.WriteString(string("createdAt")); err != nil {
734
+
if len(t.CreatedAt) > 1000000 {
735
+
return xerrors.Errorf("Value in field t.CreatedAt was too long")
738
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.CreatedAt))); err != nil {
741
+
if _, err := cw.WriteString(string(t.CreatedAt)); err != nil {
745
+
// t.References ([]string) (slice)
746
+
if t.References != nil {
748
+
if len("references") > 1000000 {
749
+
return xerrors.Errorf("Value in field \"references\" was too long")
752
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("references"))); err != nil {
755
+
if _, err := cw.WriteString(string("references")); err != nil {
759
+
if len(t.References) > 8192 {
760
+
return xerrors.Errorf("Slice value in field t.References was too long")
763
+
if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.References))); err != nil {
766
+
for _, v := range t.References {
767
+
if len(v) > 1000000 {
768
+
return xerrors.Errorf("Value in field v was too long")
771
+
if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(v))); err != nil {
774
+
if _, err := cw.WriteString(string(v)); err != nil {
783
+
func (t *Comment) UnmarshalCBOR(r io.Reader) (err error) {
786
+
cr := cbg.NewCborReader(r)
788
+
maj, extra, err := cr.ReadHeader()
794
+
err = io.ErrUnexpectedEOF
798
+
if maj != cbg.MajMap {
799
+
return fmt.Errorf("cbor input should be of type map")
802
+
if extra > cbg.MaxLength {
803
+
return fmt.Errorf("Comment: map struct too large (%d)", extra)
808
+
nameBuf := make([]byte, 10)
809
+
for i := uint64(0); i < n; i++ {
810
+
nameLen, ok, err := cbg.ReadFullStringIntoBuf(cr, nameBuf, 1000000)
816
+
// Field doesn't exist on this type, so ignore it
817
+
if err := cbg.ScanForLinks(cr, func(cid.Cid) {}); err != nil {
823
+
switch string(nameBuf[:nameLen]) {
824
+
// t.Body (string) (string)
828
+
sval, err := cbg.ReadStringWithMax(cr, 1000000)
833
+
t.Body = string(sval)
835
+
// t.LexiconTypeID (string) (string)
839
+
sval, err := cbg.ReadStringWithMax(cr, 1000000)
844
+
t.LexiconTypeID = string(sval)
846
+
// t.ReplyTo (string) (string)
850
+
b, err := cr.ReadByte()
854
+
if b != cbg.CborNull[0] {
855
+
if err := cr.UnreadByte(); err != nil {
859
+
sval, err := cbg.ReadStringWithMax(cr, 1000000)
864
+
t.ReplyTo = (*string)(&sval)
867
+
// t.Subject (string) (string)
871
+
sval, err := cbg.ReadStringWithMax(cr, 1000000)
876
+
t.Subject = string(sval)
878
+
// t.Mentions ([]string) (slice)
881
+
maj, extra, err = cr.ReadHeader()
887
+
return fmt.Errorf("t.Mentions: array too large (%d)", extra)
890
+
if maj != cbg.MajArray {
891
+
return fmt.Errorf("expected cbor array")
895
+
t.Mentions = make([]string, extra)
898
+
for i := 0; i < int(extra); i++ {
908
+
sval, err := cbg.ReadStringWithMax(cr, 1000000)
913
+
t.Mentions[i] = string(sval)
918
+
// t.CreatedAt (string) (string)
922
+
sval, err := cbg.ReadStringWithMax(cr, 1000000)
927
+
t.CreatedAt = string(sval)
929
+
// t.References ([]string) (slice)
932
+
maj, extra, err = cr.ReadHeader()
938
+
return fmt.Errorf("t.References: array too large (%d)", extra)
941
+
if maj != cbg.MajArray {
942
+
return fmt.Errorf("expected cbor array")
946
+
t.References = make([]string, extra)
949
+
for i := 0; i < int(extra); i++ {
959
+
sval, err := cbg.ReadStringWithMax(cr, 1000000)
964
+
t.References[i] = string(sval)
971
+
// Field doesn't exist on this type, so ignore it
972
+
if err := cbg.ScanForLinks(r, func(cid.Cid) {}); err != nil {
func (t *FeedReaction) MarshalCBOR(w io.Writer) error {
_, err := w.Write(cbg.CborNull)