module

Proto::Generator::NamingPolicy

NamingPolicy converts proto identifiers to Crystal identifiers.

Rules (matching protoc-gen-go / protoc-gen-python conventions adapted for Crystal):

  • package "foo.bar_baz" → module Foo::BarBaz
  • message "HelloRequest" → class HelloRequest (already CamelCase)
  • enum "Status" → enum Status
  • enum value "STATUS_OK" → STATUS_OK (kept as-is, Crystal enums use SCREAMING_SNAKE)
  • field "my_field" → property my_field (snake_case, kept)

Class methods

camelize(s : String) : String

snake_case → CamelCase

Source
fq_type_to_crystal(fq : String) : String

proto fully-qualified type ".foo.bar.Baz.Inner" → "Foo::Bar::Baz::Inner"

Source
message_name(name : String) : String

Convert a proto message/enum name (already CamelCase) to a Crystal class/enum name. Nested names are NOT joined here — the caller passes the leaf name.

Source
package_to_module(package : String) : String | Nil

Convert a proto package string to a Crystal module path. "foo.bar_baz" → "Foo::BarBaz" "" → nil

Source