Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
4.9 kB · 147 lines
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148// Code generated by glex; DO NOT EDIT.
// Lexicon schema: place.stream.richtext.facet
package placestream
import ( "encoding/json" "fmt" "io"
glex "github.com/streamplace/glex/runtime" cbg "github.com/whyrusleeping/cbor-gen" appbsky "stream.place/streamplace/pkg/appbsky")
func init() { glex.RegisterType("place.stream.richtext.facet#main", &RichtextFacet{})}
// Annotation of a sub-string within rich text in a livestream chat message.type RichtextFacet struct { LexiconTypeID string `json:"$type,omitempty"` Features []RichtextFacet_Features_Elem `json:"features"` Index appbsky.RichtextFacet_ByteSlice `json:"index"`}
// RecordTypeID implements glex.Record.func (t *RichtextFacet) RecordTypeID() string { return "place.stream.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 = "place.stream.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 = "place.stream.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 *appbsky.RichtextFacet_Link RichtextFacet_Mention *appbsky.RichtextFacet_Mention // 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.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(appbsky.RichtextFacet_Link) return json.Unmarshal(b, t.RichtextFacet_Link) case "app.bsky.richtext.facet#mention": t.RichtextFacet_Mention = new(appbsky.RichtextFacet_Mention) return json.Unmarshal(b, t.RichtextFacet_Mention) 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.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(appbsky.RichtextFacet_Link) return glex.UnmarshalCBORBytes(b, t.RichtextFacet_Link) case "app.bsky.richtext.facet#mention": t.RichtextFacet_Mention = new(appbsky.RichtextFacet_Mention) return glex.UnmarshalCBORBytes(b, t.RichtextFacet_Mention) default: t.Raw = &glex.RawRecord{Type: typ, Encoding: "cbor", Bytes: append([]byte(nil), b...)} return nil }}