// Code generated by glex; DO NOT EDIT. // Lexicon schema: app.bsky.richtext.facet 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.richtext.facet#main", &RichtextFacet{}) } // Annotation of a sub-string within rich text. type RichtextFacet struct { LexiconTypeID string `json:"$type,omitempty"` Features []RichtextFacet_Features_Elem `json:"features"` Index RichtextFacet_ByteSlice `json:"index"` } // RecordTypeID implements glex.Record. func (t *RichtextFacet) RecordTypeID() string { return "app.bsky.richtext.facet" } // MarshalJSON stamps the $type field, like MarshalCBOR does. The value // receiver operates on a copy, so the record is never mutated and both // RichtextFacet and *RichtextFacet marshal with $type. func (t RichtextFacet) MarshalJSON() ([]byte, error) { t.LexiconTypeID = "app.bsky.richtext.facet" type alias RichtextFacet return json.Marshal((alias)(t)) } func (t *RichtextFacet) 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.richtext.facet" return glex.MarshalCBOR(w, &cp) } func (t *RichtextFacet) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } type RichtextFacet_Features_Elem struct { RichtextFacet_Link *RichtextFacet_Link RichtextFacet_Mention *RichtextFacet_Mention RichtextFacet_Tag *RichtextFacet_Tag // 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 RichtextFacet_Features_Elem and *RichtextFacet_Features_Elem marshal correctly. func (t RichtextFacet_Features_Elem) MarshalJSON() ([]byte, error) { if t.RichtextFacet_Link != nil { cp := *t.RichtextFacet_Link cp.LexiconTypeID = "app.bsky.richtext.facet#link" return json.Marshal(&cp) } if t.RichtextFacet_Mention != nil { cp := *t.RichtextFacet_Mention cp.LexiconTypeID = "app.bsky.richtext.facet#mention" return json.Marshal(&cp) } if t.RichtextFacet_Tag != nil { cp := *t.RichtextFacet_Tag cp.LexiconTypeID = "app.bsky.richtext.facet#tag" 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 RichtextFacet_Features_Elem", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union RichtextFacet_Features_Elem as JSON") } func (t *RichtextFacet_Features_Elem) UnmarshalJSON(b []byte) error { typ, err := glex.TypeExtract(b) if err != nil { return err } switch typ { case "app.bsky.richtext.facet#link": t.RichtextFacet_Link = new(RichtextFacet_Link) return json.Unmarshal(b, t.RichtextFacet_Link) case "app.bsky.richtext.facet#mention": t.RichtextFacet_Mention = new(RichtextFacet_Mention) return json.Unmarshal(b, t.RichtextFacet_Mention) case "app.bsky.richtext.facet#tag": t.RichtextFacet_Tag = new(RichtextFacet_Tag) return json.Unmarshal(b, t.RichtextFacet_Tag) 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 RichtextFacet_Features_Elem) MarshalCBOR() ([]byte, error) { if t.RichtextFacet_Link != nil { cp := *t.RichtextFacet_Link cp.LexiconTypeID = "app.bsky.richtext.facet#link" return glex.MarshalCBORBytes(&cp) } if t.RichtextFacet_Mention != nil { cp := *t.RichtextFacet_Mention cp.LexiconTypeID = "app.bsky.richtext.facet#mention" return glex.MarshalCBORBytes(&cp) } if t.RichtextFacet_Tag != nil { cp := *t.RichtextFacet_Tag cp.LexiconTypeID = "app.bsky.richtext.facet#tag" 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 RichtextFacet_Features_Elem", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union RichtextFacet_Features_Elem as CBOR") } func (t *RichtextFacet_Features_Elem) UnmarshalCBOR(b []byte) error { typ, err := glex.CborTypeExtract(b) if err != nil { return err } switch typ { case "app.bsky.richtext.facet#link": t.RichtextFacet_Link = new(RichtextFacet_Link) return glex.UnmarshalCBORBytes(b, t.RichtextFacet_Link) case "app.bsky.richtext.facet#mention": t.RichtextFacet_Mention = new(RichtextFacet_Mention) return glex.UnmarshalCBORBytes(b, t.RichtextFacet_Mention) case "app.bsky.richtext.facet#tag": t.RichtextFacet_Tag = new(RichtextFacet_Tag) return glex.UnmarshalCBORBytes(b, t.RichtextFacet_Tag) default: t.Raw = &glex.RawRecord{Type: typ, Encoding: "cbor", Bytes: append([]byte(nil), b...)} return nil } } // RichtextFacet_ByteSlice is a "byteSlice" in the app.bsky.richtext.facet schema. // // 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. type RichtextFacet_ByteSlice struct { LexiconTypeID string `json:"$type,omitempty"` ByteEnd int64 `json:"byteEnd"` ByteStart int64 `json:"byteStart"` } // RecordTypeID implements glex.Record. func (t *RichtextFacet_ByteSlice) RecordTypeID() string { return "app.bsky.richtext.facet#byteSlice" } func (t *RichtextFacet_ByteSlice) 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.richtext.facet#byteSlice" return glex.MarshalCBOR(w, &cp) } func (t *RichtextFacet_ByteSlice) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } // RichtextFacet_Link is a "link" in the app.bsky.richtext.facet schema. // // Facet feature for a URL. The text URL may have been simplified or truncated, but the facet reference should be a complete URL. type RichtextFacet_Link struct { LexiconTypeID string `json:"$type,omitempty"` Uri string `json:"uri"` } // RecordTypeID implements glex.Record. func (t *RichtextFacet_Link) RecordTypeID() string { return "app.bsky.richtext.facet#link" } func (t *RichtextFacet_Link) 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.richtext.facet#link" return glex.MarshalCBOR(w, &cp) } func (t *RichtextFacet_Link) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } // RichtextFacet_Mention is a "mention" in the app.bsky.richtext.facet schema. // // Facet feature for mention of another account. The text is usually a handle, including a '@' prefix, but the facet reference is a DID. type RichtextFacet_Mention struct { LexiconTypeID string `json:"$type,omitempty"` Did string `json:"did"` } // RecordTypeID implements glex.Record. func (t *RichtextFacet_Mention) RecordTypeID() string { return "app.bsky.richtext.facet#mention" } func (t *RichtextFacet_Mention) 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.richtext.facet#mention" return glex.MarshalCBOR(w, &cp) } func (t *RichtextFacet_Mention) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } // RichtextFacet_Tag is a "tag" in the app.bsky.richtext.facet schema. // // 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'). type RichtextFacet_Tag struct { LexiconTypeID string `json:"$type,omitempty"` Tag string `json:"tag"` } // RecordTypeID implements glex.Record. func (t *RichtextFacet_Tag) RecordTypeID() string { return "app.bsky.richtext.facet#tag" } func (t *RichtextFacet_Tag) 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.richtext.facet#tag" return glex.MarshalCBOR(w, &cp) } func (t *RichtextFacet_Tag) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) }