Skip to content

Commit

Permalink
leveldb: updates per PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mikez committed Dec 6, 2023
1 parent 2df0f0f commit fe1099b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ var (
JSON = &decode.Group{Name: "json"}
JSONL = &decode.Group{Name: "jsonl"}
LevelDB_Descriptor = &decode.Group{Name: "leveldb_descriptor"}
LDB = &decode.Group{Name: "leveldb_table"}
LOG = &decode.Group{Name: "leveldb_log"}
LevelDB_LDB = &decode.Group{Name: "leveldb_table"}
LevelDB_LOG = &decode.Group{Name: "leveldb_log"}
LuaJIT = &decode.Group{Name: "luajit"}
MachO = &decode.Group{Name: "macho"}
MachO_Fat = &decode.Group{Name: "macho_fat"}
Expand Down
6 changes: 1 addition & 5 deletions format/leveldb/leveldb_descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func init() {
format.LevelDB_Descriptor,
&decode.Format{
Description: "LevelDB Descriptor",
Groups: []*decode.Group{format.Probe},
DecodeFn: ldbDescriptorDecode,
})
interp.RegisterFS(leveldbDescriptorFS)
Expand Down Expand Up @@ -70,10 +69,7 @@ func ldbDescriptorDecode(d *decode.D) any {
// List of sorted tables for each level involving key ranges and other metadata.
func readManifest(d *decode.D) {
d.FieldArray("tags", func(d *decode.D) {
for {
if d.End() {
break
}
for !d.End() {
d.FieldStruct("tag", func(d *decode.D) {
tag := d.FieldULEB128("key", tagTypes)
switch tag {
Expand Down
3 changes: 1 addition & 2 deletions format/leveldb/leveldb_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ var leveldbLogFS embed.FS

func init() {
interp.RegisterFormat(
format.LOG,
format.LevelDB_LOG,
&decode.Format{
Description: "LevelDB Log",
Groups: []*decode.Group{format.Probe},
DecodeFn: ldbLogDecode,
})
interp.RegisterFS(leveldbLogFS)
Expand Down
13 changes: 8 additions & 5 deletions format/leveldb/leveldb_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var leveldbFS embed.FS

func init() {
interp.RegisterFormat(
format.LDB,
format.LevelDB_LDB,
&decode.Format{
Description: "LevelDB Table",
Groups: []*decode.Group{format.Probe},
Expand Down Expand Up @@ -82,9 +82,13 @@ func ldbTableDecode(d *decode.D) any {
var metaIndexOffset int64
var metaIndexSize int64

d.SeekAbs(d.Len() - footerEncodedLength)
d.FieldStruct("footer", func(d *decode.D) {
handleLength := d.LimitedFn(footerEncodedLength, func(d *decode.D) {
// check for magic number and fail fast if it isn't there
d.SeekAbs(d.Len() - magicNumberLength)
d.FieldU64("magic_number", d.UintAssert(tableMagicNumber), scalar.UintHex)

d.SeekAbs(d.Len() - footerEncodedLength)
d.LimitedFn(footerEncodedLength-magicNumberLength, func(d *decode.D) {
d.FieldStruct("metaindex_handle", func(d *decode.D) {
metaIndexOffset = int64(d.FieldULEB128("offset"))
metaIndexSize = int64(d.FieldULEB128("size"))
Expand All @@ -93,9 +97,8 @@ func ldbTableDecode(d *decode.D) any {
indexOffset = int64(d.FieldULEB128("offset"))
indexSize = int64(d.FieldULEB128("size"))
})
d.FieldRawLen("padding", d.BitsLeft())
})
d.FieldRawLen("padding", footerEncodedLength-handleLength-magicNumberLength)
d.FieldU64("magic_number", d.UintAssert(tableMagicNumber), scalar.UintHex)
})

// metaindex
Expand Down

0 comments on commit fe1099b

Please sign in to comment.