// Code generated by glex; DO NOT EDIT. // Lexicon schema: app.bsky.embed.gallery package appbsky import ( "encoding/json" "fmt" "io" glex "github.com/streamplace/glex/runtime" cbg "github.com/whyrusleeping/cbor-gen" ) func init() { glex.RegisterType("app.bsky.embed.gallery#main", &EmbedGallery{}) } type EmbedGallery struct { LexiconTypeID string `json:"$type,omitempty"` // items: The schema-level maxLength of 20 is a future-proof ceiling. Clients should currently enforce a soft limit of 10 items in authoring UIs. Items []EmbedGallery_Items_Elem `json:"items"` } // RecordTypeID implements glex.Record. func (t *EmbedGallery) RecordTypeID() string { return "app.bsky.embed.gallery" } // MarshalJSON stamps the $type field, like MarshalCBOR does. The value // receiver operates on a copy, so the record is never mutated and both // EmbedGallery and *EmbedGallery marshal with $type. func (t EmbedGallery) MarshalJSON() ([]byte, error) { t.LexiconTypeID = "app.bsky.embed.gallery" type alias EmbedGallery return json.Marshal((alias)(t)) } func (t *EmbedGallery) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } // stamp $type on a copy so marshal never mutates the record cp := *t cp.LexiconTypeID = "app.bsky.embed.gallery" return glex.MarshalCBOR(w, &cp) } func (t *EmbedGallery) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } // The media items in the gallery. Each item may be of a different type, but all types must be supported by the client. type EmbedGallery_Items_Elem struct { EmbedGallery_Image *EmbedGallery_Image // Raw preserves a variant whose $type is not in this union's generated // set, so unrecognized variants still round-trip losslessly through // decode/re-encode. Nil when a known variant is set. Raw *glex.RawRecord } // MarshalJSON emits the set variant, stamped with its $type, per the atproto // union wire format. The value receiver stamps a copy, so the variant is // never mutated and both EmbedGallery_Items_Elem and *EmbedGallery_Items_Elem marshal correctly. func (t EmbedGallery_Items_Elem) MarshalJSON() ([]byte, error) { if t.EmbedGallery_Image != nil { cp := *t.EmbedGallery_Image cp.LexiconTypeID = "app.bsky.embed.gallery#image" return json.Marshal(&cp) } if t.Raw != nil { if t.Raw.Encoding != "json" { return nil, fmt.Errorf("cannot marshal raw %s record as JSON in union EmbedGallery_Items_Elem", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union EmbedGallery_Items_Elem as JSON") } func (t *EmbedGallery_Items_Elem) UnmarshalJSON(b []byte) error { typ, err := glex.TypeExtract(b) if err != nil { return err } switch typ { case "app.bsky.embed.gallery#image": t.EmbedGallery_Image = new(EmbedGallery_Image) return json.Unmarshal(b, t.EmbedGallery_Image) default: t.Raw = &glex.RawRecord{Type: typ, Encoding: "json", Bytes: append([]byte(nil), b...)} return nil } } // MarshalCBOR implements drisl.Marshaler, emitting the set variant (stamped // with its $type) per the atproto union wire format. go-dasl invokes this // when the union appears inside another record, so nested unions serialize // correctly. func (t EmbedGallery_Items_Elem) MarshalCBOR() ([]byte, error) { if t.EmbedGallery_Image != nil { cp := *t.EmbedGallery_Image cp.LexiconTypeID = "app.bsky.embed.gallery#image" return glex.MarshalCBORBytes(&cp) } if t.Raw != nil { if t.Raw.Encoding != "cbor" { return nil, fmt.Errorf("cannot marshal raw %s record as CBOR in union EmbedGallery_Items_Elem", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union EmbedGallery_Items_Elem as CBOR") } func (t *EmbedGallery_Items_Elem) UnmarshalCBOR(b []byte) error { typ, err := glex.CborTypeExtract(b) if err != nil { return err } switch typ { case "app.bsky.embed.gallery#image": t.EmbedGallery_Image = new(EmbedGallery_Image) return glex.UnmarshalCBORBytes(b, t.EmbedGallery_Image) default: t.Raw = &glex.RawRecord{Type: typ, Encoding: "cbor", Bytes: append([]byte(nil), b...)} return nil } } // EmbedGallery_Image is a "image" in the app.bsky.embed.gallery schema. type EmbedGallery_Image struct { LexiconTypeID string `json:"$type,omitempty"` // alt: Alt text description of the image, for accessibility. Alt string `json:"alt"` AspectRatio EmbedDefs_AspectRatio `json:"aspectRatio"` Image glex.Blob `json:"image"` } // RecordTypeID implements glex.Record. func (t *EmbedGallery_Image) RecordTypeID() string { return "app.bsky.embed.gallery#image" } func (t *EmbedGallery_Image) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } // stamp $type on a copy so marshal never mutates the record cp := *t cp.LexiconTypeID = "app.bsky.embed.gallery#image" return glex.MarshalCBOR(w, &cp) } func (t *EmbedGallery_Image) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } // EmbedGallery_View is a "view" in the app.bsky.embed.gallery schema. type EmbedGallery_View struct { LexiconTypeID string `json:"$type,omitempty"` Items []EmbedGallery_View_Items_Elem `json:"items"` } // RecordTypeID implements glex.Record. func (t *EmbedGallery_View) RecordTypeID() string { return "app.bsky.embed.gallery#view" } func (t *EmbedGallery_View) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } // stamp $type on a copy so marshal never mutates the record cp := *t cp.LexiconTypeID = "app.bsky.embed.gallery#view" return glex.MarshalCBOR(w, &cp) } func (t *EmbedGallery_View) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } type EmbedGallery_View_Items_Elem struct { EmbedGallery_ViewImage *EmbedGallery_ViewImage // Raw preserves a variant whose $type is not in this union's generated // set, so unrecognized variants still round-trip losslessly through // decode/re-encode. Nil when a known variant is set. Raw *glex.RawRecord } // MarshalJSON emits the set variant, stamped with its $type, per the atproto // union wire format. The value receiver stamps a copy, so the variant is // never mutated and both EmbedGallery_View_Items_Elem and *EmbedGallery_View_Items_Elem marshal correctly. func (t EmbedGallery_View_Items_Elem) MarshalJSON() ([]byte, error) { if t.EmbedGallery_ViewImage != nil { cp := *t.EmbedGallery_ViewImage cp.LexiconTypeID = "app.bsky.embed.gallery#viewImage" return json.Marshal(&cp) } if t.Raw != nil { if t.Raw.Encoding != "json" { return nil, fmt.Errorf("cannot marshal raw %s record as JSON in union EmbedGallery_View_Items_Elem", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union EmbedGallery_View_Items_Elem as JSON") } func (t *EmbedGallery_View_Items_Elem) UnmarshalJSON(b []byte) error { typ, err := glex.TypeExtract(b) if err != nil { return err } switch typ { case "app.bsky.embed.gallery#viewImage": t.EmbedGallery_ViewImage = new(EmbedGallery_ViewImage) return json.Unmarshal(b, t.EmbedGallery_ViewImage) default: t.Raw = &glex.RawRecord{Type: typ, Encoding: "json", Bytes: append([]byte(nil), b...)} return nil } } // MarshalCBOR implements drisl.Marshaler, emitting the set variant (stamped // with its $type) per the atproto union wire format. go-dasl invokes this // when the union appears inside another record, so nested unions serialize // correctly. func (t EmbedGallery_View_Items_Elem) MarshalCBOR() ([]byte, error) { if t.EmbedGallery_ViewImage != nil { cp := *t.EmbedGallery_ViewImage cp.LexiconTypeID = "app.bsky.embed.gallery#viewImage" return glex.MarshalCBORBytes(&cp) } if t.Raw != nil { if t.Raw.Encoding != "cbor" { return nil, fmt.Errorf("cannot marshal raw %s record as CBOR in union EmbedGallery_View_Items_Elem", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union EmbedGallery_View_Items_Elem as CBOR") } func (t *EmbedGallery_View_Items_Elem) UnmarshalCBOR(b []byte) error { typ, err := glex.CborTypeExtract(b) if err != nil { return err } switch typ { case "app.bsky.embed.gallery#viewImage": t.EmbedGallery_ViewImage = new(EmbedGallery_ViewImage) return glex.UnmarshalCBORBytes(b, t.EmbedGallery_ViewImage) default: t.Raw = &glex.RawRecord{Type: typ, Encoding: "cbor", Bytes: append([]byte(nil), b...)} return nil } } // EmbedGallery_ViewImage is a "viewImage" in the app.bsky.embed.gallery schema. type EmbedGallery_ViewImage struct { LexiconTypeID string `json:"$type,omitempty"` // alt: Alt text description of the image, for accessibility. Alt string `json:"alt"` AspectRatio EmbedDefs_AspectRatio `json:"aspectRatio"` // fullsize: Fully-qualified URL where a large version of the image can be fetched. May or may not be the exact original blob. For example, CDN location provided by the App View. Fullsize string `json:"fullsize"` // thumbnail: Fully-qualified URL where a thumbnail of the image can be fetched. For example, CDN location provided by the App View. Thumbnail string `json:"thumbnail"` } // RecordTypeID implements glex.Record. func (t *EmbedGallery_ViewImage) RecordTypeID() string { return "app.bsky.embed.gallery#viewImage" } func (t *EmbedGallery_ViewImage) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } // stamp $type on a copy so marshal never mutates the record cp := *t cp.LexiconTypeID = "app.bsky.embed.gallery#viewImage" return glex.MarshalCBOR(w, &cp) } func (t *EmbedGallery_ViewImage) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) }