1
1
mirror of https://github.com/wader/fq.git synced 2024-11-23 09:56:07 +03:00

leveldb: add torepr for descriptor

This commit is contained in:
Michael B. 2023-12-07 12:43:55 +01:00
parent 42830911d0
commit 41f27a13c1
6 changed files with 60 additions and 26 deletions

View File

@ -15,7 +15,8 @@ import (
"github.com/wader/fq/pkg/scalar"
)
//go:embed leveldb_log.md
//go:embed leveldb_descriptor.jq
//go:embed leveldb_descriptor.md
var leveldbDescriptorFS embed.FS
func init() {
@ -24,6 +25,7 @@ func init() {
&decode.Format{
Description: "LevelDB Descriptor",
DecodeFn: ldbDescriptorDecode,
Functions: []string{"torepr"},
})
interp.RegisterFS(leveldbDescriptorFS)
}

View File

@ -0,0 +1,42 @@
# TK(2023-12-07): in the output, object-properties are
# sorted alphabetically... how can one prevent this
# and keep the original order?
def _leveldb_descriptor_torepr:
def _f:
( if .type == "root" then
(
[
.value.blocks[].records[]
| {type: "record", value: .}
| _f
]
)
elif .type == "record" then
(
if .value.header.record_type != "full" then
empty
else
[
.value.data.tags[]
| {type: "tag", value: {(.key): .value}}
| _f
]
end
)
elif .type == "tag" then
(
.value
| if .comparator then (.comparator |= .data) else . end
| if ."new file" then (
."new file".largest_internal_key |= .data
| ."new file".smallest_internal_key |= .data
) else . end
| if ."compact pointer" then (
."compact pointer".internal_key |= .data
) else . end
)
end
);
( {type: "root", value: .}
| _f
);

View File

@ -1,7 +1,6 @@
### Limitations
- fragmented non-"full" records are not decoded further.
- fragmented non-"full" records are not merged and decoded further.
### Authors

View File

@ -1,6 +1,6 @@
### Limitations
- individual records are not merged and its data further decoded.
- fragmented non-"full" records are not merged and decoded further.
### Authors

View File

@ -9,3 +9,15 @@ Decode examples
# Decode value as leveldb_descriptor
... | leveldb_descriptor
Limitations
===========
- fragmented non-"full" records are not merged and decoded further.
Authors
=======
- @mikez (https://github.com/mikez), original author
References
==========
- https://github.com/google/leveldb/blob/main/doc/impl.md#manifest
- https://github.com/google/leveldb/blob/main/db/version_edit.cc

View File

@ -11,28 +11,7 @@ Decode examples
Limitations
===========
- individual records are not merged and its data further decoded.
Authors
=======
- @mikez (https://github.com/mikez), original author
References
==========
- https://github.com/google/leveldb/blob/main/doc/log_format.md
leveldb_log: LevelDB Log decoder
Decode examples
===============
# Decode file as leveldb_log
$ fq -d leveldb_log . file
# Decode value as leveldb_log
... | leveldb_log
Limitations
===========
- individual records are not merged and its data further decoded.
- fragmented non-"full" records are not merged and decoded further.
Authors
=======