DemoStream¶
Iterates over the outer .dem container format, handling tick-delimited messages and Snappy decompression.
See also: The .dem Format, Snappy Compression
gem.stream.DemoStream
¶
Iterates outer messages from a Source 2 .dem file.
Accepts either a raw byte buffer or a file path. When given a path, the file is memory-mapped so large replays are not fully loaded into RAM before iteration begins.
Validates the magic header on construction, then exposes the message stream via iteration. Each step yields a (tick, msg_type, data) tuple.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
bytes | str | Path
|
A bytes buffer or a str/Path pointing to a .dem file. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the magic bytes do not match PBDEMS2. |
Source code in src/gem/stream.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
close() -> None
¶
Release memory-map and file descriptor resources, if any.
__iter__() -> Iterator[tuple[int, int, bytes]]
¶
Iterate over all outer messages in the replay.
Yields:
| Type | Description |
|---|---|
int
|
tuple[int, int, bytes]: A (tick, msg_type, data) tuple for |
int
|
each message. Unpackable directly:: for tick, msg_type, data in stream: ... |
Source code in src/gem/stream.py
gem.stream.OuterMessage
dataclass
¶
A single decoded outer demo message.
Attributes:
| Name | Type | Description |
|---|---|---|
tick |
int
|
Game tick this message belongs to (pre-game normalised to 0). |
msg_type |
int
|
EDemoCommands value identifying the message type. |
data |
bytes
|
Raw (decompressed) protobuf payload bytes. |