Class: Dcc::Type::Base64Binary
- Inherits:
-
Lutaml::Model::Type::Value
- Object
- Lutaml::Model::Type::Value
- Dcc::Type::Base64Binary
- Defined in:
- lib/dcc/type/base64_binary.rb
Overview
Base64-encoded binary data, used by dcc:dataBase64 in
dcc:byteDataType.
The wire format is base64 text (VGVzdAo=). We pass it through
unchanged on cast so that round-trip serialization is byte-identical.
Callers that need the decoded binary bytes call .decode.
Class Method Summary collapse
- .cast(value) ⇒ Object
-
.decode(value) ⇒ String
Convenience: decode the base64 string to binary bytes.
-
.encode(value) ⇒ String?
Convenience: encode binary bytes to base64 text.
- .serialize(value) ⇒ Object
Class Method Details
.cast(value) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/dcc/type/base64_binary.rb', line 15 def self.cast(value) return nil if value.nil? || value == "" unless value.is_a?(::String) raise Lutaml::Model::Type::InvalidValueError.new(value, "expected binary String") end value end |
.decode(value) ⇒ String
Convenience: decode the base64 string to binary bytes.
37 38 39 40 41 42 43 |
# File 'lib/dcc/type/base64_binary.rb', line 37 def self.decode(value) return "" unless value && !value.to_s.empty? ::Base64.strict_decode64(value.to_s).b rescue ::ArgumentError "" end |
.encode(value) ⇒ String?
Convenience: encode binary bytes to base64 text.
48 49 50 51 52 |
# File 'lib/dcc/type/base64_binary.rb', line 48 def self.encode(value) return nil if value.nil? ::Base64.strict_encode64(value) end |
.serialize(value) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/dcc/type/base64_binary.rb', line 24 def self.serialize(value) return nil if value.nil? unless value.is_a?(::String) raise Lutaml::Model::Type::InvalidValueError.new(value, "expected binary String") end value end |