Class: Protobug::Field::BytesField
Instance Attribute Summary
#adder, #cardinality, #clearer, #haser, #ivar, #json_name, #name, #number, #oneof, #setter
Class Method Summary
collapse
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:, json_name: name, oneof: nil, proto3_optional: cardinality == :optional) ⇒ BytesField
constructor
A new instance of BytesField.
-
#json_decode_one(value, _ignore_unknown_fields, _registry) ⇒ Object
-
#json_encode_one(value, print_unknown_fields:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#wire_type ⇒ Object
#binary_decode, #binary_encode, #define_adder, #json_decode, #json_encode, #json_key_encode, #optional?, #packed?, #pretty_print, #proto3_optional?, #repeated?, #to_text, #validate!
Constructor Details
#initialize(number, name, cardinality:, json_name: name, oneof: nil, proto3_optional: cardinality == :optional) ⇒ BytesField
Returns a new instance of BytesField.
317
318
319
320
321
|
# File 'lib/protobug/field.rb', line 317
def initialize(number, name, cardinality:, json_name: name, oneof: nil,
proto3_optional: cardinality == :optional)
super(number, name, json_name: json_name, cardinality: cardinality, oneof: oneof,
proto3_optional: proto3_optional)
end
|
Class Method Details
.type ⇒ Object
315
|
# File 'lib/protobug/field.rb', line 315
def self.type = :bytes
|
Instance Method Details
#binary_decode_one(io, _message, _registry, wire_type) ⇒ Object
327
328
329
|
# File 'lib/protobug/field.rb', line 327
def binary_decode_one(io, _message, _registry, wire_type)
BinaryEncoding.read_field_value(io, wire_type)
end
|
#binary_encode_one(value, outbuf) ⇒ Object
323
324
325
|
# File 'lib/protobug/field.rb', line 323
def binary_encode_one(value, outbuf)
BinaryEncoding.encode_length value.b, outbuf
end
|
#default ⇒ Object
349
350
351
352
353
|
# File 'lib/protobug/field.rb', line 349
def default
return [] if repeated?
"".b
end
|
#json_decode_one(value, _ignore_unknown_fields, _registry) ⇒ Object
331
332
333
334
335
336
337
338
339
340
341
342
343
|
# File 'lib/protobug/field.rb', line 331
def json_decode_one(value, _ignore_unknown_fields, _registry)
return UNSET if value.nil?
value.tr!("-_", "+/")
begin
value = value.unpack1("m").force_encoding(Encoding::BINARY)
rescue ArgumentError => e
raise DecodeError, "Invalid URL-encoded base64 #{value.inspect} for #{inspect}: #{e}"
end
value
end
|
#json_encode_one(value, print_unknown_fields:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
345
346
347
|
# File 'lib/protobug/field.rb', line 345
def json_encode_one(value, print_unknown_fields:) [value].pack("m0")
end
|
#wire_type ⇒ Object
355
|
# File 'lib/protobug/field.rb', line 355
def wire_type = 2
|