diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-16 20:39:02 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-16 21:39:43 +0300 |
| commit | 81f365e99636104ff81151370048a51e8ae8027a (patch) | |
| tree | 0bd2781ad73fdc982abdcb70f9f44c551ac76bcf /pkg/classes/stringTable.go | |
| parent | update CI workflow for go 1.21.0 (diff) | |
| download | sdp.go-81f365e99636104ff81151370048a51e8ae8027a.tar.gz sdp.go-81f365e99636104ff81151370048a51e8ae8027a.tar.bz2 sdp.go-81f365e99636104ff81151370048a51e8ae8027a.zip | |
feat: parsing sar custom data (#4)
Diffstat (limited to 'pkg/classes/stringTable.go')
| -rw-r--r-- | pkg/classes/stringTable.go | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/pkg/classes/stringTable.go b/pkg/classes/stringTable.go index c6709f5..3983c1f 100644 --- a/pkg/classes/stringTable.go +++ b/pkg/classes/stringTable.go | |||
| @@ -1,8 +1,6 @@ | |||
| 1 | package classes | 1 | package classes |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "bytes" | ||
| 5 | |||
| 6 | "github.com/pektezol/bitreader" | 4 | "github.com/pektezol/bitreader" |
| 7 | ) | 5 | ) |
| 8 | 6 | ||
| @@ -26,7 +24,7 @@ type StringTableClass struct { | |||
| 26 | Data string | 24 | Data string |
| 27 | } | 25 | } |
| 28 | 26 | ||
| 29 | func ParseStringTables(reader *bitreader.ReaderType) []StringTable { | 27 | func ParseStringTables(reader *bitreader.Reader) []StringTable { |
| 30 | tableCount := reader.TryReadBits(8) | 28 | tableCount := reader.TryReadBits(8) |
| 31 | stringTables := make([]StringTable, tableCount) | 29 | stringTables := make([]StringTable, tableCount) |
| 32 | for i := 0; i < int(tableCount); i++ { | 30 | for i := 0; i < int(tableCount); i++ { |
| @@ -37,7 +35,7 @@ func ParseStringTables(reader *bitreader.ReaderType) []StringTable { | |||
| 37 | return stringTables | 35 | return stringTables |
| 38 | } | 36 | } |
| 39 | 37 | ||
| 40 | func (stringTable *StringTable) ParseStream(reader *bitreader.ReaderType) { | 38 | func (stringTable *StringTable) ParseStream(reader *bitreader.Reader) { |
| 41 | stringTable.Name = reader.TryReadString() | 39 | stringTable.Name = reader.TryReadString() |
| 42 | entryCount := reader.TryReadBits(16) | 40 | entryCount := reader.TryReadBits(16) |
| 43 | stringTable.TableEntries = make([]StringTableEntry, entryCount) | 41 | stringTable.TableEntries = make([]StringTableEntry, entryCount) |
| @@ -60,23 +58,23 @@ func (stringTable *StringTable) ParseStream(reader *bitreader.ReaderType) { | |||
| 60 | } | 58 | } |
| 61 | } | 59 | } |
| 62 | 60 | ||
| 63 | func (stringTableEntry *StringTableEntry) Parse(reader *bitreader.ReaderType) { | 61 | func (stringTableEntry *StringTableEntry) Parse(reader *bitreader.Reader) { |
| 64 | stringTableEntry.Name = reader.TryReadString() | 62 | stringTableEntry.Name = reader.TryReadString() |
| 65 | if reader.TryReadBool() { | 63 | if reader.TryReadBool() { |
| 66 | byteLen, err := reader.ReadBits(16) | 64 | byteLen, err := reader.ReadBits(16) |
| 67 | if err != nil { | 65 | if err != nil { |
| 68 | return | 66 | return |
| 69 | } | 67 | } |
| 70 | dataBsr := reader.TryReadBytesToSlice(int(byteLen)) | 68 | dataBsr := reader.TryReadBytesToSlice(byteLen) |
| 71 | _ = bitreader.Reader(bytes.NewReader(dataBsr), true) // TODO: Parse StringTableEntry | 69 | _ = bitreader.NewReaderFromBytes(dataBsr, true) // TODO: Parse StringTableEntry |
| 72 | // stringTableEntry.EntryData.ParseStream(entryReader) | 70 | // stringTableEntry.EntryData.ParseStream(entryReader) |
| 73 | } | 71 | } |
| 74 | } | 72 | } |
| 75 | 73 | ||
| 76 | func (stringTableClass *StringTableClass) Parse(reader *bitreader.ReaderType) { | 74 | func (stringTableClass *StringTableClass) Parse(reader *bitreader.Reader) { |
| 77 | stringTableClass.Name = reader.TryReadString() | 75 | stringTableClass.Name = reader.TryReadString() |
| 78 | if reader.TryReadBool() { | 76 | if reader.TryReadBool() { |
| 79 | dataLen := reader.TryReadBits(16) | 77 | dataLen := reader.TryReadBits(16) |
| 80 | stringTableClass.Data = reader.TryReadStringLen(int(dataLen)) | 78 | stringTableClass.Data = reader.TryReadStringLength(dataLen) |
| 81 | } | 79 | } |
| 82 | } | 80 | } |