mirror of
https://github.com/wader/fq.git
synced 2024-12-21 04:11:55 +03:00
b08ef00dd1
Replaces []Format with a Group type. A bit more type safe. Breaking change for RegisterFormat, now takes a first argument that is a "single" format group. Lots of naming cleanup. This is also preparation for decode group argument which will enable doing intresting probing, ex a format decoder could know it's decode as part of probe group (html could be probed possibly), or have "arg probe" group for decoder who inspect args to know if they should probe (-d /path/to/schema etc) to enable nice CLI-ergonomics.
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package protobuf
|
|
|
|
// TODO: move? make collection on known protobuf messages?
|
|
|
|
import (
|
|
"github.com/wader/fq/format"
|
|
"github.com/wader/fq/pkg/decode"
|
|
"github.com/wader/fq/pkg/interp"
|
|
"github.com/wader/fq/pkg/scalar"
|
|
)
|
|
|
|
var widevineProtoBufGroup decode.Group
|
|
|
|
func init() {
|
|
interp.RegisterFormat(
|
|
format.ProtobufWidevine,
|
|
&decode.Format{
|
|
Description: "Widevine protobuf",
|
|
DecodeFn: widevineDecode,
|
|
Dependencies: []decode.Dependency{
|
|
{Groups: []*decode.Group{format.Protobuf}, Out: &widevineProtoBufGroup},
|
|
},
|
|
})
|
|
}
|
|
|
|
func widevineDecode(d *decode.D) any {
|
|
widewinePb := format.ProtoBufMessage{
|
|
1: {Type: format.ProtoBufTypeEnum, Name: "algorithm", Enums: scalar.UintMapSymStr{
|
|
0: "unencrypted",
|
|
1: "aesctr",
|
|
}},
|
|
2: {Type: format.ProtoBufTypeBytes, Name: "key_id"},
|
|
3: {Type: format.ProtoBufTypeString, Name: "provider"},
|
|
4: {Type: format.ProtoBufTypeBytes, Name: "content_id"},
|
|
6: {Type: format.ProtoBufTypeString, Name: "policy"},
|
|
7: {Type: format.ProtoBufTypeUInt32, Name: "crypto_period_index"},
|
|
8: {Type: format.ProtoBufTypeBytes, Name: "grouped_license"},
|
|
9: {Type: format.ProtoBufTypeUInt32, Name: "protection_scheme", Enums: scalar.UintMapSymStr{
|
|
1667591779: "cenc",
|
|
1667392305: "cbc1",
|
|
1667591795: "cens",
|
|
1667392371: "cbcs",
|
|
}},
|
|
}
|
|
|
|
d.Format(&widevineProtoBufGroup, format.ProtoBufIn{Message: widewinePb})
|
|
|
|
return nil
|
|
}
|