Module: Protobuf::Field
- Defined in:
- lib/protobuf/field.rb,
lib/protobuf/field/base_field.rb,
lib/protobuf/field/bool_field.rb,
lib/protobuf/field/enum_field.rb,
lib/protobuf/field/field_hash.rb,
lib/protobuf/field/bytes_field.rb,
lib/protobuf/field/field_array.rb,
lib/protobuf/field/float_field.rb,
lib/protobuf/field/int32_field.rb,
lib/protobuf/field/int64_field.rb,
lib/protobuf/field/double_field.rb,
lib/protobuf/field/sint32_field.rb,
lib/protobuf/field/sint64_field.rb,
lib/protobuf/field/string_field.rb,
lib/protobuf/field/uint32_field.rb,
lib/protobuf/field/uint64_field.rb,
lib/protobuf/field/varint_field.rb,
lib/protobuf/field/fixed32_field.rb,
lib/protobuf/field/fixed64_field.rb,
lib/protobuf/field/integer_field.rb,
lib/protobuf/field/message_field.rb,
lib/protobuf/field/sfixed32_field.rb,
lib/protobuf/field/sfixed64_field.rb,
lib/protobuf/field/signed_integer_field.rb,
lib/protobuf/field/base_field_object_definitions.rb
Defined Under Namespace
Modules: BaseFieldObjectDefinitions Classes: BaseField, BoolField, BytesField, DoubleField, EnumField, FieldArray, FieldHash, Fixed32Field, Fixed64Field, FloatField, Int32Field, Int64Field, IntegerField, MessageField, Sfixed32Field, Sfixed64Field, SignedIntegerField, Sint32Field, Sint64Field, StringField, Uint32Field, Uint64Field, VarintField
Constant Summary collapse
- PRIMITIVE_FIELD_MAP =
{ :double => ::Protobuf::Field::DoubleField, :float => ::Protobuf::Field::FloatField, :int32 => ::Protobuf::Field::Int32Field, :int64 => ::Protobuf::Field::Int64Field, :uint32 => ::Protobuf::Field::Uint32Field, :uint64 => ::Protobuf::Field::Uint64Field, :sint32 => ::Protobuf::Field::Sint32Field, :sint64 => ::Protobuf::Field::Sint64Field, :fixed32 => ::Protobuf::Field::Fixed32Field, :fixed64 => ::Protobuf::Field::Fixed64Field, :sfixed32 => ::Protobuf::Field::Sfixed32Field, :sfixed64 => ::Protobuf::Field::Sfixed64Field, :string => ::Protobuf::Field::StringField, :bytes => ::Protobuf::Field::BytesField, :bool => ::Protobuf::Field::BoolField, }.freeze
Class Method Summary collapse
- .build(message_class, rule, type, name, tag, simple_name, options = {}) ⇒ Object
-
.field_class(type) ⇒ Object
Returns the field class for primitives, EnumField for types that inherit from Protobuf::Enum, and MessageField for types that inherit from Protobuf::Message.
-
.field_type(type) ⇒ Object
Returns the mapped type for primitives, otherwise the given type is returned.
Class Method Details
.build(message_class, rule, type, name, tag, simple_name, options = {}) ⇒ Object
44 45 46 |
# File 'lib/protobuf/field.rb', line 44 def self.build(, rule, type, name, tag, simple_name, = {}) field_class(type).new(, rule, field_type(type), name, tag, simple_name, ) end |
.field_class(type) ⇒ Object
Returns the field class for primitives, EnumField for types that inherit from Protobuf::Enum, and MessageField for types that inherit from Protobuf::Message.
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/protobuf/field.rb', line 52 def self.field_class(type) if PRIMITIVE_FIELD_MAP.key?(type) PRIMITIVE_FIELD_MAP[type] elsif type < ::Protobuf::Enum EnumField elsif type < ::Protobuf::Message MessageField elsif type < ::Protobuf::Field::BaseField type else fail ArgumentError, "Invalid field type #{type}" end end |
.field_type(type) ⇒ Object
Returns the mapped type for primitives, otherwise the given type is returned.
69 70 71 |
# File 'lib/protobuf/field.rb', line 69 def self.field_type(type) PRIMITIVE_FIELD_MAP.fetch(type) { type } end |