Class: CBOR_DIAG::App_bytes

Inherits:
Object show all
Defined in:
lib/cbor-diagnostic-app/bytes.rb

Class Method Summary collapse

Class Method Details

.decode(_, s) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/cbor-diagnostic-app/bytes.rb', line 4

def self.decode(_, s)
  a = if CBOR::Sequence === s
        s.elements
      else
        [s]
      end
  a.map { |el|
    unless String === el
      raise ArgumentError.new("cbor-diagnostic: bytes<<#{a.cbor_diagnostic[1...-1]}>>: #{el.cbor_diagnostic} not a string: Argument Error")
    end
    el.b
  }.join.b # .b needed so empty array becomes byte string, too
end