Class: CBOR::Box

Inherits:
Struct
  • Object
show all
Defined in:
lib/cbor-diag-support.rb

Direct Known Subclasses

Fbox, Ibox, Xbox

Constant Summary collapse

INTEGER_EI =
{
  "i" => [23, 0],
  "0" => [0xFF, 1],
  "1" => [0xFFFF, 2],
  "2" => [0xFFFFFFFF, 4],
  "3" => [0xFFFFFFFFFFFFFFFF, 8]
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



8
9
10
# File 'lib/cbor-diag-support.rb', line 8

def options
  @options
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



8
9
10
# File 'lib/cbor-diag-support.rb', line 8

def value
  @value
end

Class Method Details

.from_instance(n, options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cbor-diag-support.rb', line 15

def self.from_instance(n, options={})
  case n
  when Box
    n.class.new(n.value, n.options.merge(options))
  when ::Integer
    Ibox.new(n, options.dup)
  when ::Float
    Fbox.new(n, options.dup)
  when ::String, ::Array, ::Hash, ::CBOR::Tagged
    Xbox.new(n, options.dup)
  else
    raise ArgumentError, "cbor-diagnostic: can't box number from #{n.inspect}':\n"
  end
end

.make_head(ib, plusbytes, d) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cbor-diag-support.rb', line 37

def self.make_head(ib, plusbytes, d)
  case plusbytes
  when 0
    [ib + d].pack("C")
  when 1
    [ib + 24, d].pack("CC")
  when 2
    [ib + 25, d].pack("Cn")
  when 4
    [ib + 26, d].pack("CN")
  when 8
    [ib + 27, d].pack("CQ>")
  else
    raise ArgumentError, "cbor-diagnostic: #{plusbytes} plusbytes when encoding head\n"
  end
end

Instance Method Details

#cbor_diagnostic(opts = {}) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/cbor-diag-support.rb', line 57

def cbor_diagnostic(opts = {})
  ret = value.cbor_diagnostic(opts)
  if ei = options[:ei]
    ret << "_#{ei}"
  end
  ret
end

#inspectObject



12
13
14
# File 'lib/cbor-diag-support.rb', line 12

def inspect
  "#<CBOR::Box #{self.class} value=#{value.inspect}, options=#{options.inspect}>"
end

#to_cborObject



54
55
56
# File 'lib/cbor-diag-support.rb', line 54

def to_cbor
  CBOR.encode(value)
end

#to_sObject



9
10
11
# File 'lib/cbor-diag-support.rb', line 9

def to_s
  value.to_s
end