// Code generated by glex; DO NOT EDIT. // Lexicon schema: place.stream.media.track 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" comatproto "stream.place/streamplace/pkg/comatproto" ) func init() { glex.RegisterType("place.stream.media.track", &MediaTrack{}) } // A track for a video stream, either part of the source or a custom additional track. One of: video, audio, subtitles. type MediaTrack struct { LexiconTypeID string `json:"$type,omitempty"` Metadata *MediaTrack_Metadata `json:"metadata,omitempty"` // parentTrack: If this is a derived track like a transcode or a transcript, what was the parent track? ParentTrack *comatproto.RepoStrongRef `json:"parentTrack,omitempty"` Track MediaTrack_Track `json:"track"` // video: If this is a derived track like a transcode or a transcript, what was the source place.stream.video? Video *string `json:"video,omitempty"` } // RecordTypeID implements glex.Record. func (t *MediaTrack) RecordTypeID() string { return "place.stream.media.track" } // MarshalJSON stamps the $type field, like MarshalCBOR does. The value // receiver operates on a copy, so the record is never mutated and both // MediaTrack and *MediaTrack marshal with $type. func (t MediaTrack) MarshalJSON() ([]byte, error) { t.LexiconTypeID = "place.stream.media.track" type alias MediaTrack return json.Marshal((alias)(t)) } func (t *MediaTrack) 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.media.track" return glex.MarshalCBOR(w, &cp) } func (t *MediaTrack) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } type MediaTrack_Metadata struct { MediaTrack_CommonMetadata *MediaTrack_CommonMetadata // 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 MediaTrack_Metadata and *MediaTrack_Metadata marshal correctly. func (t MediaTrack_Metadata) MarshalJSON() ([]byte, error) { if t.MediaTrack_CommonMetadata != nil { cp := *t.MediaTrack_CommonMetadata cp.LexiconTypeID = "place.stream.media.track#commonMetadata" 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 MediaTrack_Metadata", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union MediaTrack_Metadata as JSON") } func (t *MediaTrack_Metadata) UnmarshalJSON(b []byte) error { typ, err := glex.TypeExtract(b) if err != nil { return err } switch typ { case "place.stream.media.track#commonMetadata": t.MediaTrack_CommonMetadata = new(MediaTrack_CommonMetadata) return json.Unmarshal(b, t.MediaTrack_CommonMetadata) 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 MediaTrack_Metadata) MarshalCBOR() ([]byte, error) { if t.MediaTrack_CommonMetadata != nil { cp := *t.MediaTrack_CommonMetadata cp.LexiconTypeID = "place.stream.media.track#commonMetadata" 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 MediaTrack_Metadata", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union MediaTrack_Metadata as CBOR") } func (t *MediaTrack_Metadata) UnmarshalCBOR(b []byte) error { typ, err := glex.CborTypeExtract(b) if err != nil { return err } switch typ { case "place.stream.media.track#commonMetadata": t.MediaTrack_CommonMetadata = new(MediaTrack_CommonMetadata) return glex.UnmarshalCBORBytes(b, t.MediaTrack_CommonMetadata) default: t.Raw = &glex.RawRecord{Type: typ, Encoding: "cbor", Bytes: append([]byte(nil), b...)} return nil } } type MediaTrack_Track struct { MediaDefs_MuxlTrack *MediaDefs_MuxlTrack // 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 MediaTrack_Track and *MediaTrack_Track marshal correctly. func (t MediaTrack_Track) MarshalJSON() ([]byte, error) { if t.MediaDefs_MuxlTrack != nil { cp := *t.MediaDefs_MuxlTrack cp.LexiconTypeID = "place.stream.media.defs#muxlTrack" 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 MediaTrack_Track", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union MediaTrack_Track as JSON") } func (t *MediaTrack_Track) UnmarshalJSON(b []byte) error { typ, err := glex.TypeExtract(b) if err != nil { return err } switch typ { case "place.stream.media.defs#muxlTrack": t.MediaDefs_MuxlTrack = new(MediaDefs_MuxlTrack) return json.Unmarshal(b, t.MediaDefs_MuxlTrack) 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 MediaTrack_Track) MarshalCBOR() ([]byte, error) { if t.MediaDefs_MuxlTrack != nil { cp := *t.MediaDefs_MuxlTrack cp.LexiconTypeID = "place.stream.media.defs#muxlTrack" 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 MediaTrack_Track", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union MediaTrack_Track as CBOR") } func (t *MediaTrack_Track) UnmarshalCBOR(b []byte) error { typ, err := glex.CborTypeExtract(b) if err != nil { return err } switch typ { case "place.stream.media.defs#muxlTrack": t.MediaDefs_MuxlTrack = new(MediaDefs_MuxlTrack) return glex.UnmarshalCBORBytes(b, t.MediaDefs_MuxlTrack) default: t.Raw = &glex.RawRecord{Type: typ, Encoding: "cbor", Bytes: append([]byte(nil), b...)} return nil } } // MediaTrack_CommonMetadata is a "commonMetadata" in the place.stream.media.track schema. // // Metadata common to all media types. Contains subobjects for other media types. type MediaTrack_CommonMetadata struct { LexiconTypeID string `json:"$type,omitempty"` Audio *Segment_Audio `json:"audio,omitempty"` // durationMs: duration of this track in milliseconds DurationMs *int64 `json:"durationMs,omitempty"` // language: IETF BCP 47 language tag corresponding to the content of this track Language *string `json:"language,omitempty"` Video *Segment_Video `json:"video,omitempty"` } // RecordTypeID implements glex.Record. func (t *MediaTrack_CommonMetadata) RecordTypeID() string { return "place.stream.media.track#commonMetadata" } func (t *MediaTrack_CommonMetadata) 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.media.track#commonMetadata" return glex.MarshalCBOR(w, &cp) } func (t *MediaTrack_CommonMetadata) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } // MediaTrack_TrackView is a "trackView" in the place.stream.media.track schema. type MediaTrack_TrackView struct { LexiconTypeID string `json:"$type,omitempty"` Author appbsky.ActorDefs_ProfileViewBasic `json:"author"` Cid string `json:"cid"` Record *glex.LexiconTypeDecoder `json:"record"` Uri string `json:"uri"` } // RecordTypeID implements glex.Record. func (t *MediaTrack_TrackView) RecordTypeID() string { return "place.stream.media.track#trackView" } func (t *MediaTrack_TrackView) 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.media.track#trackView" return glex.MarshalCBOR(w, &cp) } func (t *MediaTrack_TrackView) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) }