Expand description
Serializes a Protocol Buffer (protobuf) message to YAML.
This crate serializes arbitrary protobuf messages to YAML format, producing
YAML that is user-friendly, customizable and colorful. Some aspects of the
produced YAML can be customized by using specific options in your .proto
files. Let’s use the following protobuf message definition as an example:
import "yara.proto";
message MyMessage {
optional int32 some_field = 1 [(yara.field_options).fmt = "x"];
}The first think to note is the import "yara.proto" statement before the
message definition. The yara.proto file defines the existing formatting
options, so you must include it in your own .proto file in order to be able
to use the such options.
The [(yara.field_options).fmt = "x"] modifier, when applied to some field,
indicates that values of that field must be rendered in hexadecimal form. The
list of supported format modifiers is:
-
x: Serializes the value as a hexadecimal number. Only valid for integer fields. -
t: Serializes the field as a timestamp. The value itself is rendered as a decimal integer, but a comment is added with the timestamp in a human-friendly format. Only valid for integer fields. -
flag:ENUM_TYPE_NAME: Serializes the field as a set of flags. The value is rendered as a hexadecimal number, but a comment is added with the names of the flags that are enabled.ENUM_TYPE_NAMEmust be the name of enum where each value represents a flag.
§Examples
Protobuf definition:
import "yara.proto";
message MyMessage {
optional int32 some_field = 1 [(yara.field_options).fmt = "x"];
optional int64 some_timestamp = 2 [(yara.field_options).fmt = "t"];
optional int32 some_flag = 3 [(yara.field_options).fmt = "flags:MyFlags"];
}
enum MyFlags {
FOO = 0x01;
BAR = 0x02;
BAZ = 0x04;
}YAML output:
some_field: 0x8b1;
some_timestamp: 999999999 # 2001-09-09 01:46:39 UTC
some_flag: 0x06 # BAR | BAZModules§
Structs§
- Serializer
- Serializes a protobuf to YAML format.