Module: CBOR::Dcbor::Integer_Dcbor_CBOR

Defined in:
lib/cbor-dcbor.rb

Instance Method Summary collapse

Instance Method Details

#cbor_prepare_dcborObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cbor-dcbor.rb', line 19

def cbor_prepare_dcbor
  zigzag, tagnum = if self < 0
                     [-1-self, 3]
                   else
                     [self, 2]
                   end
  bytes = zigzag.digits(256)
  if bytes.size + 2 < self.to_cbor.size
    CBOR::Tagged.new(tagnum, bytes.pack("C*").reverse!)
  else
    self
  end
end