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

Class Method Summary collapse

Class Method Details

.decode(s) ⇒ Object



87
88
89
# File 'lib/cbor-pure.rb', line 87

def self.decode(s)
  Buffer.new(s).decode_item_final
end

.decode_seq(s) ⇒ Object



93
94
95
# File 'lib/cbor-pure.rb', line 93

def self.decode_seq(s)
  Buffer.new(s).decode_items
end

.decode_with_rest(s) ⇒ Object



90
91
92
# File 'lib/cbor-pure.rb', line 90

def self.decode_with_rest(s)
  Buffer.new(s).decode_item_with_rest
end

.encode(d) ⇒ Object



77
78
79
# File 'lib/cbor-pure.rb', line 77

def self.encode(d)
  Buffer.new.add(d).buffer
end

.encode_seq(ds) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/cbor-pure.rb', line 80

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) ⇒ Object



20
21
22
# File 'lib/cbor-pretty.rb', line 20

def self.pretty(s, indent = 0, max_target = 40)
  Buffer.new(s).pretty_item_final(indent, max_target)
end

.pretty_seq(s, indent = 0, max_target = 40) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/cbor-pretty.rb', line 24

def self.pretty_seq(s, indent = 0, max_target = 40)
  b = Buffer.new(s)
  res = ''                    # XXX: not all indented the same
  while !b.empty?
    res << b.pretty_item_final(indent, max_target, true)
  end
  res
end