On this page:
prop: protobuf
Version: 5.2.1

1 Reflection

 (require (planet murphy/protobuf/reflection))
Generic functionality for protocol buffer data and types.

(struct type-info (name)
  name : symbol?
Common base of protocol buffer type information records.

(struct primitive-info type-info (type reader writer))
  type : type/c
  reader : (-> input-port? any/c)
  writer : (-> any/c output-port? any)
Information about a primitive protocol buffer type. The type indicates the wire type of the primitive as used by read-tag/type and write-tag/type.

The reader and writer are responsible for (de-)serialization of values of this type.

(struct enum-info type-info (integer->enum enum->integer))
  integer->enum : (-> exact-integer? any/c)
  enum->integer : (-> any/c exact-integer?)
Information about a user defined protocol buffer enumeration type.

The integer->enum and enum->integer conversions are responsible to make the Racket representation of the enumeration compatible with (de-)serialization using read-int* and write-int*.

The define-enum-type syntax can be used to synthesize conversion procedures between symbols and integers as well as an instance of this structure type.

prop:protobuf : struct-type-property?
(protobuf? v)  boolean?
  v : any/c
(protobuf-ref v [default])  any/c
  v : any/c
  default : any/c = ...
This property is used to attach a promise of a message-info structure to the structure type corresponding to a protocol buffer message type.

The procedure protobuf? checks for the presence of the property on a structure type or instance; protobuf-ref extracts the value of the property.

(struct message-info type-info (constructor fields required))
  constructor : (-> any/c)
  fields : (hash/c exact-nonnegative-integer? field?)
  required : (set/c exact-nonnegative-integer?)
Information about a user defined protocol buffer message type.

The constructor is used to obtain fresh instances of the structure type representing the message type which have all fields initialized to the default value (void) for missing fields.

The hash fields maps wire tags to field descriptors, the set required indicates which wire tags must be present in a valid message.

The define-message-type syntax can be used to synthesize a structure type and an instance of this descriptor type.

(struct field-info (type repeated? packed? accessor mutator))
  type : (or/c primitive-info? enum-info? struct-type?)
  repeated? : any/c
  packed? : any/c
  accessor : (->* (any/c) (any/c) any/c)
  mutator : (-> any/c any/c any)
Information about a field in a user defined protocol buffer message. The type of the field can contain primitive protocol buffer type information, enumeration type information or a record type with associated message type information.

Iff the field can be present any number of times, repeated? should be true; packed? may be true for repeated fields of non-length-delimited primitive types to specify a more efficient wire format.

The accessor and mutator are used to extract and modify the values of the field in instances of the message structure.

(struct message (extensions unknown)
  extensions : (hash/c exact-nonnegative-integer? any/c)
  unknown : bytes?
The common base of all protocol buffer message types. While regular fields of a message are stored in fields of message’s subtypes, known extensions are stored in the extensions hash under their field tags. Fields with unknown tags are copied verbatim to or from the unknown byte string.