1
1
mirror of https://github.com/wader/fq.git synced 2024-12-24 22:05:31 +03:00

Merge pull request #37 from wader/bson

bson: Add decoder
This commit is contained in:
Mattias Wadman 2022-01-06 00:55:09 +01:00 committed by GitHub
commit aa7bbef7f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 244 additions and 20 deletions

View File

@ -11,6 +11,7 @@
"BCDU",
"bgrep",
"bitio",
"bson",
"bxor",
"bzip",
"CCIT",
@ -138,6 +139,7 @@
"toimage",
"tojson",
"tojvalue",
"torepr",
"tovalue",
"traf",
"trex",

View File

@ -94,7 +94,7 @@ cp fq /usr/local/bin
[./formats_list.jq]: sh-start
aac_frame, adts, adts_frame, apev2, ar, av1_ccr, av1_frame, av1_obu, avc_annexb, avc_au, avc_dcr, avc_nalu, avc_pps, avc_sei, avc_sps, bsd_loopback_frame, bzip2, dns, dns_tcp, elf, ether8023_frame, exif, flac, flac_frame, flac_metadatablock, flac_metadatablocks, flac_picture, flac_streaminfo, gif, gzip, hevc_annexb, hevc_au, hevc_dcr, hevc_nalu, icc_profile, icmp, id3v1, id3v11, id3v2, ipv4_packet, jpeg, json, matroska, mp3, mp3_frame, mp4, mpeg_asc, mpeg_es, mpeg_pes, mpeg_pes_packet, mpeg_spu, mpeg_ts, ogg, ogg_page, opus_packet, pcap, pcapng, png, protobuf, protobuf_widevine, pssh_playready, raw, sll2_packet, sll_packet, tar, tcp_segment, tiff, udp_datagram, vorbis_comment, vorbis_packet, vp8_frame, vp9_cfm, vp9_frame, vpx_ccr, wav, webp, xing, zip
aac_frame, adts, adts_frame, apev2, ar, av1_ccr, av1_frame, av1_obu, avc_annexb, avc_au, avc_dcr, avc_nalu, avc_pps, avc_sei, avc_sps, bsd_loopback_frame, bson, bzip2, dns, dns_tcp, elf, ether8023_frame, exif, flac, flac_frame, flac_metadatablock, flac_metadatablocks, flac_picture, flac_streaminfo, gif, gzip, hevc_annexb, hevc_au, hevc_dcr, hevc_nalu, icc_profile, icmp, id3v1, id3v11, id3v2, ipv4_packet, jpeg, json, matroska, mp3, mp3_frame, mp4, mpeg_asc, mpeg_es, mpeg_pes, mpeg_pes_packet, mpeg_spu, mpeg_ts, ogg, ogg_page, opus_packet, pcap, pcapng, png, protobuf, protobuf_widevine, pssh_playready, raw, sll2_packet, sll_packet, tar, tcp_segment, tiff, udp_datagram, vorbis_comment, vorbis_packet, vp8_frame, vp9_cfm, vp9_frame, vpx_ccr, wav, webp, xing, zip
[#]: sh-end

View File

@ -20,6 +20,7 @@
|`avc_sei` |H.264/AVC&nbsp;Supplemental&nbsp;Enhancement&nbsp;Information |<sub></sub>|
|`avc_sps` |H.264/AVC&nbsp;Sequence&nbsp;Parameter&nbsp;Set |<sub></sub>|
|`bsd_loopback_frame` |BSD&nbsp;loopback&nbsp;frame |<sub>`ipv4_packet`</sub>|
|`bson` |Binary&nbsp;JSON |<sub></sub>|
|`bzip2` |bzip2&nbsp;compression |<sub>`probe`</sub>|
|`dns` |DNS&nbsp;packet |<sub></sub>|
|`dns_tcp` |DNS&nbsp;packet&nbsp;(TCP) |<sub></sub>|

View File

@ -388,7 +388,7 @@
<!-- probe&#45;&gt;pcap -->
<g id="edge130" class="edge">
<title>probe&#45;&gt;pcap:pcap</title>
<path fill="none" stroke="black" d="M2282.12,-1533.56C2285.39,-1532.21 2288.73,-1530.98 2292,-1530 2399.06,-1497.74 2446.03,-1553.02 2541,-1494 2553.14,-1486.46 2548.42,-1469.46 2556.25,-1463.84"/>
<path fill="none" stroke="black" d="M2282.16,-1533.22C2285.1,-1532 2288.08,-1530.9 2291,-1530 2398.32,-1497.07 2445.64,-1553.23 2541,-1494 2553.14,-1486.46 2548.42,-1469.46 2556.25,-1463.84"/>
<polygon fill="black" stroke="black" points="2556.89,-1466.21 2563,-1462 2555.6,-1461.48 2556.89,-1466.21"/>
</g>
<!-- pcapng -->
@ -406,7 +406,7 @@
<!-- probe&#45;&gt;pcapng -->
<g id="edge131" class="edge">
<title>probe&#45;&gt;pcapng:pcapng</title>
<path fill="none" stroke="black" d="M2282.05,-1533.33C2285.34,-1532.02 2288.7,-1530.87 2292,-1530 2400.61,-1501.51 2701.89,-1555.24 2796,-1494 2806.76,-1487 2800.94,-1470.84 2806.28,-1464.56"/>
<path fill="none" stroke="black" d="M2282.1,-1533C2285.04,-1531.83 2288.05,-1530.79 2291,-1530 2399.67,-1500.88 2701.7,-1555.36 2796,-1494 2806.76,-1487 2800.94,-1470.84 2806.28,-1464.56"/>
<polygon fill="black" stroke="black" points="2807.33,-1466.78 2813,-1462 2805.59,-1462.2 2807.33,-1466.78"/>
</g>
<!-- probe&#45;&gt;png -->
@ -427,7 +427,7 @@
<!-- probe&#45;&gt;tar -->
<g id="edge136" class="edge">
<title>probe&#45;&gt;tar:tar</title>
<path fill="none" stroke="black" d="M2282.23,-1533.92C2285.49,-1532.5 2288.79,-1531.16 2292,-1530 2352,-1508.26 2382.2,-1535.12 2431,-1494 2447.79,-1479.85 2433.48,-1450.94 2447.01,-1444.35"/>
<path fill="none" stroke="black" d="M2282.27,-1533.54C2285.18,-1532.26 2288.13,-1531.05 2291,-1530 2351.31,-1507.84 2381.84,-1535.36 2431,-1494 2447.8,-1479.87 2433.48,-1450.94 2447.01,-1444.35"/>
<polygon fill="black" stroke="black" points="2447.59,-1446.74 2454,-1443 2446.66,-1441.93 2447.59,-1446.74"/>
</g>
<!-- probe&#45;&gt;tiff -->
@ -472,8 +472,8 @@
<!-- probe&#45;&gt;zip -->
<g id="edge142" class="edge">
<title>probe&#45;&gt;zip:zip</title>
<path fill="none" stroke="black" d="M2282.08,-1533.42C2285.36,-1532.1 2288.71,-1530.91 2292,-1530 2369.47,-1508.5 2588.76,-1543.65 2652,-1494 2668.54,-1481.01 2651.51,-1451.71 2663.1,-1444.58"/>
<polygon fill="black" stroke="black" points="2663.72,-1446.95 2670,-1443 2662.63,-1442.18 2663.72,-1446.95"/>
<path fill="none" stroke="black" d="M2282.12,-1533.09C2285.06,-1531.9 2288.06,-1530.83 2291,-1530 2368.57,-1508.04 2588.58,-1543.78 2652,-1494 2668.54,-1481.01 2651.51,-1451.71 2663.1,-1444.58"/>
<polygon fill="black" stroke="black" points="2663.73,-1446.95 2670,-1443 2662.63,-1442.18 2663.73,-1446.95"/>
</g>
<!-- elf -->
<g id="node78" class="node">
@ -484,13 +484,13 @@
<!-- probe&#45;&gt;elf -->
<g id="edge115" class="edge">
<title>probe&#45;&gt;elf:elf</title>
<path fill="none" stroke="black" d="M2282.06,-1533.37C2285.35,-1532.05 2288.71,-1530.88 2292,-1530 2385.03,-1505.01 2642.09,-1544.71 2724,-1494 2740.32,-1483.9 2750.44,-1463.67 2755.89,-1449.28"/>
<path fill="none" stroke="black" d="M2282.11,-1533.04C2285.05,-1531.86 2288.05,-1530.81 2291,-1530 2384.11,-1504.46 2641.9,-1544.82 2724,-1494 2740.32,-1483.9 2750.44,-1463.67 2755.89,-1449.28"/>
<polygon fill="black" stroke="black" points="2758.31,-1449.79 2758.32,-1442.37 2753.68,-1448.16 2758.31,-1449.79"/>
</g>
<!-- probe&#45;&gt;gif -->
<g id="edge118" class="edge">
<title>probe&#45;&gt;gif:gif</title>
<path fill="none" stroke="black" d="M2282.14,-1533.63C2285.41,-1532.27 2288.75,-1531.02 2292,-1530 2384.88,-1500.92 2434.49,-1557.78 2508,-1494 2529.13,-1475.67 2511.72,-1457.43 2527,-1434"/>
<path fill="none" stroke="black" d="M2282.18,-1533.28C2285.11,-1532.05 2288.09,-1530.93 2291,-1530 2384.15,-1500.32 2434.13,-1558.04 2508,-1494 2529.13,-1475.68 2511.72,-1457.43 2527,-1434"/>
<path fill="none" stroke="black" d="M2527,-1432C2549.07,-1398.15 2527.77,-775.79 2522.93,-642.14"/>
<polygon fill="black" stroke="black" points="2525.38,-642 2522.67,-635.09 2520.48,-642.18 2525.38,-642"/>
</g>
@ -503,7 +503,7 @@
<!-- probe&#45;&gt;json -->
<g id="edge123" class="edge">
<title>probe&#45;&gt;json:json</title>
<path fill="none" stroke="black" d="M2282.04,-1533.29C2285.33,-1531.99 2288.7,-1530.85 2292,-1530 2423.56,-1496.36 2785.69,-1564.08 2902,-1494 2918.44,-1484.09 2928.54,-1463.82 2933.94,-1449.37"/>
<path fill="none" stroke="black" d="M2282.09,-1532.96C2285.04,-1531.8 2288.04,-1530.77 2291,-1530 2422.59,-1495.6 2785.5,-1564.19 2902,-1494 2918.44,-1484.09 2928.54,-1463.82 2933.94,-1449.37"/>
<polygon fill="black" stroke="black" points="2936.37,-1449.84 2936.35,-1442.43 2931.74,-1448.24 2936.37,-1449.84"/>
</g>
<!-- mpeg_ts -->
@ -515,7 +515,7 @@
<!-- probe&#45;&gt;mpeg_ts -->
<g id="edge128" class="edge">
<title>probe&#45;&gt;mpeg_ts:mpeg_ts</title>
<path fill="none" stroke="black" d="M2282.04,-1533.27C2285.33,-1531.97 2288.69,-1530.83 2292,-1530 2439.15,-1492.85 2840.76,-1566.67 2974,-1494 2992.13,-1484.11 3004.65,-1463.17 3011.57,-1448.6"/>
<path fill="none" stroke="black" d="M2282.08,-1532.95C2285.03,-1531.78 2288.04,-1530.76 2291,-1530 2438.17,-1492.02 2840.57,-1566.77 2974,-1494 2992.13,-1484.11 3004.65,-1463.17 3011.57,-1448.6"/>
<polygon fill="black" stroke="black" points="3013.89,-1449.42 3014.52,-1442.03 3009.42,-1447.41 3013.89,-1449.42"/>
</g>
<!-- av1_frame -->
@ -1524,8 +1524,8 @@
<!-- tar&#45;&gt;probe -->
<g id="edge99" class="edge">
<title>tar:probe&#45;&gt;probe</title>
<path fill="none" stroke="black" d="M2454,-1423C2420.83,-1423 2455.15,-1471.26 2431,-1494 2384.55,-1537.75 2352,-1508.26 2292,-1530 2291,-1530.36 2289.99,-1530.74 2288.97,-1531.14"/>
<polygon fill="black" stroke="black" points="2287.77,-1528.98 2282.23,-1533.92 2289.64,-1533.51 2287.77,-1528.98"/>
<path fill="none" stroke="black" d="M2454,-1423C2420.83,-1423 2455.17,-1471.28 2431,-1494 2384.19,-1538.01 2351.31,-1507.84 2291,-1530 2290.28,-1530.26 2289.56,-1530.54 2288.83,-1530.82"/>
<polygon fill="black" stroke="black" points="2287.8,-1528.6 2282.27,-1533.54 2289.67,-1533.12 2287.8,-1528.6"/>
</g>
<!-- tiff&#45;&gt;icc_profile -->
<g id="edge100" class="edge">
@ -1565,20 +1565,26 @@
<!-- zip&#45;&gt;probe -->
<g id="edge108" class="edge">
<title>zip:probe&#45;&gt;probe</title>
<path fill="none" stroke="black" d="M2670,-1423C2637.45,-1423 2676.66,-1472.75 2652,-1494 2591.09,-1546.47 2369.47,-1508.5 2292,-1530 2290.97,-1530.29 2289.94,-1530.6 2288.9,-1530.93"/>
<polygon fill="black" stroke="black" points="2287.81,-1528.72 2282.08,-1533.42 2289.49,-1533.32 2287.81,-1528.72"/>
<path fill="none" stroke="black" d="M2670,-1423C2637.45,-1423 2676.67,-1472.76 2652,-1494 2590.91,-1546.61 2368.57,-1508.04 2291,-1530 2290.26,-1530.21 2289.53,-1530.43 2288.79,-1530.67"/>
<polygon fill="black" stroke="black" points="2287.86,-1528.39 2282.12,-1533.09 2289.54,-1533 2287.86,-1528.39"/>
</g>
<!-- bson -->
<g id="node82" class="node">
<title>bson</title>
<polygon fill="paleturquoise" stroke="transparent" points="2312,-1539 2312,-1558 2342,-1558 2342,-1539 2312,-1539"/>
<text text-anchor="start" x="2314" y="-1544.3" font-family="Times,serif" font-size="14.00">bson</text>
</g>
<!-- dns_tcp -->
<g id="node82" class="node">
<g id="node83" class="node">
<title>dns_tcp</title>
<polygon fill="paleturquoise" stroke="transparent" points="2308.5,-1539 2308.5,-1558 2355.5,-1558 2355.5,-1539 2308.5,-1539"/>
<text text-anchor="start" x="2311" y="-1544.3" font-family="Times,serif" font-size="14.00">dns_tcp</text>
<polygon fill="paleturquoise" stroke="transparent" points="2380.5,-1539 2380.5,-1558 2427.5,-1558 2427.5,-1539 2380.5,-1539"/>
<text text-anchor="start" x="2383" y="-1544.3" font-family="Times,serif" font-size="14.00">dns_tcp</text>
</g>
<!-- raw -->
<g id="node83" class="node">
<g id="node84" class="node">
<title>raw</title>
<polygon fill="paleturquoise" stroke="transparent" points="2396.5,-1539 2396.5,-1558 2421.5,-1558 2421.5,-1539 2396.5,-1539"/>
<text text-anchor="start" x="2399" y="-1544.3" font-family="Times,serif" font-size="14.00">raw</text>
<polygon fill="paleturquoise" stroke="transparent" points="2468.5,-1539 2468.5,-1558 2493.5,-1558 2493.5,-1539 2468.5,-1539"/>
<text text-anchor="start" x="2471" y="-1544.3" font-family="Times,serif" font-size="14.00">raw</text>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 101 KiB

After

Width:  |  Height:  |  Size: 101 KiB

View File

@ -6,6 +6,7 @@ import (
_ "github.com/wader/fq/format/ape"
_ "github.com/wader/fq/format/ar"
_ "github.com/wader/fq/format/av1"
_ "github.com/wader/fq/format/bson"
_ "github.com/wader/fq/format/bzip2"
_ "github.com/wader/fq/format/dns"
_ "github.com/wader/fq/format/elf"

116
format/bson/bson.go Normal file
View File

@ -0,0 +1,116 @@
package bson
// https://bsonspec.org/spec.html
// TODO: more types
import (
"embed"
"github.com/wader/fq/format"
"github.com/wader/fq/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/scalar"
)
//go:embed *.jq
var bsonFS embed.FS
func init() {
registry.MustRegister(decode.Format{
Name: format.BSON,
Description: "Binary JSON",
DecodeFn: decodeBSON,
Files: bsonFS,
})
}
const (
elementTypeDouble = 0x01
elementTypeString = 0x02
elementTypeDocument = 0x03
elementTypeArray = 0x04
elementTypeBinary = 0x05
elementTypeUndefined = 0x06
elementTypeObjectID = 0x07
elementTypeBoolean = 0x08
elementTypeDatatime = 0x09
elementTypeNull = 0x0a
elementTypeRegexp = 0x0b
elementTypeInt32 = 0x10
elementTypeTimestamp = 0x11
elementTypeInt64 = 0x12
)
var elementTypeMap = scalar.UToScalar{
elementTypeDouble: {Sym: "double", Description: "64-bit binary floating point"},
elementTypeString: {Sym: "string", Description: "UTF-8 string"},
elementTypeDocument: {Sym: "document", Description: "Embedded document"},
elementTypeArray: {Sym: "array", Description: "Array"},
elementTypeBinary: {Sym: "binary", Description: "Binary data"},
elementTypeUndefined: {Sym: "undefined", Description: "Undefined (deprecated)"},
elementTypeObjectID: {Sym: "object_id", Description: "ObjectId"},
elementTypeBoolean: {Sym: "boolean", Description: "Boolean"},
elementTypeDatatime: {Sym: "datatime", Description: "UTC datetime"},
elementTypeNull: {Sym: "null", Description: "Null value"},
elementTypeRegexp: {Sym: "regexp", Description: "Regular expression"},
elementTypeInt32: {Sym: "int32", Description: "32-bit integer"},
elementTypeTimestamp: {Sym: "timestamp", Description: "Timestamp"},
elementTypeInt64: {Sym: "int64", Description: "64-bit integer"},
}
func decodeBSONDocument(d *decode.D) {
size := d.FieldU32("size")
d.LenFn(int64(size-4)*8, func(d *decode.D) {
d.FieldArray("elements", func(d *decode.D) {
for d.BitsLeft() > 8 {
d.FieldStruct("element", func(d *decode.D) {
typ := d.FieldU8("type", elementTypeMap)
d.FieldUTF8Null("name")
switch typ {
case elementTypeDouble:
d.FieldF64("value")
case elementTypeString:
length := d.FieldU32("length")
d.FieldUTF8NullFixedLen("value", int(length))
case elementTypeDocument:
d.FieldStruct("value", decodeBSONDocument)
case elementTypeArray:
d.FieldStruct("value", decodeBSONDocument)
case elementTypeBinary:
length := d.FieldU32("length")
d.FieldU8("subtype")
d.FieldRawLen("value", int64(length)*8)
case elementTypeUndefined:
case elementTypeObjectID:
d.FieldRawLen("value", 12*8)
case elementTypeBoolean:
d.FieldU8("value")
case elementTypeDatatime:
d.FieldS32("value")
case elementTypeNull:
case elementTypeRegexp:
d.FieldUTF8Null("value")
d.FieldUTF8Null("options")
case elementTypeInt32:
d.FieldS32("value")
case elementTypeTimestamp:
d.FieldU64("value")
case elementTypeInt64:
d.FieldS64("value")
default:
d.FieldRawLen("value", d.BitsLeft())
}
})
}
})
d.FieldU8("terminator", d.ValidateU(0))
})
}
func decodeBSON(d *decode.D, in interface{}) interface{} {
d.Endian = decode.LittleEndian
decodeBSONDocument(d)
return nil
}

18
format/bson/bson.jq Normal file
View File

@ -0,0 +1,18 @@
def bson_torepr:
def _torepr:
( if .type == null or .type == "array" then
( .value.elements
| map(_torepr)
)
elif .type == "document" then
( .value.elements
| map({key: .name, value: _torepr})
| from_entries
)
elif .type == "boolean" then .value != 0
else .value
end
);
( {type: "document", value: .}
| _torepr
);

BIN
format/bson/testdata/test.bson vendored Normal file

Binary file not shown.

78
format/bson/testdata/test.fqtest vendored Normal file
View File

@ -0,0 +1,78 @@
# https://github.com/dwight/bsontools
# echo '{array: [1,2,3], object: {key: "value"}, number: 123, string: "abc", true: true, false: false, null: null}' | fromjson test.bson
$ fq -d bson verbose /test.bson
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: /test.bson (bson) 0x0-0x72.7 (115)
0x00|73 00 00 00 |s... | size: 115 0x0-0x3.7 (4)
| | | elements[0:7]: 0x4-0x71.7 (110)
| | | [0]{}: element 0x4-0x24.7 (33)
0x00| 04 | . | type: "array" (4) (Array) 0x4-0x4.7 (1)
0x00| 61 72 72 61 79 00 | array. | name: "array" 0x5-0xa.7 (6)
| | | value{}: 0xb-0x24.7 (26)
0x00| 1a 00 00 00 | .... | size: 26 0xb-0xe.7 (4)
| | | elements[0:3]: 0xf-0x23.7 (21)
| | | [0]{}: element 0xf-0x15.7 (7)
0x00| 10| .| type: "int32" (16) (32-bit integer) 0xf-0xf.7 (1)
0x10|30 00 |0. | name: "0" 0x10-0x11.7 (2)
0x10| 01 00 00 00 | .... | value: 1 0x12-0x15.7 (4)
| | | [1]{}: element 0x16-0x1c.7 (7)
0x10| 10 | . | type: "int32" (16) (32-bit integer) 0x16-0x16.7 (1)
0x10| 31 00 | 1. | name: "1" 0x17-0x18.7 (2)
0x10| 02 00 00 00 | .... | value: 2 0x19-0x1c.7 (4)
| | | [2]{}: element 0x1d-0x23.7 (7)
0x10| 10 | . | type: "int32" (16) (32-bit integer) 0x1d-0x1d.7 (1)
0x10| 32 00| 2.| name: "2" 0x1e-0x1f.7 (2)
0x20|03 00 00 00 |.... | value: 3 0x20-0x23.7 (4)
0x20| 00 | . | terminator: 0 (valid) 0x24-0x24.7 (1)
| | | [1]{}: element 0x25-0x40.7 (28)
0x20| 03 | . | type: "document" (3) (Embedded document) 0x25-0x25.7 (1)
0x20| 6f 62 6a 65 63 74 00 | object. | name: "object" 0x26-0x2c.7 (7)
| | | value{}: 0x2d-0x40.7 (20)
0x20| 14 00 00| ...| size: 20 0x2d-0x30.7 (4)
0x30|00 |. |
| | | elements[0:1]: 0x31-0x3f.7 (15)
| | | [0]{}: element 0x31-0x3f.7 (15)
0x30| 02 | . | type: "string" (2) (UTF-8 string) 0x31-0x31.7 (1)
0x30| 6b 65 79 00 | key. | name: "key" 0x32-0x35.7 (4)
0x30| 06 00 00 00 | .... | length: 6 0x36-0x39.7 (4)
0x30| 76 61 6c 75 65 00| value.| value: "value" 0x3a-0x3f.7 (6)
0x40|00 |. | terminator: 0 (valid) 0x40-0x40.7 (1)
| | | [2]{}: element 0x41-0x4c.7 (12)
0x40| 10 | . | type: "int32" (16) (32-bit integer) 0x41-0x41.7 (1)
0x40| 6e 75 6d 62 65 72 00 | number. | name: "number" 0x42-0x48.7 (7)
0x40| 7b 00 00 00 | {... | value: 123 0x49-0x4c.7 (4)
| | | [3]{}: element 0x4d-0x5c.7 (16)
0x40| 02 | . | type: "string" (2) (UTF-8 string) 0x4d-0x4d.7 (1)
0x40| 73 74| st| name: "string" 0x4e-0x54.7 (7)
0x50|72 69 6e 67 00 |ring. |
0x50| 04 00 00 00 | .... | length: 4 0x55-0x58.7 (4)
0x50| 61 62 63 00 | abc. | value: "abc" 0x59-0x5c.7 (4)
| | | [4]{}: element 0x5d-0x63.7 (7)
0x50| 08 | . | type: "boolean" (8) (Boolean) 0x5d-0x5d.7 (1)
0x50| 74 72| tr| name: "true" 0x5e-0x62.7 (5)
0x60|75 65 00 |ue. |
0x60| 01 | . | value: 1 0x63-0x63.7 (1)
| | | [5]{}: element 0x64-0x6b.7 (8)
0x60| 08 | . | type: "boolean" (8) (Boolean) 0x64-0x64.7 (1)
0x60| 66 61 6c 73 65 00 | false. | name: "false" 0x65-0x6a.7 (6)
0x60| 00 | . | value: 0 0x6b-0x6b.7 (1)
| | | [6]{}: element 0x6c-0x71.7 (6)
0x60| 0a | . | type: "null" (10) (Null value) 0x6c-0x6c.7 (1)
0x60| 6e 75 6c| nul| name: "null" 0x6d-0x71.7 (5)
0x70|6c 00 |l. |
0x70| 00| | .| | terminator: 0 (valid) 0x72-0x72.7 (1)
$ fq -d bson bson_torepr /test.bson
{
"array": [
1,
2,
3
],
"false": false,
"null": null,
"number": 123,
"object": {
"key": "value"
},
"string": "abc",
"true": true
}

View File

@ -12,6 +12,7 @@ const (
RAW = "raw"
JSON = "json"
BSON = "bson"
DNS = "dns"
DNS_TCP = "dns_tcp"

View File

@ -67,6 +67,7 @@ avc_pps H.264/AVC Picture Parameter Set
avc_sei H.264/AVC Supplemental Enhancement Information
avc_sps H.264/AVC Sequence Parameter Set
bsd_loopback_frame BSD loopback frame
bson Binary JSON
bzip2 bzip2 compression
dns DNS packet
dns_tcp DNS packet (TCP)