Class: Protobug::Field::MessageField
Constant Summary
PACKABLE_WIRE_TYPES
Instance Attribute Summary collapse
#adder, #cardinality, #clearer, #haser, #ivar, #json_name, #name, #number, #oneof, #setter
Instance Method Summary
collapse
-
#binary_decode_one(io, message, registry, wire_type) ⇒ Object
-
#binary_encode_one(value, outbuf) ⇒ Object
-
#default ⇒ Object
-
#initialize(number, name, cardinality:, message_type:, json_name: name, oneof: nil, proto3_optional: cardinality == :optional) ⇒ MessageField
constructor
A new instance of MessageField.
-
#json_decode_one(value, ignore_unknown_fields, registry) ⇒ Object
-
#json_encode_one(value, print_unknown_fields:) ⇒ Object
-
#type_lookup(registry) ⇒ Object
-
#wire_type ⇒ Object
#adder_method_definition, #binary_decode, #binary_encode, #json_decode, #json_encode, #json_key_encode, #method_definitions, #optional?, #packed?, #pretty_print, #proto3_optional?, #repeated?, #to_text, #validate!
Constructor Details
#initialize(number, name, cardinality:, message_type:, json_name: name, oneof: nil, proto3_optional: cardinality == :optional) ⇒ MessageField
Returns a new instance of MessageField.
230
231
232
233
234
235
|
# File 'lib/protobug/field.rb', line 230
def initialize(number, name, cardinality:, message_type:, json_name: name, oneof: nil,
proto3_optional: cardinality == :optional)
super(number, name, json_name: json_name, cardinality: cardinality, oneof: oneof,
proto3_optional: proto3_optional)
@message_type = message_type
end
|
Instance Attribute Details
#message_type ⇒ Object
Returns the value of attribute message_type.
228
229
230
|
# File 'lib/protobug/field.rb', line 228
def message_type
@message_type
end
|
Instance Method Details
#binary_decode_one(io, message, registry, wire_type) ⇒ Object
241
242
243
244
245
246
|
# File 'lib/protobug/field.rb', line 241
def binary_decode_one(io, message, registry, wire_type)
value = BinaryEncoding.read_field_value(io, wire_type)
kwargs = {}
kwargs[:object] = message.send(name) if !repeated? && message.send(haser)
type_lookup(registry).decode(StringIO.new(value), registry: registry, **kwargs)
end
|
#binary_encode_one(value, outbuf) ⇒ Object
237
238
239
|
# File 'lib/protobug/field.rb', line 237
def binary_encode_one(value, outbuf)
BinaryEncoding.encode_length value.class.encode(value), outbuf
end
|
#default ⇒ Object
261
262
263
264
265
266
|
# File 'lib/protobug/field.rb', line 261
def default
return [] if repeated?
nil
end
|
#json_decode_one(value, ignore_unknown_fields, registry) ⇒ Object
248
249
250
251
|
# File 'lib/protobug/field.rb', line 248
def json_decode_one(value, ignore_unknown_fields, registry)
klass = type_lookup(registry)
klass.decode_json_hash(value, registry: registry, ignore_unknown_fields: ignore_unknown_fields)
end
|
#json_encode_one(value, print_unknown_fields:) ⇒ Object
257
258
259
|
# File 'lib/protobug/field.rb', line 257
def json_encode_one(value, print_unknown_fields:)
value.as_json(print_unknown_fields: print_unknown_fields)
end
|
#type_lookup(registry) ⇒ Object
253
254
255
|
# File 'lib/protobug/field.rb', line 253
def type_lookup(registry)
registry.fetch(message_type)
end
|
#wire_type ⇒ Object
268
269
270
|
# File 'lib/protobug/field.rb', line 268
def wire_type
2
end
|