// Code generated by glex; DO NOT EDIT. // Lexicon schema: place.stream.media.viewCount package placestream import ( "encoding/json" "io" glex "github.com/streamplace/glex/runtime" cbg "github.com/whyrusleeping/cbor-gen" comatproto "stream.place/streamplace/pkg/comatproto" ) func init() { glex.RegisterType("place.stream.media.viewCount", &MediaViewCount{}) } // A streamplace node's report of view counts for one place.stream.video over a closed time window. Published in the reporting node's server repo (not the streamer's), so a video served by multiple nodes accumulates multiple records — consumers are expected to sum across trusted reporters. The rkey is conventionally `-` so re-running the aggregator over the same window is idempotent. Counts represent the reporting node's best effort given the data it has; the `tracks` array carries the objective byte / duration totals it observed. type MediaViewCount struct { LexiconTypeID string `json:"$type,omitempty"` // count: Number of distinct sessions the reporting node observed as a view over [windowStart, windowEnd). Count int64 `json:"count"` // indexedAt: When the reporting node ran this aggregation. Useful for ordering successive reports. IndexedAt string `json:"indexedAt"` // tracks: Per-track totals of bytes + playback duration the reporting node served over the window. Each entry references the place.stream.media.track record whose bytes were transferred, so user-contributed tracks (transcripts, transcodes published by other accounts) attribute naturally to their own records. Tracks []MediaViewCount_TrackUsage `json:"tracks,omitempty"` // video: AT-URI of the place.stream.video this count is for. Video string `json:"video"` // windowEnd: Exclusive upper bound of the aggregation window. WindowEnd string `json:"windowEnd"` // windowStart: Inclusive lower bound of the aggregation window. WindowStart string `json:"windowStart"` } // RecordTypeID implements glex.Record. func (t *MediaViewCount) RecordTypeID() string { return "place.stream.media.viewCount" } // MarshalJSON stamps the $type field, like MarshalCBOR does. The value // receiver operates on a copy, so the record is never mutated and both // MediaViewCount and *MediaViewCount marshal with $type. func (t MediaViewCount) MarshalJSON() ([]byte, error) { t.LexiconTypeID = "place.stream.media.viewCount" type alias MediaViewCount return json.Marshal((alias)(t)) } func (t *MediaViewCount) 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.viewCount" return glex.MarshalCBOR(w, &cp) } func (t *MediaViewCount) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } // MediaViewCount_TrackUsage is a "trackUsage" in the place.stream.media.viewCount schema. // // One row of the tracks array: bytes + duration transferred for a single place.stream.media.track record over the window. type MediaViewCount_TrackUsage struct { LexiconTypeID string `json:"$type,omitempty"` // bytes: Total bytes served from this track over the window. Sum across attributed segment_requests' Range intersections with the track's segment offsets in the metafile. Bytes int64 `json:"bytes"` // durationMs: Total playback duration served from this track, in milliseconds. Per HLS segment in the range: (overlap bytes / segment bytes) * segment duration, so partial-segment fetches credit a proportional share of duration. DurationMs int64 `json:"durationMs"` // track: Strong reference to the place.stream.media.track record whose bytes were transferred. Track comatproto.RepoStrongRef `json:"track"` } // RecordTypeID implements glex.Record. func (t *MediaViewCount_TrackUsage) RecordTypeID() string { return "place.stream.media.viewCount#trackUsage" } func (t *MediaViewCount_TrackUsage) 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.viewCount#trackUsage" return glex.MarshalCBOR(w, &cp) } func (t *MediaViewCount_TrackUsage) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) }