From 2d41dab3d9b77738cbbd22c76344a10db7148293 Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Fri, 31 Mar 2023 12:39:25 -0700 Subject: [PATCH] cborgen --- api/atproto/cbor_gen.go | 53 +++++++----- api/bsky/cbor_gen.go | 180 ++++++++++++++++++++++++---------------- 2 files changed, 140 insertions(+), 93 deletions(-) diff --git a/api/atproto/cbor_gen.go b/api/atproto/cbor_gen.go index e3437d924..6e73365f3 100644 --- a/api/atproto/cbor_gen.go +++ b/api/atproto/cbor_gen.go @@ -96,10 +96,14 @@ func (t *RepoStrongRef) MarshalCBOR(w io.Writer) error { return err } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("com.atproto.repo.strongRef"))); err != nil { + if len(t.LexiconTypeID) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.LexiconTypeID was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LexiconTypeID))); err != nil { return err } - if _, err := io.WriteString(w, string("com.atproto.repo.strongRef")); err != nil { + if _, err := io.WriteString(w, string(t.LexiconTypeID)); err != nil { return err } } @@ -957,6 +961,10 @@ func (t *SyncSubscribeRepos_Info) MarshalCBOR(w io.Writer) error { fieldCount-- } + if t.Message == nil { + fieldCount-- + } + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { return err } @@ -1011,32 +1019,35 @@ func (t *SyncSubscribeRepos_Info) MarshalCBOR(w io.Writer) error { } // t.Message (string) (string) - if len("message") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"message\" was too long") - } - - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("message"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("message")); err != nil { - return err - } + if t.Message != nil { - if t.Message == nil { - if _, err := cw.Write(cbg.CborNull); err != nil { - return err - } - } else { - if len(*t.Message) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Message was too long") + if len("message") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"message\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Message))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("message"))); err != nil { return err } - if _, err := io.WriteString(w, string(*t.Message)); err != nil { + if _, err := io.WriteString(w, string("message")); err != nil { return err } + + if t.Message == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.Message) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Message was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Message))); err != nil { + return err + } + if _, err := io.WriteString(w, string(*t.Message)); err != nil { + return err + } + } } return nil } diff --git a/api/bsky/cbor_gen.go b/api/bsky/cbor_gen.go index aad720ffe..922d8ce0d 100644 --- a/api/bsky/cbor_gen.go +++ b/api/bsky/cbor_gen.go @@ -1417,6 +1417,10 @@ func (t *EmbedExternal_External) MarshalCBOR(w io.Writer) error { fieldCount-- } + if t.Thumb == nil { + fieldCount-- + } + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { return err } @@ -1471,19 +1475,22 @@ func (t *EmbedExternal_External) MarshalCBOR(w io.Writer) error { } // t.Thumb (util.LexBlob) (struct) - if len("thumb") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"thumb\" was too long") - } + if t.Thumb != nil { - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("thumb"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("thumb")); err != nil { - return err - } + if len("thumb") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"thumb\" was too long") + } - if err := t.Thumb.MarshalCBOR(cw); err != nil { - return err + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("thumb"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("thumb")); err != nil { + return err + } + + if err := t.Thumb.MarshalCBOR(cw); err != nil { + return err + } } // t.Title (string) (string) @@ -1984,8 +1991,25 @@ func (t *ActorProfile) MarshalCBOR(w io.Writer) error { } cw := cbg.NewCborWriter(w) + fieldCount := 5 + + if t.Avatar == nil { + fieldCount-- + } - if _, err := cw.Write([]byte{165}); err != nil { + if t.Banner == nil { + fieldCount-- + } + + if t.Description == nil { + fieldCount-- + } + + if t.DisplayName == nil { + fieldCount-- + } + + if _, err := cw.Write(cbg.CborEncodeMajorType(cbg.MajMap, uint64(fieldCount))); err != nil { return err } @@ -2009,93 +2033,105 @@ func (t *ActorProfile) MarshalCBOR(w io.Writer) error { } // t.Avatar (util.LexBlob) (struct) - if len("avatar") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"avatar\" was too long") - } + if t.Avatar != nil { - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("avatar"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("avatar")); err != nil { - return err - } + if len("avatar") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"avatar\" was too long") + } - if err := t.Avatar.MarshalCBOR(cw); err != nil { - return err + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("avatar"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("avatar")); err != nil { + return err + } + + if err := t.Avatar.MarshalCBOR(cw); err != nil { + return err + } } // t.Banner (util.LexBlob) (struct) - if len("banner") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"banner\" was too long") - } + if t.Banner != nil { - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("banner"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("banner")); err != nil { - return err - } + if len("banner") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"banner\" was too long") + } - if err := t.Banner.MarshalCBOR(cw); err != nil { - return err - } + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("banner"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("banner")); err != nil { + return err + } - // t.Description (string) (string) - if len("description") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"description\" was too long") + if err := t.Banner.MarshalCBOR(cw); err != nil { + return err + } } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("description"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("description")); err != nil { - return err - } + // t.Description (string) (string) + if t.Description != nil { - if t.Description == nil { - if _, err := cw.Write(cbg.CborNull); err != nil { - return err - } - } else { - if len(*t.Description) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Description was too long") + if len("description") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"description\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Description))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("description"))); err != nil { return err } - if _, err := io.WriteString(w, string(*t.Description)); err != nil { + if _, err := io.WriteString(w, string("description")); err != nil { return err } - } - // t.DisplayName (string) (string) - if len("displayName") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"displayName\" was too long") - } + if t.Description == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.Description) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Description was too long") + } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("displayName"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("displayName")); err != nil { - return err + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.Description))); err != nil { + return err + } + if _, err := io.WriteString(w, string(*t.Description)); err != nil { + return err + } + } } - if t.DisplayName == nil { - if _, err := cw.Write(cbg.CborNull); err != nil { - return err - } - } else { - if len(*t.DisplayName) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.DisplayName was too long") + // t.DisplayName (string) (string) + if t.DisplayName != nil { + + if len("displayName") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"displayName\" was too long") } - if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.DisplayName))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("displayName"))); err != nil { return err } - if _, err := io.WriteString(w, string(*t.DisplayName)); err != nil { + if _, err := io.WriteString(w, string("displayName")); err != nil { return err } + + if t.DisplayName == nil { + if _, err := cw.Write(cbg.CborNull); err != nil { + return err + } + } else { + if len(*t.DisplayName) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.DisplayName was too long") + } + + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(*t.DisplayName))); err != nil { + return err + } + if _, err := io.WriteString(w, string(*t.DisplayName)); err != nil { + return err + } + } } return nil }