// Code generated by glex; DO NOT EDIT. // Lexicon schema: app.bsky.feed.post 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.feed.post", &FeedPost{}) } // Record containing a Bluesky post. type FeedPost struct { LexiconTypeID string `json:"$type,omitempty"` // createdAt: Client-declared timestamp when this post was originally created. CreatedAt string `json:"createdAt"` Embed *FeedPost_Embed `json:"embed,omitempty"` // entities: DEPRECATED: replaced by app.bsky.richtext.facet. Entities []FeedPost_Entity `json:"entities,omitempty"` // facets: Annotations of text (mentions, URLs, hashtags, etc) Facets []RichtextFacet `json:"facets,omitempty"` // labels: Self-label values for this post. Effectively content warnings. Labels *FeedPost_Labels `json:"labels,omitempty"` // langs: Indicates human language of post primary text content. Langs []string `json:"langs,omitempty"` Reply *FeedPost_ReplyRef `json:"reply,omitempty"` // tags: Additional hashtags, in addition to any included in post text and facets. Tags []string `json:"tags,omitempty"` // text: The primary post content. May be an empty string, if there are embeds. Text string `json:"text"` } // RecordTypeID implements glex.Record. func (t *FeedPost) RecordTypeID() string { return "app.bsky.feed.post" } // MarshalJSON stamps the $type field, like MarshalCBOR does. The value // receiver operates on a copy, so the record is never mutated and both // FeedPost and *FeedPost marshal with $type. func (t FeedPost) MarshalJSON() ([]byte, error) { t.LexiconTypeID = "app.bsky.feed.post" type alias FeedPost return json.Marshal((alias)(t)) } func (t *FeedPost) 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.feed.post" return glex.MarshalCBOR(w, &cp) } func (t *FeedPost) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } type FeedPost_Embed struct { EmbedExternal *EmbedExternal EmbedGallery *EmbedGallery EmbedImages *EmbedImages EmbedRecord *EmbedRecord EmbedRecordWithMedia *EmbedRecordWithMedia 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 FeedPost_Embed and *FeedPost_Embed marshal correctly. func (t FeedPost_Embed) 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.EmbedRecord != nil { cp := *t.EmbedRecord cp.LexiconTypeID = "app.bsky.embed.record" return json.Marshal(&cp) } if t.EmbedRecordWithMedia != nil { cp := *t.EmbedRecordWithMedia cp.LexiconTypeID = "app.bsky.embed.recordWithMedia" 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 FeedPost_Embed", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union FeedPost_Embed as JSON") } func (t *FeedPost_Embed) 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.record": t.EmbedRecord = new(EmbedRecord) return json.Unmarshal(b, t.EmbedRecord) case "app.bsky.embed.recordWithMedia": t.EmbedRecordWithMedia = new(EmbedRecordWithMedia) return json.Unmarshal(b, t.EmbedRecordWithMedia) 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 FeedPost_Embed) 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.EmbedRecord != nil { cp := *t.EmbedRecord cp.LexiconTypeID = "app.bsky.embed.record" return glex.MarshalCBORBytes(&cp) } if t.EmbedRecordWithMedia != nil { cp := *t.EmbedRecordWithMedia cp.LexiconTypeID = "app.bsky.embed.recordWithMedia" 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 FeedPost_Embed", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union FeedPost_Embed as CBOR") } func (t *FeedPost_Embed) 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.record": t.EmbedRecord = new(EmbedRecord) return glex.UnmarshalCBORBytes(b, t.EmbedRecord) case "app.bsky.embed.recordWithMedia": t.EmbedRecordWithMedia = new(EmbedRecordWithMedia) return glex.UnmarshalCBORBytes(b, t.EmbedRecordWithMedia) 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 } } // Self-label values for this post. Effectively content warnings. type FeedPost_Labels struct { LabelDefs_SelfLabels *comatproto.LabelDefs_SelfLabels // 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 FeedPost_Labels and *FeedPost_Labels marshal correctly. func (t FeedPost_Labels) MarshalJSON() ([]byte, error) { if t.LabelDefs_SelfLabels != nil { cp := *t.LabelDefs_SelfLabels cp.LexiconTypeID = "com.atproto.label.defs#selfLabels" 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 FeedPost_Labels", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union FeedPost_Labels as JSON") } func (t *FeedPost_Labels) UnmarshalJSON(b []byte) error { typ, err := glex.TypeExtract(b) if err != nil { return err } switch typ { case "com.atproto.label.defs#selfLabels": t.LabelDefs_SelfLabels = new(comatproto.LabelDefs_SelfLabels) return json.Unmarshal(b, t.LabelDefs_SelfLabels) 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 FeedPost_Labels) MarshalCBOR() ([]byte, error) { if t.LabelDefs_SelfLabels != nil { cp := *t.LabelDefs_SelfLabels cp.LexiconTypeID = "com.atproto.label.defs#selfLabels" 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 FeedPost_Labels", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union FeedPost_Labels as CBOR") } func (t *FeedPost_Labels) UnmarshalCBOR(b []byte) error { typ, err := glex.CborTypeExtract(b) if err != nil { return err } switch typ { case "com.atproto.label.defs#selfLabels": t.LabelDefs_SelfLabels = new(comatproto.LabelDefs_SelfLabels) return glex.UnmarshalCBORBytes(b, t.LabelDefs_SelfLabels) default: t.Raw = &glex.RawRecord{Type: typ, Encoding: "cbor", Bytes: append([]byte(nil), b...)} return nil } } // FeedPost_Entity is a "entity" in the app.bsky.feed.post schema. // // Deprecated: use facets instead. type FeedPost_Entity struct { LexiconTypeID string `json:"$type,omitempty"` Index FeedPost_TextSlice `json:"index"` // type: Expected values are 'mention' and 'link'. Type string `json:"type"` Value string `json:"value"` } // RecordTypeID implements glex.Record. func (t *FeedPost_Entity) RecordTypeID() string { return "app.bsky.feed.post#entity" } func (t *FeedPost_Entity) 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.feed.post#entity" return glex.MarshalCBOR(w, &cp) } func (t *FeedPost_Entity) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } // FeedPost_ReplyRef is a "replyRef" in the app.bsky.feed.post schema. type FeedPost_ReplyRef struct { LexiconTypeID string `json:"$type,omitempty"` Parent comatproto.RepoStrongRef `json:"parent"` Root comatproto.RepoStrongRef `json:"root"` } // RecordTypeID implements glex.Record. func (t *FeedPost_ReplyRef) RecordTypeID() string { return "app.bsky.feed.post#replyRef" } func (t *FeedPost_ReplyRef) 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.feed.post#replyRef" return glex.MarshalCBOR(w, &cp) } func (t *FeedPost_ReplyRef) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } // FeedPost_TextSlice is a "textSlice" in the app.bsky.feed.post schema. // // Deprecated. Use app.bsky.richtext instead -- A text segment. Start is inclusive, end is exclusive. Indices are for utf16-encoded strings. type FeedPost_TextSlice struct { LexiconTypeID string `json:"$type,omitempty"` End int64 `json:"end"` Start int64 `json:"start"` } // RecordTypeID implements glex.Record. func (t *FeedPost_TextSlice) RecordTypeID() string { return "app.bsky.feed.post#textSlice" } func (t *FeedPost_TextSlice) 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.feed.post#textSlice" return glex.MarshalCBOR(w, &cp) } func (t *FeedPost_TextSlice) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) }