1// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT.
2
3package bsky
4
5// schema: app.bsky.embed.recordWithMedia
6
7import (
8 "bytes"
9 "encoding/json"
10 "fmt"
11 "io"
12
13 "github.com/bluesky-social/indigo/lex/util"
14 cbg "github.com/whyrusleeping/cbor-gen"
15)
16
17func init() {
18 util.RegisterType("app.bsky.embed.recordWithMedia#main", &EmbedRecordWithMedia{})
19} // EmbedRecordWithMedia is a "main" in the app.bsky.embed.recordWithMedia schema.
20// RECORDTYPE: EmbedRecordWithMedia
21type EmbedRecordWithMedia struct {
22 LexiconTypeID string `json:"$type,const=app.bsky.embed.recordWithMedia" cborgen:"$type,const=app.bsky.embed.recordWithMedia"`
23 Media *EmbedRecordWithMedia_Media `json:"media" cborgen:"media"`
24 Record *EmbedRecord `json:"record" cborgen:"record"`
25}
26
27type EmbedRecordWithMedia_Media struct {
28 EmbedImages *EmbedImages
29 EmbedVideo *EmbedVideo
30 EmbedExternal *EmbedExternal
31}
32
33func (t *EmbedRecordWithMedia_Media) MarshalJSON() ([]byte, error) {
34 if t.EmbedImages != nil {
35 t.EmbedImages.LexiconTypeID = "app.bsky.embed.images"
36 return json.Marshal(t.EmbedImages)
37 }
38 if t.EmbedVideo != nil {
39 t.EmbedVideo.LexiconTypeID = "app.bsky.embed.video"
40 return json.Marshal(t.EmbedVideo)
41 }
42 if t.EmbedExternal != nil {
43 t.EmbedExternal.LexiconTypeID = "app.bsky.embed.external"
44 return json.Marshal(t.EmbedExternal)
45 }
46 return nil, fmt.Errorf("cannot marshal empty enum")
47}
48func (t *EmbedRecordWithMedia_Media) UnmarshalJSON(b []byte) error {
49 typ, err := util.TypeExtract(b)
50 if err != nil {
51 return err
52 }
53
54 switch typ {
55 case "app.bsky.embed.images":
56 t.EmbedImages = new(EmbedImages)
57 return json.Unmarshal(b, t.EmbedImages)
58 case "app.bsky.embed.video":
59 t.EmbedVideo = new(EmbedVideo)
60 return json.Unmarshal(b, t.EmbedVideo)
61 case "app.bsky.embed.external":
62 t.EmbedExternal = new(EmbedExternal)
63 return json.Unmarshal(b, t.EmbedExternal)
64
65 default:
66 return nil
67 }
68}
69
70func (t *EmbedRecordWithMedia_Media) MarshalCBOR(w io.Writer) error {
71
72 if t == nil {
73 _, err := w.Write(cbg.CborNull)
74 return err
75 }
76 if t.EmbedImages != nil {
77 return t.EmbedImages.MarshalCBOR(w)
78 }
79 if t.EmbedVideo != nil {
80 return t.EmbedVideo.MarshalCBOR(w)
81 }
82 if t.EmbedExternal != nil {
83 return t.EmbedExternal.MarshalCBOR(w)
84 }
85 return fmt.Errorf("cannot cbor marshal empty enum")
86}
87func (t *EmbedRecordWithMedia_Media) UnmarshalCBOR(r io.Reader) error {
88 typ, b, err := util.CborTypeExtractReader(r)
89 if err != nil {
90 return err
91 }
92
93 switch typ {
94 case "app.bsky.embed.images":
95 t.EmbedImages = new(EmbedImages)
96 return t.EmbedImages.UnmarshalCBOR(bytes.NewReader(b))
97 case "app.bsky.embed.video":
98 t.EmbedVideo = new(EmbedVideo)
99 return t.EmbedVideo.UnmarshalCBOR(bytes.NewReader(b))
100 case "app.bsky.embed.external":
101 t.EmbedExternal = new(EmbedExternal)
102 return t.EmbedExternal.UnmarshalCBOR(bytes.NewReader(b))
103
104 default:
105 return nil
106 }
107}
108
109// EmbedRecordWithMedia_View is a "view" in the app.bsky.embed.recordWithMedia schema.
110//
111// RECORDTYPE: EmbedRecordWithMedia_View
112type EmbedRecordWithMedia_View struct {
113 LexiconTypeID string `json:"$type,const=app.bsky.embed.recordWithMedia#view" cborgen:"$type,const=app.bsky.embed.recordWithMedia#view"`
114 Media *EmbedRecordWithMedia_View_Media `json:"media" cborgen:"media"`
115 Record *EmbedRecord_View `json:"record" cborgen:"record"`
116}
117
118type EmbedRecordWithMedia_View_Media struct {
119 EmbedImages_View *EmbedImages_View
120 EmbedVideo_View *EmbedVideo_View
121 EmbedExternal_View *EmbedExternal_View
122}
123
124func (t *EmbedRecordWithMedia_View_Media) MarshalJSON() ([]byte, error) {
125 if t.EmbedImages_View != nil {
126 t.EmbedImages_View.LexiconTypeID = "app.bsky.embed.images#view"
127 return json.Marshal(t.EmbedImages_View)
128 }
129 if t.EmbedVideo_View != nil {
130 t.EmbedVideo_View.LexiconTypeID = "app.bsky.embed.video#view"
131 return json.Marshal(t.EmbedVideo_View)
132 }
133 if t.EmbedExternal_View != nil {
134 t.EmbedExternal_View.LexiconTypeID = "app.bsky.embed.external#view"
135 return json.Marshal(t.EmbedExternal_View)
136 }
137 return nil, fmt.Errorf("cannot marshal empty enum")
138}
139func (t *EmbedRecordWithMedia_View_Media) UnmarshalJSON(b []byte) error {
140 typ, err := util.TypeExtract(b)
141 if err != nil {
142 return err
143 }
144
145 switch typ {
146 case "app.bsky.embed.images#view":
147 t.EmbedImages_View = new(EmbedImages_View)
148 return json.Unmarshal(b, t.EmbedImages_View)
149 case "app.bsky.embed.video#view":
150 t.EmbedVideo_View = new(EmbedVideo_View)
151 return json.Unmarshal(b, t.EmbedVideo_View)
152 case "app.bsky.embed.external#view":
153 t.EmbedExternal_View = new(EmbedExternal_View)
154 return json.Unmarshal(b, t.EmbedExternal_View)
155
156 default:
157 return nil
158 }
159}