protobuf_descriptor

Gem Version Build Status MIT license

Description

Protobuf_descriptor provides helper methods to make working with Google Protocol Buffer descriptors easier, go figure.. It handles type resolution, and computing type names (both within protocol buffers and in the generated output).

Examples

Given the descriptor.desc generated by the protocol buffer compiler, you can introspect the various data types. This example references the descriptor that would be generated by compiling single_file.proto

require 'protobuf_descriptor'
descriptor = ProtobufDescriptor.load("descriptor.desc")

# Load a single file by its filename/basename
file_descriptor = descriptor[:single_file]

# Grab a handle to an enum, or a message
file_descriptor.messages[:FieldOptions]
file_descriptor.enums[:UnnestedEnum]

# Also allows resolving types by their fully qualified name:
descriptor.resolve_type(".porkbuns.UnnestedEnum") # note the leading "."
# or even doing so relative to another enum
descriptor.resolve_type("CType", ".porkbuns.FieldOptions")

For even more gory details, please peruse the actual documentation.

Requirements

I've only tested this on Ruby 1.9.3+. If it works for you on an older version of Ruby, let me know. You most likely want to install the Google Protocol Buffer library.

Install

$ gem install protobuf_descriptor

Copyright (c) 2014 Hsiu-Fan Wang

See LICENSE.txt for details.