On this page:
define-primitive-type
primitive:  int32
primitive:  int64
primitive:  uint32
primitive:  uint64
primitive:  sint32
primitive:  sint64
primitive:  fixed32
primitive:  fixed64
primitive:  sfixed32
primitive:  sfixed64
primitive:  bool
primitive:  float
primitive:  double
primitive:  bytes
primitive:  string
primitive:  uint*
primitive:  sint*
define-enum-type
define-message-type
define-message-extension
8.12

2 Syntax🔗ℹ

 (require (lib "protobuf/syntax")) package: protobuf
Racket syntax to represent protocol buffer definitions as used by code output from protoc-gen-racket.

syntax

(define-primitive-type name type
  reader writer)
 
  reader : (-> input-port? any/c)
  writer : (-> any/c output-port? any)
Binds primitive:name to an instance of primitive-info using the quoted type and the specified reader and writer.

This is an internal utility macro and should normally not be used since the set of primitive wire types for protocol buffers is not intended to be extended.

The primitive protocol buffer types.

procedure

(primitive:uint* max-size)  primitive-info?

  max-size : (or/c exact-positive-integer? #f)

procedure

(primitive:sint* max-size)  primitive-info?

  max-size : (or/c exact-positive-integer? #f)
Generators for variants of the primitive protocol buffer integer types that modify or lift the maximum encoded size restriction for these values.

The protoc-gen-racket code generator uses these types when it finds an (extend.protobuf.max_size) option on a field of type uint64 or sint64. The max-size will be the value of the option or #f in case the option is zero. Protocol buffer definitions using this extension must import "extend/protobuf/bigint.proto" from this library’s distribution.

Note that relaxing the size restriction is not compatible with other implementations of protocol buffers and lifting the restriction entirely may also be vulnerable to denial of service attacks.

syntax

(define-enum-type name
  ([alt tag] ...))
 
  tag : exact-nonnegative-integer?
Binds enum:name to an instance of enum-info and defines the enumeration conversion procedures integer->name and name->integer.

Each alt is a possible symbolic enumeration item corresponding to the numeric tag.

syntax

(define-message-type name
  ([label type field tag . default] ...))
 
label = required
  | optional
  | repeated
  | packed
 
  type : (or/c primitive-info? enum-info? struct-type?)
  tag : exact-nonnegative-integer?
Defines a structure type similar to the following code:
(struct name message
  ([field #:auto] ...)
  #:transparent #:mutable
  #:auto-value (void)
  #:property prop:protobuf (delay (message-info 'name ...)))

In addition to the unary constructor procedure name that is of limited use, a variadic constructor name* is created. This constructor accepts an optional keyword argument for every declared field of the message.

The accessors generated for each field accept an additional optional argument to specify a default value. If the accessor is applied to an instance of the message type in which the field is set to (void), the default value is applied in case it is a thunk or is returned otherwise.

If no explicit default value is specified for a missing field, the accessors behave as follows:
  • The accessor for a required field raises an exn:fail:user error.

  • The accessor for an optional field runs a default thunk with default.

  • The accessor for a repeated (or packed repeated) field returns an empty list.

syntax

(define-message-extension name
  [label type field tag . default])
 
label = required
  | optional
  | repeated
  | packed
 
  type : (or/c primitive-info? enum-info? struct-type?)
  tag : exact-nonnegative-integer?
Registers an extension field for the existing message type called name. The field declaration syntax is identical to that of a single field in define-message-type.