// Code generated by glex; DO NOT EDIT. // Lexicon schema: app.bsky.embed.recordWithMedia 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.recordWithMedia#main", &EmbedRecordWithMedia{}) } type EmbedRecordWithMedia struct { LexiconTypeID string `json:"$type,omitempty"` Media EmbedRecordWithMedia_Media `json:"media"` Record EmbedRecord `json:"record"` } // RecordTypeID implements glex.Record. func (t *EmbedRecordWithMedia) RecordTypeID() string { return "app.bsky.embed.recordWithMedia" } // MarshalJSON stamps the $type field, like MarshalCBOR does. The value // receiver operates on a copy, so the record is never mutated and both // EmbedRecordWithMedia and *EmbedRecordWithMedia marshal with $type. func (t EmbedRecordWithMedia) MarshalJSON() ([]byte, error) { t.LexiconTypeID = "app.bsky.embed.recordWithMedia" type alias EmbedRecordWithMedia return json.Marshal((alias)(t)) } func (t *EmbedRecordWithMedia) 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.recordWithMedia" return glex.MarshalCBOR(w, &cp) } func (t *EmbedRecordWithMedia) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } type EmbedRecordWithMedia_Media struct { EmbedExternal *EmbedExternal EmbedGallery *EmbedGallery EmbedImages *EmbedImages EmbedVideo *EmbedVideo // 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 EmbedRecordWithMedia_Media and *EmbedRecordWithMedia_Media marshal correctly. func (t EmbedRecordWithMedia_Media) MarshalJSON() ([]byte, error) { if t.EmbedExternal != nil { cp := *t.EmbedExternal cp.LexiconTypeID = "app.bsky.embed.external" return json.Marshal(&cp) } if t.EmbedGallery != nil { cp := *t.EmbedGallery cp.LexiconTypeID = "app.bsky.embed.gallery" return json.Marshal(&cp) } if t.EmbedImages != nil { cp := *t.EmbedImages cp.LexiconTypeID = "app.bsky.embed.images" return json.Marshal(&cp) } if t.EmbedVideo != nil { cp := *t.EmbedVideo cp.LexiconTypeID = "app.bsky.embed.video" 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 EmbedRecordWithMedia_Media", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union EmbedRecordWithMedia_Media as JSON") } func (t *EmbedRecordWithMedia_Media) UnmarshalJSON(b []byte) error { typ, err := glex.TypeExtract(b) if err != nil { return err } switch typ { case "app.bsky.embed.external": t.EmbedExternal = new(EmbedExternal) return json.Unmarshal(b, t.EmbedExternal) case "app.bsky.embed.gallery": t.EmbedGallery = new(EmbedGallery) return json.Unmarshal(b, t.EmbedGallery) case "app.bsky.embed.images": t.EmbedImages = new(EmbedImages) return json.Unmarshal(b, t.EmbedImages) case "app.bsky.embed.video": t.EmbedVideo = new(EmbedVideo) return json.Unmarshal(b, t.EmbedVideo) 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 EmbedRecordWithMedia_Media) MarshalCBOR() ([]byte, error) { if t.EmbedExternal != nil { cp := *t.EmbedExternal cp.LexiconTypeID = "app.bsky.embed.external" return glex.MarshalCBORBytes(&cp) } if t.EmbedGallery != nil { cp := *t.EmbedGallery cp.LexiconTypeID = "app.bsky.embed.gallery" return glex.MarshalCBORBytes(&cp) } if t.EmbedImages != nil { cp := *t.EmbedImages cp.LexiconTypeID = "app.bsky.embed.images" return glex.MarshalCBORBytes(&cp) } if t.EmbedVideo != nil { cp := *t.EmbedVideo cp.LexiconTypeID = "app.bsky.embed.video" 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 EmbedRecordWithMedia_Media", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union EmbedRecordWithMedia_Media as CBOR") } func (t *EmbedRecordWithMedia_Media) UnmarshalCBOR(b []byte) error { typ, err := glex.CborTypeExtract(b) if err != nil { return err } switch typ { case "app.bsky.embed.external": t.EmbedExternal = new(EmbedExternal) return glex.UnmarshalCBORBytes(b, t.EmbedExternal) case "app.bsky.embed.gallery": t.EmbedGallery = new(EmbedGallery) return glex.UnmarshalCBORBytes(b, t.EmbedGallery) case "app.bsky.embed.images": t.EmbedImages = new(EmbedImages) return glex.UnmarshalCBORBytes(b, t.EmbedImages) case "app.bsky.embed.video": t.EmbedVideo = new(EmbedVideo) return glex.UnmarshalCBORBytes(b, t.EmbedVideo) default: t.Raw = &glex.RawRecord{Type: typ, Encoding: "cbor", Bytes: append([]byte(nil), b...)} return nil } } // EmbedRecordWithMedia_View is a "view" in the app.bsky.embed.recordWithMedia schema. type EmbedRecordWithMedia_View struct { LexiconTypeID string `json:"$type,omitempty"` Media EmbedRecordWithMedia_View_Media `json:"media"` Record EmbedRecord_View `json:"record"` } // RecordTypeID implements glex.Record. func (t *EmbedRecordWithMedia_View) RecordTypeID() string { return "app.bsky.embed.recordWithMedia#view" } func (t *EmbedRecordWithMedia_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.recordWithMedia#view" return glex.MarshalCBOR(w, &cp) } func (t *EmbedRecordWithMedia_View) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } type EmbedRecordWithMedia_View_Media struct { EmbedExternal_View *EmbedExternal_View EmbedGallery_View *EmbedGallery_View EmbedImages_View *EmbedImages_View EmbedVideo_View *EmbedVideo_View // 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 EmbedRecordWithMedia_View_Media and *EmbedRecordWithMedia_View_Media marshal correctly. func (t EmbedRecordWithMedia_View_Media) MarshalJSON() ([]byte, error) { if t.EmbedExternal_View != nil { cp := *t.EmbedExternal_View cp.LexiconTypeID = "app.bsky.embed.external#view" return json.Marshal(&cp) } if t.EmbedGallery_View != nil { cp := *t.EmbedGallery_View cp.LexiconTypeID = "app.bsky.embed.gallery#view" return json.Marshal(&cp) } if t.EmbedImages_View != nil { cp := *t.EmbedImages_View cp.LexiconTypeID = "app.bsky.embed.images#view" return json.Marshal(&cp) } if t.EmbedVideo_View != nil { cp := *t.EmbedVideo_View cp.LexiconTypeID = "app.bsky.embed.video#view" 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 EmbedRecordWithMedia_View_Media", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union EmbedRecordWithMedia_View_Media as JSON") } func (t *EmbedRecordWithMedia_View_Media) UnmarshalJSON(b []byte) error { typ, err := glex.TypeExtract(b) if err != nil { return err } switch typ { case "app.bsky.embed.external#view": t.EmbedExternal_View = new(EmbedExternal_View) return json.Unmarshal(b, t.EmbedExternal_View) case "app.bsky.embed.gallery#view": t.EmbedGallery_View = new(EmbedGallery_View) return json.Unmarshal(b, t.EmbedGallery_View) case "app.bsky.embed.images#view": t.EmbedImages_View = new(EmbedImages_View) return json.Unmarshal(b, t.EmbedImages_View) case "app.bsky.embed.video#view": t.EmbedVideo_View = new(EmbedVideo_View) return json.Unmarshal(b, t.EmbedVideo_View) 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 EmbedRecordWithMedia_View_Media) MarshalCBOR() ([]byte, error) { if t.EmbedExternal_View != nil { cp := *t.EmbedExternal_View cp.LexiconTypeID = "app.bsky.embed.external#view" return glex.MarshalCBORBytes(&cp) } if t.EmbedGallery_View != nil { cp := *t.EmbedGallery_View cp.LexiconTypeID = "app.bsky.embed.gallery#view" return glex.MarshalCBORBytes(&cp) } if t.EmbedImages_View != nil { cp := *t.EmbedImages_View cp.LexiconTypeID = "app.bsky.embed.images#view" return glex.MarshalCBORBytes(&cp) } if t.EmbedVideo_View != nil { cp := *t.EmbedVideo_View cp.LexiconTypeID = "app.bsky.embed.video#view" 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 EmbedRecordWithMedia_View_Media", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union EmbedRecordWithMedia_View_Media as CBOR") } func (t *EmbedRecordWithMedia_View_Media) UnmarshalCBOR(b []byte) error { typ, err := glex.CborTypeExtract(b) if err != nil { return err } switch typ { case "app.bsky.embed.external#view": t.EmbedExternal_View = new(EmbedExternal_View) return glex.UnmarshalCBORBytes(b, t.EmbedExternal_View) case "app.bsky.embed.gallery#view": t.EmbedGallery_View = new(EmbedGallery_View) return glex.UnmarshalCBORBytes(b, t.EmbedGallery_View) case "app.bsky.embed.images#view": t.EmbedImages_View = new(EmbedImages_View) return glex.UnmarshalCBORBytes(b, t.EmbedImages_View) case "app.bsky.embed.video#view": t.EmbedVideo_View = new(EmbedVideo_View) return glex.UnmarshalCBORBytes(b, t.EmbedVideo_View) default: t.Raw = &glex.RawRecord{Type: typ, Encoding: "cbor", Bytes: append([]byte(nil), b...)} return nil } }