Class: Protobug::Field::BoolField
Instance Attribute Summary
#adder, #cardinality, #clearer, #haser, #ivar, #json_name, #name, #number, #oneof, #setter
Instance Method Summary
collapse
Methods inherited from UInt64Field
#bit_length, #encoding, #signed, #wire_type
#json_encode_one
#binary_decode, #binary_encode, #define_adder, #initialize, #json_decode, #json_encode, #json_key_encode, #optional?, #packed?, #pretty_print, #proto3_optional?, #repeated?, #to_text
Instance Method Details
#binary_decode_one ⇒ Object
571
572
573
|
# File 'lib/protobug/field.rb', line 571
def binary_decode_one(*)
super != 0
end
|
#binary_encode_one(value, outbuf) ⇒ Object
575
576
577
|
# File 'lib/protobug/field.rb', line 575
def binary_encode_one(value, outbuf)
super(value ? 1 : 0, outbuf)
end
|
#default ⇒ Object
600
601
602
603
604
|
# File 'lib/protobug/field.rb', line 600
def default
return [] if repeated?
false
end
|
#json_decode_one(value, _ignore_unknown_fields, _registry) ⇒ Object
579
580
581
582
583
584
585
586
587
588
589
590
591
592
|
# File 'lib/protobug/field.rb', line 579
def json_decode_one(value, _ignore_unknown_fields, _registry)
case value
when TrueClass, FalseClass
value
when "true"
true
when "false"
false
when NilClass
UNSET
else
raise DecodeError, "expected boolean, got #{value.inspect}"
end
end
|
#validate!(value, message) ⇒ Object
594
595
596
597
598
|
# File 'lib/protobug/field.rb', line 594
def validate!(value, message)
raise "expected boolean, got #{value.inspect}" unless [true, false].include?(value)
super(value ? 1 : 0, message)
end
|