// Code generated by glex; DO NOT EDIT. // Lexicon schema: app.bsky.embed.record package appbsky import ( "encoding/json" "fmt" "io" glex "github.com/streamplace/glex/runtime" cbg "github.com/whyrusleeping/cbor-gen" comatproto "stream.place/streamplace/pkg/comatproto" ) func init() { glex.RegisterType("app.bsky.embed.record#main", &EmbedRecord{}) } type EmbedRecord struct { LexiconTypeID string `json:"$type,omitempty"` Record comatproto.RepoStrongRef `json:"record"` } // RecordTypeID implements glex.Record. func (t *EmbedRecord) RecordTypeID() string { return "app.bsky.embed.record" } // MarshalJSON stamps the $type field, like MarshalCBOR does. The value // receiver operates on a copy, so the record is never mutated and both // EmbedRecord and *EmbedRecord marshal with $type. func (t EmbedRecord) MarshalJSON() ([]byte, error) { t.LexiconTypeID = "app.bsky.embed.record" type alias EmbedRecord return json.Marshal((alias)(t)) } func (t *EmbedRecord) 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.record" return glex.MarshalCBOR(w, &cp) } func (t *EmbedRecord) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } // EmbedRecord_View is a "view" in the app.bsky.embed.record schema. type EmbedRecord_View struct { LexiconTypeID string `json:"$type,omitempty"` Record EmbedRecord_View_Record `json:"record"` } // RecordTypeID implements glex.Record. func (t *EmbedRecord_View) RecordTypeID() string { return "app.bsky.embed.record#view" } func (t *EmbedRecord_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.record#view" return glex.MarshalCBOR(w, &cp) } func (t *EmbedRecord_View) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } type EmbedRecord_View_Record struct { EmbedRecord_ViewBlocked *EmbedRecord_ViewBlocked EmbedRecord_ViewDetached *EmbedRecord_ViewDetached EmbedRecord_ViewNotFound *EmbedRecord_ViewNotFound EmbedRecord_ViewRecord *EmbedRecord_ViewRecord FeedDefs_GeneratorView *FeedDefs_GeneratorView GraphDefs_ListView *GraphDefs_ListView GraphDefs_StarterPackViewBasic *GraphDefs_StarterPackViewBasic LabelerDefs_LabelerView *LabelerDefs_LabelerView // 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 EmbedRecord_View_Record and *EmbedRecord_View_Record marshal correctly. func (t EmbedRecord_View_Record) MarshalJSON() ([]byte, error) { if t.EmbedRecord_ViewBlocked != nil { cp := *t.EmbedRecord_ViewBlocked cp.LexiconTypeID = "app.bsky.embed.record#viewBlocked" return json.Marshal(&cp) } if t.EmbedRecord_ViewDetached != nil { cp := *t.EmbedRecord_ViewDetached cp.LexiconTypeID = "app.bsky.embed.record#viewDetached" return json.Marshal(&cp) } if t.EmbedRecord_ViewNotFound != nil { cp := *t.EmbedRecord_ViewNotFound cp.LexiconTypeID = "app.bsky.embed.record#viewNotFound" return json.Marshal(&cp) } if t.EmbedRecord_ViewRecord != nil { cp := *t.EmbedRecord_ViewRecord cp.LexiconTypeID = "app.bsky.embed.record#viewRecord" return json.Marshal(&cp) } if t.FeedDefs_GeneratorView != nil { cp := *t.FeedDefs_GeneratorView cp.LexiconTypeID = "app.bsky.feed.defs#generatorView" return json.Marshal(&cp) } if t.GraphDefs_ListView != nil { cp := *t.GraphDefs_ListView cp.LexiconTypeID = "app.bsky.graph.defs#listView" return json.Marshal(&cp) } if t.GraphDefs_StarterPackViewBasic != nil { cp := *t.GraphDefs_StarterPackViewBasic cp.LexiconTypeID = "app.bsky.graph.defs#starterPackViewBasic" return json.Marshal(&cp) } if t.LabelerDefs_LabelerView != nil { cp := *t.LabelerDefs_LabelerView cp.LexiconTypeID = "app.bsky.labeler.defs#labelerView" 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 EmbedRecord_View_Record", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union EmbedRecord_View_Record as JSON") } func (t *EmbedRecord_View_Record) UnmarshalJSON(b []byte) error { typ, err := glex.TypeExtract(b) if err != nil { return err } switch typ { case "app.bsky.embed.record#viewBlocked": t.EmbedRecord_ViewBlocked = new(EmbedRecord_ViewBlocked) return json.Unmarshal(b, t.EmbedRecord_ViewBlocked) case "app.bsky.embed.record#viewDetached": t.EmbedRecord_ViewDetached = new(EmbedRecord_ViewDetached) return json.Unmarshal(b, t.EmbedRecord_ViewDetached) case "app.bsky.embed.record#viewNotFound": t.EmbedRecord_ViewNotFound = new(EmbedRecord_ViewNotFound) return json.Unmarshal(b, t.EmbedRecord_ViewNotFound) case "app.bsky.embed.record#viewRecord": t.EmbedRecord_ViewRecord = new(EmbedRecord_ViewRecord) return json.Unmarshal(b, t.EmbedRecord_ViewRecord) case "app.bsky.feed.defs#generatorView": t.FeedDefs_GeneratorView = new(FeedDefs_GeneratorView) return json.Unmarshal(b, t.FeedDefs_GeneratorView) case "app.bsky.graph.defs#listView": t.GraphDefs_ListView = new(GraphDefs_ListView) return json.Unmarshal(b, t.GraphDefs_ListView) case "app.bsky.graph.defs#starterPackViewBasic": t.GraphDefs_StarterPackViewBasic = new(GraphDefs_StarterPackViewBasic) return json.Unmarshal(b, t.GraphDefs_StarterPackViewBasic) case "app.bsky.labeler.defs#labelerView": t.LabelerDefs_LabelerView = new(LabelerDefs_LabelerView) return json.Unmarshal(b, t.LabelerDefs_LabelerView) 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 EmbedRecord_View_Record) MarshalCBOR() ([]byte, error) { if t.EmbedRecord_ViewBlocked != nil { cp := *t.EmbedRecord_ViewBlocked cp.LexiconTypeID = "app.bsky.embed.record#viewBlocked" return glex.MarshalCBORBytes(&cp) } if t.EmbedRecord_ViewDetached != nil { cp := *t.EmbedRecord_ViewDetached cp.LexiconTypeID = "app.bsky.embed.record#viewDetached" return glex.MarshalCBORBytes(&cp) } if t.EmbedRecord_ViewNotFound != nil { cp := *t.EmbedRecord_ViewNotFound cp.LexiconTypeID = "app.bsky.embed.record#viewNotFound" return glex.MarshalCBORBytes(&cp) } if t.EmbedRecord_ViewRecord != nil { cp := *t.EmbedRecord_ViewRecord cp.LexiconTypeID = "app.bsky.embed.record#viewRecord" return glex.MarshalCBORBytes(&cp) } if t.FeedDefs_GeneratorView != nil { cp := *t.FeedDefs_GeneratorView cp.LexiconTypeID = "app.bsky.feed.defs#generatorView" return glex.MarshalCBORBytes(&cp) } if t.GraphDefs_ListView != nil { cp := *t.GraphDefs_ListView cp.LexiconTypeID = "app.bsky.graph.defs#listView" return glex.MarshalCBORBytes(&cp) } if t.GraphDefs_StarterPackViewBasic != nil { cp := *t.GraphDefs_StarterPackViewBasic cp.LexiconTypeID = "app.bsky.graph.defs#starterPackViewBasic" return glex.MarshalCBORBytes(&cp) } if t.LabelerDefs_LabelerView != nil { cp := *t.LabelerDefs_LabelerView cp.LexiconTypeID = "app.bsky.labeler.defs#labelerView" 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 EmbedRecord_View_Record", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union EmbedRecord_View_Record as CBOR") } func (t *EmbedRecord_View_Record) UnmarshalCBOR(b []byte) error { typ, err := glex.CborTypeExtract(b) if err != nil { return err } switch typ { case "app.bsky.embed.record#viewBlocked": t.EmbedRecord_ViewBlocked = new(EmbedRecord_ViewBlocked) return glex.UnmarshalCBORBytes(b, t.EmbedRecord_ViewBlocked) case "app.bsky.embed.record#viewDetached": t.EmbedRecord_ViewDetached = new(EmbedRecord_ViewDetached) return glex.UnmarshalCBORBytes(b, t.EmbedRecord_ViewDetached) case "app.bsky.embed.record#viewNotFound": t.EmbedRecord_ViewNotFound = new(EmbedRecord_ViewNotFound) return glex.UnmarshalCBORBytes(b, t.EmbedRecord_ViewNotFound) case "app.bsky.embed.record#viewRecord": t.EmbedRecord_ViewRecord = new(EmbedRecord_ViewRecord) return glex.UnmarshalCBORBytes(b, t.EmbedRecord_ViewRecord) case "app.bsky.feed.defs#generatorView": t.FeedDefs_GeneratorView = new(FeedDefs_GeneratorView) return glex.UnmarshalCBORBytes(b, t.FeedDefs_GeneratorView) case "app.bsky.graph.defs#listView": t.GraphDefs_ListView = new(GraphDefs_ListView) return glex.UnmarshalCBORBytes(b, t.GraphDefs_ListView) case "app.bsky.graph.defs#starterPackViewBasic": t.GraphDefs_StarterPackViewBasic = new(GraphDefs_StarterPackViewBasic) return glex.UnmarshalCBORBytes(b, t.GraphDefs_StarterPackViewBasic) case "app.bsky.labeler.defs#labelerView": t.LabelerDefs_LabelerView = new(LabelerDefs_LabelerView) return glex.UnmarshalCBORBytes(b, t.LabelerDefs_LabelerView) default: t.Raw = &glex.RawRecord{Type: typ, Encoding: "cbor", Bytes: append([]byte(nil), b...)} return nil } } // EmbedRecord_ViewBlocked is a "viewBlocked" in the app.bsky.embed.record schema. type EmbedRecord_ViewBlocked struct { LexiconTypeID string `json:"$type,omitempty"` Author FeedDefs_BlockedAuthor `json:"author"` Blocked bool `json:"blocked"` Uri string `json:"uri"` } // RecordTypeID implements glex.Record. func (t *EmbedRecord_ViewBlocked) RecordTypeID() string { return "app.bsky.embed.record#viewBlocked" } func (t *EmbedRecord_ViewBlocked) 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.record#viewBlocked" return glex.MarshalCBOR(w, &cp) } func (t *EmbedRecord_ViewBlocked) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } // EmbedRecord_ViewDetached is a "viewDetached" in the app.bsky.embed.record schema. type EmbedRecord_ViewDetached struct { LexiconTypeID string `json:"$type,omitempty"` Detached bool `json:"detached"` Uri string `json:"uri"` } // RecordTypeID implements glex.Record. func (t *EmbedRecord_ViewDetached) RecordTypeID() string { return "app.bsky.embed.record#viewDetached" } func (t *EmbedRecord_ViewDetached) 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.record#viewDetached" return glex.MarshalCBOR(w, &cp) } func (t *EmbedRecord_ViewDetached) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } // EmbedRecord_ViewNotFound is a "viewNotFound" in the app.bsky.embed.record schema. type EmbedRecord_ViewNotFound struct { LexiconTypeID string `json:"$type,omitempty"` NotFound bool `json:"notFound"` Uri string `json:"uri"` } // RecordTypeID implements glex.Record. func (t *EmbedRecord_ViewNotFound) RecordTypeID() string { return "app.bsky.embed.record#viewNotFound" } func (t *EmbedRecord_ViewNotFound) 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.record#viewNotFound" return glex.MarshalCBOR(w, &cp) } func (t *EmbedRecord_ViewNotFound) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } // EmbedRecord_ViewRecord is a "viewRecord" in the app.bsky.embed.record schema. type EmbedRecord_ViewRecord struct { LexiconTypeID string `json:"$type,omitempty"` Author ActorDefs_ProfileViewBasic `json:"author"` Cid string `json:"cid"` Embeds []EmbedRecord_ViewRecord_Embeds_Elem `json:"embeds,omitempty"` IndexedAt string `json:"indexedAt"` Labels []comatproto.LabelDefs_Label `json:"labels,omitempty"` LikeCount *int64 `json:"likeCount,omitempty"` QuoteCount *int64 `json:"quoteCount,omitempty"` ReplyCount *int64 `json:"replyCount,omitempty"` RepostCount *int64 `json:"repostCount,omitempty"` Uri string `json:"uri"` // value: The record data itself. Value *glex.LexiconTypeDecoder `json:"value"` } // RecordTypeID implements glex.Record. func (t *EmbedRecord_ViewRecord) RecordTypeID() string { return "app.bsky.embed.record#viewRecord" } func (t *EmbedRecord_ViewRecord) 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.record#viewRecord" return glex.MarshalCBOR(w, &cp) } func (t *EmbedRecord_ViewRecord) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } type EmbedRecord_ViewRecord_Embeds_Elem struct { EmbedExternal_View *EmbedExternal_View EmbedGallery_View *EmbedGallery_View EmbedImages_View *EmbedImages_View EmbedRecordWithMedia_View *EmbedRecordWithMedia_View EmbedRecord_View *EmbedRecord_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 EmbedRecord_ViewRecord_Embeds_Elem and *EmbedRecord_ViewRecord_Embeds_Elem marshal correctly. func (t EmbedRecord_ViewRecord_Embeds_Elem) 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.EmbedRecordWithMedia_View != nil { cp := *t.EmbedRecordWithMedia_View cp.LexiconTypeID = "app.bsky.embed.recordWithMedia#view" return json.Marshal(&cp) } if t.EmbedRecord_View != nil { cp := *t.EmbedRecord_View cp.LexiconTypeID = "app.bsky.embed.record#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 EmbedRecord_ViewRecord_Embeds_Elem", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union EmbedRecord_ViewRecord_Embeds_Elem as JSON") } func (t *EmbedRecord_ViewRecord_Embeds_Elem) 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.recordWithMedia#view": t.EmbedRecordWithMedia_View = new(EmbedRecordWithMedia_View) return json.Unmarshal(b, t.EmbedRecordWithMedia_View) case "app.bsky.embed.record#view": t.EmbedRecord_View = new(EmbedRecord_View) return json.Unmarshal(b, t.EmbedRecord_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 EmbedRecord_ViewRecord_Embeds_Elem) 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.EmbedRecordWithMedia_View != nil { cp := *t.EmbedRecordWithMedia_View cp.LexiconTypeID = "app.bsky.embed.recordWithMedia#view" return glex.MarshalCBORBytes(&cp) } if t.EmbedRecord_View != nil { cp := *t.EmbedRecord_View cp.LexiconTypeID = "app.bsky.embed.record#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 EmbedRecord_ViewRecord_Embeds_Elem", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union EmbedRecord_ViewRecord_Embeds_Elem as CBOR") } func (t *EmbedRecord_ViewRecord_Embeds_Elem) 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.recordWithMedia#view": t.EmbedRecordWithMedia_View = new(EmbedRecordWithMedia_View) return glex.UnmarshalCBORBytes(b, t.EmbedRecordWithMedia_View) case "app.bsky.embed.record#view": t.EmbedRecord_View = new(EmbedRecord_View) return glex.UnmarshalCBORBytes(b, t.EmbedRecord_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 } }