class Google::Protobuf::Internal::NestingBuilder

Public Class Methods

new(msg_names, enum_names) click to toggle source
# File lib/google/protobuf.rb, line 75
def initialize(msg_names, enum_names)
  @to_pos = {nil=>nil}
  @msg_children = Hash.new { |hash, key| hash[key] = [] }
  @enum_children = Hash.new { |hash, key| hash[key] = [] }

  msg_names.each_with_index { |name, idx| @to_pos[name] = idx }
  enum_names.each_with_index { |name, idx| @to_pos[name] = idx }

  msg_names.each { |name| @msg_children[parent(name)] << name }
  enum_names.each { |name| @enum_children[parent(name)] << name }
end

Public Instance Methods

build(package) click to toggle source
# File lib/google/protobuf.rb, line 87
def build(package)
  return build_msg(package)
end

Private Instance Methods

build_msg(msg) click to toggle source
# File lib/google/protobuf.rb, line 92
def build_msg(msg)
  return {
    :pos => @to_pos[msg],
    :msgs => @msg_children[msg].map { |child| build_msg(child) },
    :enums => @enum_children[msg].map { |child| @to_pos[child] },
  }
end
parent(name) click to toggle source
# File lib/google/protobuf.rb, line 101
def parent(name)
  idx = name.rindex(?.)
  if idx
    return name.slice(0, idx)
  else
    return nil
  end
end