Module: CBOR
- Defined in:
- lib/cbor-pure.rb,
lib/cbor-pretty.rb
Defined Under Namespace
Modules: CoreExt, Streaming
Classes: Break, Buffer, OutOfBytesError, Sequence, Simple, Tagged, Transform, Transform_j, Transform_jr
Constant Summary
collapse
- BREAK =
Break.new.freeze
- TAG_BIGNUM_BASE =
2
- SIMPLE_VALUES =
{20 => false, 21 => true, 22 => nil}
Class Method Summary
collapse
Class Method Details
.encode(d) ⇒ Object
121
122
123
|
# File 'lib/cbor-pure.rb', line 121
def self.encode(d)
Buffer.new.add(d).buffer
end
|
.encode_seq(ds) ⇒ Object
124
125
126
127
128
129
130
|
# File 'lib/cbor-pure.rb', line 124
def self.encode_seq(ds)
out = Buffer.new
ds.each do |d|
out.add(d)
end
out.buffer
end
|
.pretty(s, indent = 0, max_target = 40, warnings: nil) ⇒ Object
26
27
28
29
30
31
|
# File 'lib/cbor-pretty.rb', line 26
def self.pretty(s, indent = 0, max_target = 40, warnings: nil)
b = Buffer.new(s)
warnings ||= s.cbor_warnings
b.warnings = warnings if warnings
b.pretty_item_final(indent, max_target)
end
|
.pretty_seq(s, indent = 0, max_target = 40, warnings: nil) ⇒ Object
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/cbor-pretty.rb', line 33
def self.pretty_seq(s, indent = 0, max_target = 40, warnings: nil)
b = Buffer.new(s)
warnings ||= s.cbor_warnings
b.warnings = warnings if warnings
res = '' while !b.empty?
res << b.pretty_item_final(indent, max_target, true)
end
res
end
|
.Simple(v) ⇒ Object
101
102
103
104
105
106
107
108
109
|
# File 'lib/cbor-pure.rb', line 101
def self.Simple(v)
SIMPLE_VALUES.fetch(v) {
if Integer === v && (v >= 0 && v < 24 || v >= 32 && v < 256)
CBOR::Simple.new(v)
else
raise ArgumentError, "No simple value for #{v.inspect}"
end
}
end
|
.Tagged(t, v) ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/cbor-pure.rb', line 79
def self.Tagged(t, v)
if Integer === t && t >= 0 && t < (1 << 64)
CBOR::Tagged.new(t, v)
else
raise ArgumentError, "Not a tag number: #{t.inspect}"
end
end
|