diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-12 20:53:09 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-16 21:39:42 +0300 |
| commit | 82871ba1bac1d62f69e1933b66659e62d2e5e063 (patch) | |
| tree | a906310fba89b670bcfda9625a6d776553d482f6 /pkg/classes/stringTable.go | |
| parent | net/svc messages finally getting parsed correctly (diff) | |
| download | sdp.go-82871ba1bac1d62f69e1933b66659e62d2e5e063.tar.gz sdp.go-82871ba1bac1d62f69e1933b66659e62d2e5e063.tar.bz2 sdp.go-82871ba1bac1d62f69e1933b66659e62d2e5e063.zip | |
another rewrite, v1.0.0
Diffstat (limited to 'pkg/classes/stringTable.go')
| -rw-r--r-- | pkg/classes/stringTable.go | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/pkg/classes/stringTable.go b/pkg/classes/stringTable.go new file mode 100644 index 0000000..c6709f5 --- /dev/null +++ b/pkg/classes/stringTable.go | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "bytes" | ||
| 5 | |||
| 6 | "github.com/pektezol/bitreader" | ||
| 7 | ) | ||
| 8 | |||
| 9 | type StringTable struct { | ||
| 10 | Name string | ||
| 11 | TableEntries []StringTableEntry | ||
| 12 | Classes []StringTableClass | ||
| 13 | } | ||
| 14 | |||
| 15 | type StringTableEntry struct { | ||
| 16 | Name string | ||
| 17 | EntryData StringTableEntryData | ||
| 18 | } | ||
| 19 | |||
| 20 | type StringTableEntryData struct { | ||
| 21 | // TODO: Parse StringTableEntry | ||
| 22 | } | ||
| 23 | |||
| 24 | type StringTableClass struct { | ||
| 25 | Name string | ||
| 26 | Data string | ||
| 27 | } | ||
| 28 | |||
| 29 | func ParseStringTables(reader *bitreader.ReaderType) []StringTable { | ||
| 30 | tableCount := reader.TryReadBits(8) | ||
| 31 | stringTables := make([]StringTable, tableCount) | ||
| 32 | for i := 0; i < int(tableCount); i++ { | ||
| 33 | var table StringTable | ||
| 34 | table.ParseStream(reader) | ||
| 35 | stringTables[i] = table | ||
| 36 | } | ||
| 37 | return stringTables | ||
| 38 | } | ||
| 39 | |||
| 40 | func (stringTable *StringTable) ParseStream(reader *bitreader.ReaderType) { | ||
| 41 | stringTable.Name = reader.TryReadString() | ||
| 42 | entryCount := reader.TryReadBits(16) | ||
| 43 | stringTable.TableEntries = make([]StringTableEntry, entryCount) | ||
| 44 | |||
| 45 | for i := 0; i < int(entryCount); i++ { | ||
| 46 | var entry StringTableEntry | ||
| 47 | entry.Parse(reader) | ||
| 48 | stringTable.TableEntries[i] = entry | ||
| 49 | } | ||
| 50 | |||
| 51 | if reader.TryReadBool() { | ||
| 52 | classCount := reader.TryReadBits(16) | ||
| 53 | stringTable.Classes = make([]StringTableClass, classCount) | ||
| 54 | |||
| 55 | for i := 0; i < int(classCount); i++ { | ||
| 56 | var class StringTableClass | ||
| 57 | class.Parse(reader) | ||
| 58 | stringTable.Classes[i] = class | ||
| 59 | } | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | func (stringTableEntry *StringTableEntry) Parse(reader *bitreader.ReaderType) { | ||
| 64 | stringTableEntry.Name = reader.TryReadString() | ||
| 65 | if reader.TryReadBool() { | ||
| 66 | byteLen, err := reader.ReadBits(16) | ||
| 67 | if err != nil { | ||
| 68 | return | ||
| 69 | } | ||
| 70 | dataBsr := reader.TryReadBytesToSlice(int(byteLen)) | ||
| 71 | _ = bitreader.Reader(bytes.NewReader(dataBsr), true) // TODO: Parse StringTableEntry | ||
| 72 | // stringTableEntry.EntryData.ParseStream(entryReader) | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | func (stringTableClass *StringTableClass) Parse(reader *bitreader.ReaderType) { | ||
| 77 | stringTableClass.Name = reader.TryReadString() | ||
| 78 | if reader.TryReadBool() { | ||
| 79 | dataLen := reader.TryReadBits(16) | ||
| 80 | stringTableClass.Data = reader.TryReadStringLen(int(dataLen)) | ||
| 81 | } | ||
| 82 | } | ||