1// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT.
2
3package bsky
4
5// schema: app.bsky.richtext.facet
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
17// RichtextFacet is a "main" in the app.bsky.richtext.facet schema.
18//
19// Annotation of a sub-string within rich text.
20type RichtextFacet struct {
21 Features []*RichtextFacet_Features_Elem `json:"features" cborgen:"features"`
22 Index *RichtextFacet_ByteSlice `json:"index" cborgen:"index"`
23}
24
25// RichtextFacet_ByteSlice is a "byteSlice" in the app.bsky.richtext.facet schema.
26//
27// Specifies the sub-string range a facet feature applies to. Start index is inclusive, end index is exclusive. Indices are zero-indexed, counting bytes of the UTF-8 encoded text. NOTE: some languages, like Javascript, use UTF-16 or Unicode codepoints for string slice indexing; in these languages, convert to byte arrays before working with facets.
28type RichtextFacet_ByteSlice struct {
29 ByteEnd int64 `json:"byteEnd" cborgen:"byteEnd"`
30 ByteStart int64 `json:"byteStart" cborgen:"byteStart"`
31}
32
33type RichtextFacet_Features_Elem struct {
34 RichtextFacet_Mention *RichtextFacet_Mention
35 RichtextFacet_Link *RichtextFacet_Link
36 RichtextFacet_Tag *RichtextFacet_Tag
37}
38
39func (t *RichtextFacet_Features_Elem) MarshalJSON() ([]byte, error) {
40 if t.RichtextFacet_Mention != nil {
41 t.RichtextFacet_Mention.LexiconTypeID = "app.bsky.richtext.facet#mention"
42 return json.Marshal(t.RichtextFacet_Mention)
43 }
44 if t.RichtextFacet_Link != nil {
45 t.RichtextFacet_Link.LexiconTypeID = "app.bsky.richtext.facet#link"
46 return json.Marshal(t.RichtextFacet_Link)
47 }
48 if t.RichtextFacet_Tag != nil {
49 t.RichtextFacet_Tag.LexiconTypeID = "app.bsky.richtext.facet#tag"
50 return json.Marshal(t.RichtextFacet_Tag)
51 }
52 return nil, fmt.Errorf("cannot marshal empty enum")
53}
54func (t *RichtextFacet_Features_Elem) UnmarshalJSON(b []byte) error {
55 typ, err := util.TypeExtract(b)
56 if err != nil {
57 return err
58 }
59
60 switch typ {
61 case "app.bsky.richtext.facet#mention":
62 t.RichtextFacet_Mention = new(RichtextFacet_Mention)
63 return json.Unmarshal(b, t.RichtextFacet_Mention)
64 case "app.bsky.richtext.facet#link":
65 t.RichtextFacet_Link = new(RichtextFacet_Link)
66 return json.Unmarshal(b, t.RichtextFacet_Link)
67 case "app.bsky.richtext.facet#tag":
68 t.RichtextFacet_Tag = new(RichtextFacet_Tag)
69 return json.Unmarshal(b, t.RichtextFacet_Tag)
70
71 default:
72 return nil
73 }
74}
75
76func (t *RichtextFacet_Features_Elem) MarshalCBOR(w io.Writer) error {
77
78 if t == nil {
79 _, err := w.Write(cbg.CborNull)
80 return err
81 }
82 if t.RichtextFacet_Mention != nil {
83 return t.RichtextFacet_Mention.MarshalCBOR(w)
84 }
85 if t.RichtextFacet_Link != nil {
86 return t.RichtextFacet_Link.MarshalCBOR(w)
87 }
88 if t.RichtextFacet_Tag != nil {
89 return t.RichtextFacet_Tag.MarshalCBOR(w)
90 }
91 return fmt.Errorf("cannot cbor marshal empty enum")
92}
93func (t *RichtextFacet_Features_Elem) UnmarshalCBOR(r io.Reader) error {
94 typ, b, err := util.CborTypeExtractReader(r)
95 if err != nil {
96 return err
97 }
98
99 switch typ {
100 case "app.bsky.richtext.facet#mention":
101 t.RichtextFacet_Mention = new(RichtextFacet_Mention)
102 return t.RichtextFacet_Mention.UnmarshalCBOR(bytes.NewReader(b))
103 case "app.bsky.richtext.facet#link":
104 t.RichtextFacet_Link = new(RichtextFacet_Link)
105 return t.RichtextFacet_Link.UnmarshalCBOR(bytes.NewReader(b))
106 case "app.bsky.richtext.facet#tag":
107 t.RichtextFacet_Tag = new(RichtextFacet_Tag)
108 return t.RichtextFacet_Tag.UnmarshalCBOR(bytes.NewReader(b))
109
110 default:
111 return nil
112 }
113}
114
115// RichtextFacet_Link is a "link" in the app.bsky.richtext.facet schema.
116//
117// Facet feature for a URL. The text URL may have been simplified or truncated, but the facet reference should be a complete URL.
118//
119// RECORDTYPE: RichtextFacet_Link
120type RichtextFacet_Link struct {
121 LexiconTypeID string `json:"$type,const=app.bsky.richtext.facet#link" cborgen:"$type,const=app.bsky.richtext.facet#link"`
122 Uri string `json:"uri" cborgen:"uri"`
123}
124
125// RichtextFacet_Mention is a "mention" in the app.bsky.richtext.facet schema.
126//
127// Facet feature for mention of another account. The text is usually a handle, including a '@' prefix, but the facet reference is a DID.
128//
129// RECORDTYPE: RichtextFacet_Mention
130type RichtextFacet_Mention struct {
131 LexiconTypeID string `json:"$type,const=app.bsky.richtext.facet#mention" cborgen:"$type,const=app.bsky.richtext.facet#mention"`
132 Did string `json:"did" cborgen:"did"`
133}
134
135// RichtextFacet_Tag is a "tag" in the app.bsky.richtext.facet schema.
136//
137// Facet feature for a hashtag. The text usually includes a '#' prefix, but the facet reference should not (except in the case of 'double hash tags').
138//
139// RECORDTYPE: RichtextFacet_Tag
140type RichtextFacet_Tag struct {
141 LexiconTypeID string `json:"$type,const=app.bsky.richtext.facet#tag" cborgen:"$type,const=app.bsky.richtext.facet#tag"`
142 Tag string `json:"tag" cborgen:"tag"`
143}