module Ruby::Proto

Constants

VERSION

Public Class Methods

testForRequire() click to toggle source
# File lib/ruby/proto.rb, line 6
def testForRequire()
  true
end
toProtoData(_hash, _proc) click to toggle source
# File lib/ruby/proto.rb, line 10
def toProtoData(_hash, _proc)
  protoData(_proc, _hash)
  _proc
end

Private Class Methods

convert_basic_field_value(_field, _value) click to toggle source
# File lib/ruby/proto.rb, line 20
def convert_basic_field_value(_field, _value)
  return _value if _value.is_a?(Array)
  return _value if _value.is_a?(Hash)
  index = getBasicField.index(_field.type.to_s)
  unless index.nil?
    _value = case index
               when 0..1
                 _value.to_i
               when 2
                 _value.to_s
               when 3
                 _value == 1
               else
                 _value
             end
  end
  _value
end
getBasicField() click to toggle source
# File lib/ruby/proto.rb, line 16
def getBasicField
  @arrBasicField ||= ["int32", "uint32", "string", "bool"]
end
protoData(_proc, _hash) click to toggle source
# File lib/ruby/proto.rb, line 39
def protoData(_proc, _hash)
  _proc.fields.each do |_tag, _field|
    ret = _hash.fetch(_field.name.to_s, nil)
    next if ret.nil?
    if ret.is_a?(Hash)
      subProc = _field.type.new
      protoData(subProc, ret)
      ret = subProc
    elsif ret.is_a?(Array)
      arr = []
      ret.each do |_hash|
        subProc = nil
        if (getBasicField.include?(_field.type.to_s))
          subProc = convert_basic_field_value(_field, _hash)
        else
          subProc = _field.type.new
          protoData(subProc, _hash)
        end
        arr.push subProc
      end
      ret = arr
    end
    _proc.send(_field.name.to_s + "=", ret)
  end
end