// Code generated by glex; DO NOT EDIT. // Lexicon schema: app.bsky.actor.status 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.actor.status", &ActorStatus{}) } // A declaration of a Bluesky account status. type ActorStatus struct { LexiconTypeID string `json:"$type,omitempty"` CreatedAt string `json:"createdAt"` // durationMinutes: The duration of the status in minutes. Applications can choose to impose minimum and maximum limits. DurationMinutes *int64 `json:"durationMinutes,omitempty"` // embed: An optional embed associated with the status. Embed *ActorStatus_Embed `json:"embed,omitempty"` // status: The status for the account. Status string `json:"status"` } // RecordTypeID implements glex.Record. func (t *ActorStatus) RecordTypeID() string { return "app.bsky.actor.status" } // MarshalJSON stamps the $type field, like MarshalCBOR does. The value // receiver operates on a copy, so the record is never mutated and both // ActorStatus and *ActorStatus marshal with $type. func (t ActorStatus) MarshalJSON() ([]byte, error) { t.LexiconTypeID = "app.bsky.actor.status" type alias ActorStatus return json.Marshal((alias)(t)) } func (t *ActorStatus) 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.actor.status" return glex.MarshalCBOR(w, &cp) } func (t *ActorStatus) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } // An optional embed associated with the status. type ActorStatus_Embed struct { EmbedExternal *EmbedExternal // 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 ActorStatus_Embed and *ActorStatus_Embed marshal correctly. func (t ActorStatus_Embed) MarshalJSON() ([]byte, error) { if t.EmbedExternal != nil { cp := *t.EmbedExternal cp.LexiconTypeID = "app.bsky.embed.external" 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 ActorStatus_Embed", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union ActorStatus_Embed as JSON") } func (t *ActorStatus_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) 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 ActorStatus_Embed) MarshalCBOR() ([]byte, error) { if t.EmbedExternal != nil { cp := *t.EmbedExternal cp.LexiconTypeID = "app.bsky.embed.external" 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 ActorStatus_Embed", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union ActorStatus_Embed as CBOR") } func (t *ActorStatus_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) default: t.Raw = &glex.RawRecord{Type: typ, Encoding: "cbor", Bytes: append([]byte(nil), b...)} return nil } }