// Code generated by glex; DO NOT EDIT. // Lexicon schema: place.stream.live.getRecommendations package placestream import ( "context" "encoding/json" "fmt" "io" glex "github.com/streamplace/glex/runtime" cbg "github.com/whyrusleeping/cbor-gen" ) type LiveGetRecommendations_Output struct { LexiconTypeID string `json:"$type,omitempty"` // recommendations: Ordered list of recommendations Recommendations []LiveGetRecommendations_Output_Recommendations_Elem `json:"recommendations"` // userDID: The user DID this recommendation is for UserDID *string `json:"userDID,omitempty"` } // RecordTypeID implements glex.Record. func (t *LiveGetRecommendations_Output) RecordTypeID() string { return "place.stream.live.getRecommendations" } func (t *LiveGetRecommendations_Output) 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.live.getRecommendations" return glex.MarshalCBOR(w, &cp) } func (t *LiveGetRecommendations_Output) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } type LiveGetRecommendations_Output_Recommendations_Elem struct { LiveGetRecommendations_LivestreamRecommendation *LiveGetRecommendations_LivestreamRecommendation // 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 LiveGetRecommendations_Output_Recommendations_Elem and *LiveGetRecommendations_Output_Recommendations_Elem marshal correctly. func (t LiveGetRecommendations_Output_Recommendations_Elem) MarshalJSON() ([]byte, error) { if t.LiveGetRecommendations_LivestreamRecommendation != nil { cp := *t.LiveGetRecommendations_LivestreamRecommendation cp.LexiconTypeID = "place.stream.live.getRecommendations#livestreamRecommendation" 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 LiveGetRecommendations_Output_Recommendations_Elem", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union LiveGetRecommendations_Output_Recommendations_Elem as JSON") } func (t *LiveGetRecommendations_Output_Recommendations_Elem) UnmarshalJSON(b []byte) error { typ, err := glex.TypeExtract(b) if err != nil { return err } switch typ { case "place.stream.live.getRecommendations#livestreamRecommendation": t.LiveGetRecommendations_LivestreamRecommendation = new(LiveGetRecommendations_LivestreamRecommendation) return json.Unmarshal(b, t.LiveGetRecommendations_LivestreamRecommendation) 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 LiveGetRecommendations_Output_Recommendations_Elem) MarshalCBOR() ([]byte, error) { if t.LiveGetRecommendations_LivestreamRecommendation != nil { cp := *t.LiveGetRecommendations_LivestreamRecommendation cp.LexiconTypeID = "place.stream.live.getRecommendations#livestreamRecommendation" 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 LiveGetRecommendations_Output_Recommendations_Elem", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union LiveGetRecommendations_Output_Recommendations_Elem as CBOR") } func (t *LiveGetRecommendations_Output_Recommendations_Elem) UnmarshalCBOR(b []byte) error { typ, err := glex.CborTypeExtract(b) if err != nil { return err } switch typ { case "place.stream.live.getRecommendations#livestreamRecommendation": t.LiveGetRecommendations_LivestreamRecommendation = new(LiveGetRecommendations_LivestreamRecommendation) return glex.UnmarshalCBORBytes(b, t.LiveGetRecommendations_LivestreamRecommendation) default: t.Raw = &glex.RawRecord{Type: typ, Encoding: "cbor", Bytes: append([]byte(nil), b...)} return nil } } // LiveGetRecommendations calls the XRPC method "place.stream.live.getRecommendations". // // # Get the list of streamers recommended by a user // // userDID: The DID of the user whose recommendations to fetch func LiveGetRecommendations(ctx context.Context, c glex.LexClient, userDID string) (*LiveGetRecommendations_Output, error) { var out LiveGetRecommendations_Output params := map[string]interface{}{} params["userDID"] = userDID if err := c.LexDo(ctx, glex.Query, "", "place.stream.live.getRecommendations", params, nil, &out); err != nil { return nil, err } return &out, nil } // LiveGetRecommendations_LivestreamRecommendation is a "livestreamRecommendation" in the place.stream.live.getRecommendations schema. type LiveGetRecommendations_LivestreamRecommendation struct { LexiconTypeID string `json:"$type,omitempty"` // did: The DID of the recommended streamer Did string `json:"did"` // source: Source of the recommendation Source string `json:"source"` } // RecordTypeID implements glex.Record. func (t *LiveGetRecommendations_LivestreamRecommendation) RecordTypeID() string { return "place.stream.live.getRecommendations#livestreamRecommendation" } func (t *LiveGetRecommendations_LivestreamRecommendation) 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.live.getRecommendations#livestreamRecommendation" return glex.MarshalCBOR(w, &cp) } func (t *LiveGetRecommendations_LivestreamRecommendation) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) }