diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-06-15 13:58:30 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-15 13:58:30 +0300 |
| commit | 77e4b066cb8d506b4bc944ab4eb2d6e4679e2202 (patch) | |
| tree | 1d549eca619ed36cb881e487cb054c4643ac8376 /pkg/packets/headers.go | |
| parent | change project name to sdp.go (diff) | |
| download | sdp.go-77e4b066cb8d506b4bc944ab4eb2d6e4679e2202.tar.gz sdp.go-77e4b066cb8d506b4bc944ab4eb2d6e4679e2202.tar.bz2 sdp.go-77e4b066cb8d506b4bc944ab4eb2d6e4679e2202.zip | |
enable multithreading with goroutines (#20)
Diffstat (limited to '')
| -rw-r--r-- | pkg/packets/headers.go | 42 |
1 files changed, 14 insertions, 28 deletions
diff --git a/pkg/packets/headers.go b/pkg/packets/headers.go index 6c5ab10..bee8ddf 100644 --- a/pkg/packets/headers.go +++ b/pkg/packets/headers.go | |||
| @@ -2,25 +2,11 @@ package packets | |||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "github.com/pektezol/bitreader" | 4 | "github.com/pektezol/bitreader" |
| 5 | "github.com/pektezol/sdp.go/pkg/writer" | 5 | "github.com/pektezol/sdp.go/pkg/types" |
| 6 | ) | 6 | ) |
| 7 | 7 | ||
| 8 | type Headers struct { | 8 | func ParseHeaders(reader *bitreader.Reader, demo *types.Demo) types.Headers { |
| 9 | DemoFileStamp string | 9 | headers := types.Headers{ |
| 10 | DemoProtocol int32 | ||
| 11 | NetworkProtocol int32 | ||
| 12 | ServerName string | ||
| 13 | ClientName string | ||
| 14 | MapName string | ||
| 15 | GameDirectory string | ||
| 16 | PlaybackTime float32 | ||
| 17 | PlaybackTicks int32 | ||
| 18 | PlaybackFrames int32 | ||
| 19 | SignOnLength int32 | ||
| 20 | } | ||
| 21 | |||
| 22 | func ParseHeaders(reader *bitreader.Reader) Headers { | ||
| 23 | headers := Headers{ | ||
| 24 | DemoFileStamp: reader.TryReadString(), | 10 | DemoFileStamp: reader.TryReadString(), |
| 25 | DemoProtocol: int32(reader.TryReadSInt32()), | 11 | DemoProtocol: int32(reader.TryReadSInt32()), |
| 26 | NetworkProtocol: int32(reader.TryReadSInt32()), | 12 | NetworkProtocol: int32(reader.TryReadSInt32()), |
| @@ -42,16 +28,16 @@ func ParseHeaders(reader *bitreader.Reader) Headers { | |||
| 42 | if headers.NetworkProtocol != 2001 { | 28 | if headers.NetworkProtocol != 2001 { |
| 43 | panic("this parser only supports demos from portal 2") | 29 | panic("this parser only supports demos from portal 2") |
| 44 | } | 30 | } |
| 45 | writer.AppendLine("\nDemo File Stamp: %s", headers.DemoFileStamp) | 31 | demo.Writer.AppendLine("\nDemo File Stamp: %s", headers.DemoFileStamp) |
| 46 | writer.AppendLine("Demo Protocol: %d", headers.DemoProtocol) | 32 | demo.Writer.AppendLine("Demo Protocol: %d", headers.DemoProtocol) |
| 47 | writer.AppendLine("Network Protocol: %d", headers.NetworkProtocol) | 33 | demo.Writer.AppendLine("Network Protocol: %d", headers.NetworkProtocol) |
| 48 | writer.AppendLine("Server Name: %s", headers.ServerName) | 34 | demo.Writer.AppendLine("Server Name: %s", headers.ServerName) |
| 49 | writer.AppendLine("Client Name: %s", headers.ClientName) | 35 | demo.Writer.AppendLine("Client Name: %s", headers.ClientName) |
| 50 | writer.AppendLine("Map Name: %s", headers.MapName) | 36 | demo.Writer.AppendLine("Map Name: %s", headers.MapName) |
| 51 | writer.AppendLine("Game Directory: %s", headers.GameDirectory) | 37 | demo.Writer.AppendLine("Game Directory: %s", headers.GameDirectory) |
| 52 | writer.AppendLine("Playback Time: %f", headers.PlaybackTime) | 38 | demo.Writer.AppendLine("Playback Time: %f", headers.PlaybackTime) |
| 53 | writer.AppendLine("Playback Ticks: %d", headers.PlaybackTicks) | 39 | demo.Writer.AppendLine("Playback Ticks: %d", headers.PlaybackTicks) |
| 54 | writer.AppendLine("Playback Frames: %d", headers.PlaybackFrames) | 40 | demo.Writer.AppendLine("Playback Frames: %d", headers.PlaybackFrames) |
| 55 | writer.AppendLine("Sign On Length: %d\n", headers.SignOnLength) | 41 | demo.Writer.AppendLine("Sign On Length: %d\n", headers.SignOnLength) |
| 56 | return headers | 42 | return headers |
| 57 | } | 43 | } |