here.platform.schema.protobuf_parser module

here.platform.schema.protobuf_parser module

Protobuf Parser module

class here.platform.schema.protobuf_parser.ProtobufParser(schema_pkg_file: str | Path | BytesIO)
Bases: Parser

A class for parsing Protobuf data of a catalog layer partition.

static access_field(message: Message, path: str | None)
Return the data at the given path.

Parameters:

  • message – a decoded Protobuf message

  • path – path to the field, concatenate field names with ‘.’ to select nested fields

Returns:
the field referenced by the path parameter. This is either a Message in case the field contains a nested Protobuf structure, a simple value for integers, strings and other native types, or a container that can be iterated for a repeated field in Protobuf.

get_message_class(fully_qualified_message_name: str) Any

Get Message class by fully qualified message name.

Parameters:
fully_qualified_message_name – fully qualified message name of the proto class

Returns:
message class

get_partition_class()

Returns partition class.

Returns:
Partition class

parse_message(message: bytes) Message

Parse a Protobuf message and returns the corresponding partition class instance.

Parameters:
message – message received as blob

Returns:
parsed Protobuf message

parse_message_by_class(message: bytes, fully_qualified_message_name: str) Message | Any

Parse a Protobuf message by proto class and returns the corresponding partition class instance.

Parameters:

  • message – message received as blob

  • fully_qualified_message_name – fully qualified message name of the proto class

Returns:
parsed Protobuf message

primary_fields(all_fields: bool = False) List[FieldDescriptor]

Return the field descriptors of the root partition class.

Parameters:
all_fields – Return all field descriptors of the root partition class that are labeled ‘repeated’ if all is set to False. Return all the field descriptors otherwise.

Returns:
List of field descriptors

serialize_bytes(data: Message | dict) bytes

Parse a Protobuf message and returns the bytes.

Parameters:
data – Protobuf message

Returns:
bytes