1
1
mirror of https://github.com/wader/fq.git synced 2024-11-23 18:56:52 +03:00
fq/format/protobuf/protobuf_widevine.go
Mattias Wadman 2fc0a71a47 decode: Refactor scalar usage
Move scalar into own package.
Split scalar code into decode related scalar code (that reads etc) and
scalar code that just transform the scalar value.
Use a scalar.Mapper interface instead of just a function.
Make mappers, assert and validat impement the interface.
2021-12-02 17:39:26 +01:00

49 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/format/registry"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/scalar"
)
var widevineProtoBufFormat decode.Group
func init() {
registry.MustRegister(decode.Format{
Name: format.PROTOBUF_WIDEVINE,
Description: "Widevine protobuf",
DecodeFn: widevineDecode,
Dependencies: []decode.Dependency{
{Names: []string{format.PROTOBUF}, Group: &widevineProtoBufFormat},
},
})
}
func widevineDecode(d *decode.D, in interface{}) interface{} {
widewinePb := format.ProtoBufMessage{
1: {Type: format.ProtoBufTypeEnum, Name: "algorithm", Enums: scalar.UToSymStr{
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.UToSymStr{
1667591779: "cenc",
1667392305: "cbc1",
1667591795: "cens",
1667392371: "cbcs",
}},
}
d.Format(widevineProtoBufFormat, format.ProtoBufIn{Message: widewinePb})
return nil
}