Crate yara_x_proto_yaml

Source
Expand description

Serializes a Protocol Buffer (protobuf) message to YAML.

This crates 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 "yaml.proto";

message MyMessage {
  optional int32 some_field = 1 [(yaml.field).fmt = "x"];
}

The first think to note is the import "yaml.proto" statement before the message definition. The yaml.proto file defines the existing YAML formatting options, so you must include it in your own .proto file in order to be able to use the such options.

The [(yaml.field).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 withe flags set. ENUM_TYPE_NAME must be the name of enum where each value represents a flag.

§Examples

Protobuf definition:

import "yaml.proto";

message MyMessage {
  optional int32 some_field = 1 [(yaml.field).fmt = "x"];
  optional int64 some_timestamp = 2 [(yaml.field).fmt = "t"];
  optional int32 some_flag = 3 [(yaml.field).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 | BAZ

Modules§

test
Generated file from test.proto
yaml
Generated file from yaml.proto

Structs§

Serializer
Serializes a protobuf to YAML format.