Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CBOR Overview

ritou
March 19, 2018

CBOR Overview

ritou

March 19, 2018
Tweet

More Decks by ritou

Other Decks in Technology

Transcript

  1. Road to CWT 1. Concise Binary Object Representation (CBOR) 2.

    CBOR Object Signing and Encryption (COSE) 3. CBOR Web Token (CWT) 2
  2. RFC 7049 The Concise Binary Object Representation (CBOR) is a

    data format whose design goals include the possibility of extremely small code size, fairly small message size, and extensibility without the need for version negotiation. 4
  3. The objectives of CBOR 1. Unambiguous encoding of most common

    data formats 2. Code compactness for encoder or decoder 3. No schema description needed 4. Reasonably compact serialization 5. Applicability to constrained and unconstrained applications 6. Good JSON conversion 7. Extensibility 5
  4. Major Types • 0. Unsigned Integer • 1. Negative Integer

    • 2. Byte String • 3. Text String • 4. Array • 5. Map 6. Optional Tagging of Items 7. Floating-Point Numbers and Simple Values 6
  5. 0. Unsigned Integer 7 uint8 0:<<0>>, 23:<<23>>, 24:<<24, 24>>, 255:<<24,

    255>> uint16 256:<<25, 1, 0>>, 65535:<<25, 255, 255>> uint32 65536:<<26, 0, 1, 0, 0>>, 4294967295:<<26, 255, 255, 255, 255>> uint64 4294967296:<<27, 0, 0, 0, 1, 0, 0, 0, 0>> 18446744073709551615:<<27, 255, 255, 255, 255, 255, 255, 255, 255>>
  6. 1. Negative Integer 8 uint8 -1:<<32>>, -24:<<55>>, -25:<<56, 24>>, -256:<<56,

    255>> uint16 -257:<<57, 1, 0>>, -65536:<<57, 255, 255>> uint32 -65537:<<58, 0, 1, 0, 0>>, -4294967296:<<58, 255, 255, 255, 255>> uint64 -4294967297:<<59, 0, 0, 0, 1, 0, 0, 0, 0>> -18446744073709551616:<<59, 255, 255, 255, 255, 255, 255, 255, 255>>
  7. 2. Byte String 9 <<>>:<<64>>, <<255>>:<<65, 255>>, <<1, 0>>:<<66, 1,

    0>>, bytes(23):<<87>> <> bytes bytes(24):<<88, 24>> <> bytes, bytes(255):<<88, 255>> <> bytes bytes(256):<<89, 1, 0>> <> bytes, bytes(65535):<<89, 255, 255>> <> bytes
  8. 3. Text String 10 “”:<<96>>, bytes(23):<<119>> <> bytes bytes(24):<<120, 24>>

    <> bytes, bytes(255):<<120, 255>> <> bytes bytes(256):<<121, 1, 0>> <> bytes, bytes(65535):<<121, 255, 255>> <> bytes
  9. 4. Array 11 []:<<128>>, [0]:<<129, 0>>, [1, 2, 3 …

    23]:<<151, 1, 2, 3, … 23>> [1 … 24]:<<152, 24, 1 … 24, 24>>, [1 … 255]:<<152, 255, 1 … 24, 255>> [1 … 256]:<<153, 1, 0, 1 … 25, 1, 0>>, [1 … 65535]:<<153, 255, 255, 1 … 25, 255, 255>>
  10. 5. Map 12 %{}:<<160>>, %{0 => 0}:<<161, 0, 0>>, %{1

    => 1 … 23 => 23}:<<183, 1, 1 … 23, 23>> %{1 => 1 … 24 => 24}:<<184, 24, 1, 1 … 24, 24, 24, 24>> %{1 => 1 … 255 => 255}:<<184, 255, 1, 1 … 24, 255, 24, 255>>
  11. 6. Optional semantic tagging 13 timetext 0("2013-03-21T20:04:00Z"):<<192, 84, 50, 48,

    49, 51, 45, 48, 51, 45, 50, 49, 84, 50, 48, 58, 48, 52, 58, 48, 48, 90>> timeepoch 1(1363896240):<<193, 26, 81, 75, 103, 176>> Bignums 18446744073709551616:<<194, 73, 1, 0, 0, 0, 0, 0, 0, 0, 0>> -18446744073709551617:<<195, 73, 1, 0, 0, 0, 0, 0, 0, 0, 0>>
  12. 7. Floating-Point Numbers and Simple Values 14 Simple simple(0):<<224>>, simple(19):<<243>>,

    simple(255):<<248, 255>> Boolean false:<<244>>, true:<<245>>, Null Null:<<246>> Undefined Undefined:<<247>> Floating- point 0.0:<<249, 0, 0>>, -0.0:<<249, 128, 0>>, 1.0:<<249, 60, 0>> 100000.0:<<250, 71, 195, 80, 0>>, 3.4028234663852886e+38:<<250, 127, 127, 255, 255>>
  13. 16

  14. 17

  15. Size Comparison value CBOR(bytes) JSON(bytes) 0 1 1 23 1

    2 18446744073709551615 9 20 18446744073709551616 11 20 "12345678901234567890123" 24 25 "123456789012345678901234" 26 26 20
  16. Size Comparison value CBOR(bytes) JSON(bytes) [] 1 2 [1, 2,

    3, 4] 5 9 [“a”, “b”, “c”, “d”] 9 17 {} 1 2 {1:2, 3:4} 5 13 {“a”:”b”, “c”:”d”} 9 17 21