1
0
mirror of https://github.com/garraflavatra/go-fmp.git synced 2025-06-28 04:25:11 +00:00
Files
go-fmp/fmp/fmp_type.go

90 lines
1.5 KiB
Go
Raw Normal View History

2025-06-12 10:43:02 +02:00
package fmp
import (
"io"
"time"
)
type FmpFile struct {
VersionDate time.Time
CreatorName string
FileSize uint
Sectors []*FmpSector
Chunks []*FmpChunk
Dictionary *FmpDict
2025-06-12 21:21:55 +02:00
2025-06-13 12:09:39 +02:00
numSectors uint64 // Excludes the header sector
currentSectorID uint64
stream io.ReadSeeker
2025-06-12 10:43:02 +02:00
}
type FmpSector struct {
2025-06-13 12:09:39 +02:00
ID uint64
Level uint8
Deleted bool
PrevID uint64
NextID uint64
Prev *FmpSector
Next *FmpSector
Chunks []*FmpChunk
2025-06-12 10:43:02 +02:00
}
type FmpChunk struct {
Type FmpChunkType
Length uint64
Key uint64 // If Type == FMP_CHUNK_SHORT_KEY_VALUE or FMP_CHUNK_LONG_KEY_VALUE
Index uint64 // Segment index, if Type == FMP_CHUNK_SEGMENTED_DATA
2025-06-12 10:43:02 +02:00
Value []byte
}
type FmpDict map[uint64]*FmpDictEntry
2025-06-12 10:43:02 +02:00
type FmpDictEntry struct {
Value []byte
Children *FmpDict
}
2025-06-12 11:44:57 +02:00
type FmpTable struct {
Name string
}
func (dict *FmpDict) get(path []uint64) *FmpDictEntry {
2025-06-12 10:43:02 +02:00
for i, key := range path {
_, ok := (*dict)[key]
if !ok {
2025-06-12 11:54:24 +02:00
return nil
2025-06-12 10:43:02 +02:00
}
if i == len(path)-1 {
2025-06-12 11:44:57 +02:00
return (*dict)[key]
2025-06-12 10:43:02 +02:00
} else {
dict = (*dict)[key].Children
}
}
return nil
}
func (dict *FmpDict) getValue(path []uint64) []byte {
2025-06-12 11:44:57 +02:00
ent := dict.get(path)
if ent != nil {
return ent.Value
}
return nil
}
func (dict *FmpDict) set(path []uint64, value []byte) {
2025-06-12 10:43:02 +02:00
for i, key := range path {
_, ok := (*dict)[key]
if !ok {
(*dict)[key] = &FmpDictEntry{Children: &FmpDict{}}
}
if i == len(path)-1 {
(*dict)[key].Value = value
} else {
dict = (*dict)[key].Children
}
}
}