On this page:
proto-string->symbol
register-types!
register-enum-type!
register-message-types!
type-ref
translate-types
translate-enum-type
translate-message-types
translate-extension
generate-racket

1 Programming Interface

 (require (planet murphy/protobuf/generator))
Functions to convert Protocol Buffer descriptors into Racket code.
This module relies on the ProtoC plug-in interfaces which are available as racket modules generated from protocol buffer definitions themselves.

(proto-string->symbol str [prefix])  symbol?
  str : string?
  prefix : any/c = #f
Reformats an identifier following protocol buffer definition conventions into a symbol, optionally adding a prefix.

The conversion proceeds as follows:
  • Camel case words are separated by - characters.

  • The entire string is converted to lower case.

  • Any occurrence of _ is replaced by -.

  • An is- prefix is replaced by a ? suffix.

  • The prefix, if present, is stringified and prepended to the identifier separated by :.

(register-types! types proto)  void?
  types : (hash/c string? (cons/c symbol? symbol?) #:immutable #f)
  proto : file-descriptor-proto?
Register all types defined in proto in the hash types that maps the fully qualified protocol buffer names to pairs of 'enum or 'struct and an identifier.

(register-enum-type! types proto)  void?
  types : (hash/c string? (cons/c symbol? symbol?) #:immutable #f)
  proto : enum-descriptor-proto?
Register the enumeration type described by proto in the hash types.

(register-message-types! types proto)  void?
  types : (hash/c string? (cons/c symbol? symbol?) #:immutable #f)
  proto : descriptor-proto?
Register the message type described by proto and all its nested types in the hash types.

(type-ref types package name)  (cons/c symbol? symbol?)
  types : (hash/c string? (cons/c symbol? symbol?))
  package : string?
  name : string?
Find the kind and identifier of a type in types specified by its protocol buffers package and name.

(translate-types types proto)  list?
  types : (hash/c string? (cons/c symbol? symbol?))
  proto : file-descriptor-proto?
Translate all types defined in proto into module level Racket code. Use types for lookup of type references.

(translate-enum-type types package proto)  any/c
  types : (hash/c string? (cons/c symbol? symbol?))
  package : (or/c string? #f)
  proto : enum-descriptor-proto?
Translate the enumeration type described by proto into module level Racket code. Use types for lookup of type references.

(translate-message-types types    
  package    
  proto)  list?
  types : (hash/c string? (cons/c symbol? symbol?))
  package : (or/c string? #f)
  proto : descriptor-proto?
Translate the message type described by proto and all its nested types into module level Racket code. Use types for lookup of type references.

(translate-extension types package proto)  any/c
  types : (hash/c string? (cons/c symbol? symbol?))
  package : (or/c string? #f)
  proto : field-descriptor-proto?
Translate the message type extension described by proto into module level Racket code. Use types for lookup of type references.

(generate-racket req)  code-generator-response?
  req : code-generator-request?
Process a code generation request and generate Racket code.