idnits 2.17.1 draft-hallambaker-jsonbcd-16.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack an Authors' Addresses Section. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (27 July 2020) is 1361 days in the past. Is this intentional? Checking references for intended status: Informational ---------------------------------------------------------------------------- == Missing Reference: 'RFC2119' is mentioned on line 171, but not defined ** Obsolete normative reference: RFC 7159 (Obsoleted by RFC 8259) Summary: 2 errors (**), 0 flaws (~~), 2 warnings (==), 1 comment (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Network Working Group P. M. Hallam-Baker 3 Internet-Draft 27 July 2020 4 Intended status: Informational 5 Expires: 28 January 2021 7 Binary Encodings for JavaScript Object Notation: JSON-B, JSON-C, JSON-D 8 draft-hallambaker-jsonbcd-16 10 Abstract 12 Three binary encodings for JavaScript Object Notation (JSON) are 13 presented. JSON-B (Binary) is a strict superset of the JSON encoding 14 that permits efficient binary encoding of intrinsic JavaScript data 15 types. JSON-C (Compact) is a strict superset of JSON-B that supports 16 compact representation of repeated data strings with short numeric 17 codes. JSON-D (Data) supports additional binary data types for 18 integer and floating-point representations for use in scientific 19 applications where conversion between binary and decimal 20 representations would cause a loss of precision. 22 This document is also available online at 23 http://mathmesh.com/Documents/draft-hallambaker-jsonbcd.html. 25 Status of This Memo 27 This Internet-Draft is submitted in full conformance with the 28 provisions of BCP 78 and BCP 79. 30 Internet-Drafts are working documents of the Internet Engineering 31 Task Force (IETF). Note that other groups may also distribute 32 working documents as Internet-Drafts. The list of current Internet- 33 Drafts is at https://datatracker.ietf.org/drafts/current/. 35 Internet-Drafts are draft documents valid for a maximum of six months 36 and may be updated, replaced, or obsoleted by other documents at any 37 time. It is inappropriate to use Internet-Drafts as reference 38 material or to cite them other than as "work in progress." 40 This Internet-Draft will expire on 28 January 2021. 42 Copyright Notice 44 Copyright (c) 2020 IETF Trust and the persons identified as the 45 document authors. All rights reserved. 47 This document is subject to BCP 78 and the IETF Trust's Legal 48 Provisions Relating to IETF Documents (https://trustee.ietf.org/ 49 license-info) in effect on the date of publication of this document. 50 Please review these documents carefully, as they describe your rights 51 and restrictions with respect to this document. 53 Table of Contents 55 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2 56 1.1. Objectives . . . . . . . . . . . . . . . . . . . . . . . 3 57 2. Definitions . . . . . . . . . . . . . . . . . . . . . . . . . 4 58 2.1. Requirements Language . . . . . . . . . . . . . . . . . . 4 59 2.2. Defined Terms . . . . . . . . . . . . . . . . . . . . . . 4 60 2.3. Related Specifications . . . . . . . . . . . . . . . . . 4 61 2.4. Terminology . . . . . . . . . . . . . . . . . . . . . . . 4 62 3. Extended JSON Grammar . . . . . . . . . . . . . . . . . . . . 5 63 4. JSON-B . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 64 4.1. JSON-B Examples . . . . . . . . . . . . . . . . . . . . . 9 65 5. JSON-C . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 66 5.1. JSON-C Examples . . . . . . . . . . . . . . . . . . . . . 11 67 6. JSON-D (Data) . . . . . . . . . . . . . . . . . . . . . . . . 12 68 7. JBCD Frames and Records . . . . . . . . . . . . . . . . . . . 13 69 8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 15 70 9. Security Considerations . . . . . . . . . . . . . . . . . . . 15 71 10. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 15 72 11. Normative References . . . . . . . . . . . . . . . . . . . . 16 73 12. Informative References . . . . . . . . . . . . . . . . . . . 16 75 1. Introduction 77 JavaScript Object Notation (JSON) is a simple text encoding for the 78 JavaScript Data model that has found wide application beyond its 79 original field of use. In particular JSON has rapidly become a 80 preferred encoding for Web Services. 82 JSON encoding supports just four fundamental data types (integer, 83 floating point, string and boolean), arrays and objects which consist 84 of a list of tag-value pairs. 86 Although the JSON encoding is sufficient for many purposes it is not 87 always efficient. In particular there is no efficient representation 88 for blocks of binary data. Use of base64 encoding increases data 89 volume by 33%. This overhead increases exponentially in applications 90 where nested binary encodings are required making use of JSON 91 encoding unsatisfactory in cryptographic applications where nested 92 binary structures are frequently required. 94 Another source of inefficiency in JSON encoding is the repeated 95 occurrence of object tags. A JSON encoding containing an array of a 96 hundred objects such as {"first":1,"second":2} will contain a hundred 97 occurrences of the string "first" (seven bytes) and a hundred 98 occurrences of the string "second" (eight bytes). Using two byte 99 code sequences in place of strings allows a saving of 11 bytes per 100 object without loss of information, a saving of 50%. 102 A third objection to the use of JSON encoding is that floating point 103 numbers can only be represented in decimal form and this necessarily 104 involves a loss of precision when converting between binary and 105 decimal representations. While such issues are rarely important in 106 network applications they can be critical in scientific applications. 107 It is not acceptable for saving and restoring a data set to change 108 the result of a calculation. 110 1.1. Objectives 112 The following were identified as core objectives for a binary JSON 113 encoding: 115 * Easy to convert existing encoders and decoders to add binary 116 support 118 * Efficient encoding of binary data 120 * Ability to convert from JSON to binary encoding in a streaming 121 mode (i.e. without reading the entire binary data block before 122 beginning encoding. 124 * Lossless encoding of JavaScript data types 126 * The ability to support JSON tag compression and extended data 127 types are considered desirable but not essential for typical 128 network applications. 130 Three binary encodings are defined: 132 JSON-B (Binary) Encodes JSON data in binary. Only the JavaScript 133 data model is supported (i.e. atomic types are integers, double or 134 string). Integers may be 8, 16, 32 or 64 bits either signed or 135 unsigned. Floating points are IEEE 754 binary64 format [IEEE754]. 136 Supports chunked encoding for binary and UTF-8 string types. 138 JSON-C (Compact) As JSON-B but with support for representing JSON 139 tags in numeric code form (16 bit code space). This is done for 140 both compact encoding and to allow simplification of encoders/ 141 decoders in constrained environments. Codes may be defined inline 142 or by reference to a known dictionary of codes referenced via a 143 digest value. 145 JSON-D (Data) As JSON-C but with support for representing additional 146 data types without loss of precision. In particular other IEEE 147 754 floating point formats, both binary and decimal and Intel's 80 148 bit floating point, plus 128 bit integers and bignum integers. 150 Each encoding is a proper superset of JSON, JSON-C is a proper 151 superset of JSON-B and JSON-D is a proper superset of JSON-C. Thus a 152 single decoder MAY be used for all three new encodings and for JSON. 153 Figure 1 shows these relationships graphically: 155 (Artwork only available as svg: No external link available, see 156 draft-hallambaker-jsonbcd-16.html for artwork.) 158 Figure 1 160 2. Definitions 162 This section presents the related specifications and standard, the 163 terms that are used as terms of art within the documents and the 164 terms used as requirements language. 166 2.1. Requirements Language 168 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 169 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 170 document are to be interpreted as described in [RFC2119]. 172 2.2. Defined Terms 174 The terms of art used in this document are described in the _Mesh 175 Architecture Guide_ [draft-hallambaker-mesh-architecture]. 177 2.3. Related Specifications 179 The JSON-B, JSON-C and JSON-D encodings are all based on the JSON 180 grammar [RFC7159]. IEEE 754 Floating Point Standard is used for 181 encoding floating point numbers [IEEE754], 183 2.4. Terminology 185 No new terms of art are defined 187 3. Extended JSON Grammar 189 The JSON-B, JSON-C and JSON-D encodings are all based on the JSON 190 grammar [RFC7159] using the same syntactic structure but different 191 lexical encodings. 193 JSON-B0 and JSON-C0 replace the JSON lexical encodings for strings 194 and numbers with binary encodings. JSON-B1 and JSON-C1 allow either 195 lexical encoding to be used. Thus, any valid JSON encoding is a 196 valid JSON-B1 or JSON-C1 encoding. 198 The grammar of JSON-B, JSON-C and JSON-D is a superset of the JSON 199 grammar. The following productions are added to the grammar: 201 x-value Binary encodings for data values. As the binary value 202 encodings are all self-delimiting 204 x-member An object member where the value is specified as an X-value 205 and thus does not require a value-separator. 207 b-value Binary data encodings defined in JSON-B. 209 b-string Defined length string encoding defined in JSON-B. 211 c-def Tag code definition defined in JSON-C. These may only appear 212 before the beginning of an Object or Array and before any 213 preceding white space. 215 c-tag Tag code value defined in JSON-C. 217 d-value Additional binary data encodings defined in JSON-D for use 218 in scientific data applications. 220 The JSON grammar is modified to permit the use of x-value productions 221 in place of ( value value-separator ) : 223 JSON-text = (object / array) 225 object = *cdef begin-object [ 226 *( member value-separator | x-member ) 227 (member | x-member) ] end-object 229 member = tag value 230 x-member = tag x-value 232 tag = string name-separator | b-string | c-tag 234 array = *cdef begin-array [ *( value value-separator | x-value ) 235 (value | x-value) ] end-array 237 x-value = b-value / d-value 239 value = false / null / true / object / array / number / string 241 name-separator = ws %x3A ws ; : colon 242 value-separator = ws %x2C ws ; , comma 244 The following lexical values are unchanged: 245 begin-array = ws %x5B ws ; [ left square bracket 246 begin-object = ws %x7B ws ; { left curly bracket 247 end-array = ws %x5D ws ; ] right square bracket 248 end-object = ws %x7D ws ; } right curly bracket 250 ws = *( %x20 %x09 %x0A %x0D ) 252 false = %x66.61.6c.73.65 ; false 253 null = %x6e.75.6c.6c ; null 254 true = %x74.72.75.65 ; true 256 The productions number and string are defined as before: 258 number = [ minus ] int [ frac ] [ exp ] 259 decimal-point = %x2E ; . 260 digit1-9 = %x31-39 ; 1-9 261 e = %x65 / %x45 ; e E 262 exp = e [ minus / plus ] 1*DIGIT 263 frac = decimal-point 1*DIGIT 264 int = zero / ( digit1-9 *DIGIT ) 265 minus = %x2D ; - 266 plus = %x2B ; + 267 zero = %x30 ; 0 269 string = quotation-mark *char quotation-mark 270 char = unescaped / 271 escape ( %x22 / %x5C / %x2F / %x62 / %x66 / 272 %x6E / %x72 / %x74 / %x75 4HEXDIG ) 274 escape = %x5C ; \ 275 quotation-mark = %x22 ; " 276 unescaped = %x20-21 / %x23-5B / %x5D-10FFFF 278 4. JSON-B 280 The JSON-B encoding defines the b-value and b-string productions: 282 b-value = b-atom | b-string | b-data | b-integer | 283 b-float 285 b-string = *( string-chunk ) string-term 286 b-data = *( data-chunk ) data-last 288 b-integer = p-int8 | p-int16 | p-int32 | p-int64 | p-bignum16 | 289 n-int8 | n-int16 | n-int32 | n-int64 | n-bignum16 291 b-float = binary64 293 The lexical encodings of the productions are defined in the following 294 tables where the column 'tag' specifies the byte code that begins the 295 production, 'Fixed' specifies the number of data bytes that follow 296 and 'Length' specifies the number of bytes used to define the length 297 of a variable length field following the data bytes: 299 +==============+=====+=======+========+==================+ 300 | Production | Tag | Fixed | Length | Data Description | 301 +==============+=====+=======+========+==================+ 302 | string-term | x80 | - | 1 | Terminal String | 303 | | | | | 8 bit length | 304 +--------------+-----+-------+--------+------------------+ 305 | string-term | x81 | - | 2 | Terminal String | 306 | | | | | 16 bit length | 307 +--------------+-----+-------+--------+------------------+ 308 | string-term | x82 | - | 4 | Terminal String | 309 | | | | | 32 bit length | 310 +--------------+-----+-------+--------+------------------+ 311 | string-term | x83 | - | 8 | Terminal String | 312 | | | | | 64 bit length | 313 +--------------+-----+-------+--------+------------------+ 314 | string-chunk | x84 | - | 1 | Terminal String | 315 | | | | | 8 bit length | 316 +--------------+-----+-------+--------+------------------+ 317 | string-chunk | x85 | - | 2 | Terminal String | 318 | | | | | 16 bit length | 319 +--------------+-----+-------+--------+------------------+ 320 | string-chunk | x86 | - | 4 | Terminal String | 321 | | | | | 32 bit length | 322 +--------------+-----+-------+--------+------------------+ 323 | string-chunk | x87 | - | 8 | Terminal String | 324 | | | | | 64 bit length | 325 +--------------+-----+-------+--------+------------------+ 326 | data-term | x88 | - | 1 | Terminal String | 327 | | | | | 8 bit length | 328 +--------------+-----+-------+--------+------------------+ 329 | data-term | x89 | - | 2 | Terminal String | 330 | | | | | 16 bit length | 331 +--------------+-----+-------+--------+------------------+ 332 | data-term | x8A | - | 4 | Terminal String | 333 | | | | | 32 bit length | 334 +--------------+-----+-------+--------+------------------+ 335 | data-term | x8B | - | 8 | Terminal String | 336 | | | | | 64 bit length | 337 +--------------+-----+-------+--------+------------------+ 338 | data-chunk | X8C | - | 1 | Terminal String | 339 | | | | | 8 bit length | 340 +--------------+-----+-------+--------+------------------+ 341 | data-chunk | x8D | - | 2 | Terminal String | 342 | | | | | 16 bit length | 343 +--------------+-----+-------+--------+------------------+ 344 | data-chunk | x8E | - | 4 | Terminal String | 345 | | | | | 32 bit length | 346 +--------------+-----+-------+--------+------------------+ 347 | data-chunk | x8F | - | 8 | Terminal String | 348 | | | | | 64 bit length | 349 +--------------+-----+-------+--------+------------------+ 351 Table 1 353 Table 1: Codes for String and Data items 354 +============+=====+=======+========+=========================+ 355 | Production | Tag | Fixed | Length | Data Description | 356 +============+=====+=======+========+=========================+ 357 | p-int8 | xA0 | 1 | - | Positive 8 bit Integer | 358 +------------+-----+-------+--------+-------------------------+ 359 | p-int16 | xa1 | 2 | - | Positive 16 bit Integer | 360 +------------+-----+-------+--------+-------------------------+ 361 | p-int32 | xa2 | 4 | - | Positive 32 bit Integer | 362 +------------+-----+-------+--------+-------------------------+ 363 | p-int64 | xa3 | 8 | - | Positive 64 bit Integer | 364 +------------+-----+-------+--------+-------------------------+ 365 | p-bignum16 | Xa7 | - | 2 | Positive Bignum | 366 +------------+-----+-------+--------+-------------------------+ 367 | n-int8 | xA8 | 1 | - | Negative 8 bit Integer | 368 +------------+-----+-------+--------+-------------------------+ 369 | n-int16 | xA9 | 2 | - | Negative 16 bit Integer | 370 +------------+-----+-------+--------+-------------------------+ 371 | n-int32 | xAA | 4 | - | Negative 32 bit Integer | 372 +------------+-----+-------+--------+-------------------------+ 373 | n-int64 | xAB | 8 | - | Negative 64 bit Integer | 374 +------------+-----+-------+--------+-------------------------+ 375 | n-bignum16 | xAF | - | 2 | Negative Bignum | 376 +------------+-----+-------+--------+-------------------------+ 377 | binary64 | x92 | 8 | - | IEEE 754 Floating Point | 378 | | | | | Binary 64 bit | 379 +------------+-----+-------+--------+-------------------------+ 380 | b-value | xB0 | - | - | True | 381 +------------+-----+-------+--------+-------------------------+ 382 | b-value | xB1 | - | - | False | 383 +------------+-----+-------+--------+-------------------------+ 384 | b-value | xB2 | - | - | Null | 385 +------------+-----+-------+--------+-------------------------+ 387 Table 2 389 Table 2: Codes for Integers, 64 Bit Floating Point, Boolean and Null 390 items. 392 A data type commonly used in networking that is not defined in this 393 scheme is a datetime representation. To define such a data type, a 394 string containing a date-time value in Internet type format is 395 typically used. 397 4.1. JSON-B Examples 399 The following examples show examples of using JSON-B encoding: 401 A0 2A 42 (as 8 bit integer) 402 A1 00 2A 42 (as 16 bit integer) 403 A2 00 00 00 2A 42 (as 32 bit integer) 404 A3 00 00 00 00 00 00 00 2A 42 (as 64 bit integer) 405 A5 00 01 42 42 (as Bignum) 407 80 05 48 65 6c 6c 6f "Hello" (single chunk) 408 81 00 05 48 65 6c 6c 6f "Hello" (single chunk) 409 84 05 48 65 6c 6c 6f 80 00 "Hello" (as two chunks) 411 92 3f f0 00 00 00 00 00 00 1.0 412 92 40 24 00 00 00 00 00 00 10.0 413 92 40 09 21 fb 54 44 2e ea 3.14159265359 414 92 bf f0 00 00 00 00 00 00 -1.0 416 B0 true 417 B1 false 418 B2 null 420 5. JSON-C 422 JSON-C (Compressed) permits numeric code values to be substituted for 423 strings and binary data. Tag codes MAY be 8, 16 or 32 bits long 424 encoded in network byte order. 426 Tag codes MUST be defined before they are referenced. A Tag code MAY 427 be defined before the corresponding data or string value is used or 428 at the same time that it is used. 430 A dictionary is a list of tag code definitions. An encoding MAY 431 incorporate definitions from a dictionary using the dict-hash 432 production. The dict hash production specifies a (positive) offset 433 value to be added to the entries in the dictionary followed by the 434 UDF fingerprint [draft-hallambaker-udf] of the dictionary to be used. 436 +============+=====+=======+========+===============================+ 437 | Production | Tag | Fixed | Length | Data Description | 438 +============+=====+=======+========+===============================+ 439 | c-tag | xC0 | 1 | - | 8 bit tag code | 440 +------------+-----+-------+--------+-------------------------------+ 441 | c-tag | xC1 | 2 | - | 16 bit tag code | 442 +------------+-----+-------+--------+-------------------------------+ 443 | c-tag | xC2 | 4 | - | 32 bit tag code | 444 +------------+-----+-------+--------+-------------------------------+ 445 | c-def | xC4 | 1 | - | 8 bit tag definition | 446 +------------+-----+-------+--------+-------------------------------+ 447 | c-def | xC5 | 2 | - | 16 bit tag definition | 448 +------------+-----+-------+--------+-------------------------------+ 449 | c-def | xC6 | 4 | - | 32 bit tag definition | 450 +------------+-----+-------+--------+-------------------------------+ 451 | c-tag | xC8 | 1 | - | 8 bit tag code and | 452 | | | | | definition | 453 +------------+-----+-------+--------+-------------------------------+ 454 | c-tag | xC9 | 2 | - | 16 bit tag code and | 455 | | | | | definition | 456 +------------+-----+-------+--------+-------------------------------+ 457 | c-tag | xCA | 4 | - | 32 bit tag code and | 458 | | | | | definition | 459 +------------+-----+-------+--------+-------------------------------+ 460 | c-def | xCC | 1 | - | 8 bit tag dictionary | 461 | | | | | definition | 462 +------------+-----+-------+--------+-------------------------------+ 463 | c-def | xCD | 2 | - | 16 bit tag dictionary | 464 | | | | | definition | 465 +------------+-----+-------+--------+-------------------------------+ 466 | c-def | xCE | 4 | - | 32 bit tag dictionary | 467 | | | | | definition | 468 +------------+-----+-------+--------+-------------------------------+ 469 | dict-hash | xD0 | 4 | 1 | UDF fingerprint of | 470 | | | | | dictionary | 471 +------------+-----+-------+--------+-------------------------------+ 473 Table 3 475 Table 3: Codes Used for Compression 477 All integer values are encoded in Network Byte Order (most 478 significant byte first). 480 5.1. JSON-C Examples 482 The following examples show examples of using JSON-C encoding: 484 C8 20 80 05 48 65 6c 6c 6f "Hello" 20 = "Hello" 485 C4 21 80 05 48 65 6c 6c 6f 21 = "Hello" 486 C0 20 "Hello" 487 C1 00 20 "Hello" 489 D0 00 00 01 00 20 Insert dictionary at code 256 490 e3 b0 c4 42 98 fc 1c 14 491 9a fb f4 c8 99 6f b9 24 492 27 ae 41 e4 64 9b 93 4c 493 a4 95 99 1b 78 52 b8 55 UDF (C4 21 80 05 48 65 6c 6c 6f) 495 6. JSON-D (Data) 497 JSON-B and JSON-C only support the two numeric types defined in the 498 JavaScript data model: Integers and 64 bit floating point values. 499 JSON-D (Data) defines binary encodings for additional data types that 500 are commonly used in scientific applications. These comprise 501 positive and negative 128 bit integers, six additional floating point 502 representations defined by IEEE 754 [IEEE754] and the Intel extended 503 precision 80 bit floating point representation [INTEL]. 505 Should the need arise, even bigger bignums could be defined with the 506 length specified as a 32 bit value permitting bignums of up to 2^35 507 bits to be represented. 509 d-value = d-integer | d-float 511 d-float = binary16 | binary32 | binary128 | binary80 | 512 decimal32 | decimal64 | decimal 128 514 The codes for these values are as follows: 516 +============+=====+=======+========+==========================+ 517 | Production | Tag | Fixed | Length | Data Description | 518 +============+=====+=======+========+==========================+ 519 | p-int128 | xA4 | 16 | - | Positive 128 bit Integer | 520 +------------+-----+-------+--------+--------------------------+ 521 | n-int128 | xAC | 16 | - | Negative 128 bit Integer | 522 +------------+-----+-------+--------+--------------------------+ 523 | binary16 | x90 | 2 | - | IEEE 754 Floating Point | 524 | | | | | Binary 16 bit | 525 +------------+-----+-------+--------+--------------------------+ 526 | binary32 | x91 | 4 | - | IEEE 754 Floating Point | 527 | | | | | Binary 32 bit | 528 +------------+-----+-------+--------+--------------------------+ 529 | binary128 | x94 | 16 | - | IEEE 754 Floating Point | 530 | | | | | Binary 64 bit | 531 +------------+-----+-------+--------+--------------------------+ 532 | Intel80 | x95 | 10 | - | Intel extended Floating | 533 | | | | | Point 80 bit | 534 +------------+-----+-------+--------+--------------------------+ 535 | decimal32 | x96 | 4 | - | IEEE 754 Floating Point | 536 | | | | | Decimal 32 | 537 +------------+-----+-------+--------+--------------------------+ 538 | Decimal64 | x97 | 8 | - | IEEE 754 Floating Point | 539 | | | | | Decimal 64 | 540 +------------+-----+-------+--------+--------------------------+ 541 | Decimal128 | x98 | 16 | - | IEEE 754 Floating Point | 542 | | | | | Decimal 128 | 543 +------------+-----+-------+--------+--------------------------+ 545 Table 4 547 Table 4: Additional Codes for Scientific Data 549 7. JBCD Frames and Records 551 Tag codes in the range xF0-XFF are reserved for specifying markers 552 for _frames_ and _records_. These tags are not used to encode JSON 553 data, they are only used to encapsulate opaque binary data blobs as a 554 unit. 556 A JBCD record consists of consist of the tag, a length and the data 557 item. The length indication provided by the record format allows 558 efficient traversal of a sequence of records in the forward direction 559 only. 561 A JBCD Frames consists of consist of the tag, a length and the data 562 item followed by the tag-length sequence repeated with the bytes 563 written in the reverse order. The first length indication allows 564 efficient traversal of a sequence of records in the forward direction 565 and the second allows efficient traversal in the reverse direction. 567 (Artwork only available as svg: No external link available, see 568 draft-hallambaker-jsonbcd-16.html for artwork.) 570 Figure 2 572 The JBCD-Frame tags currently defined are: 574 +============+=========+=======+========+=======================+ 575 | Production | Tag | Fixed | Length | Data Description | 576 +============+=========+=======+========+=======================+ 577 | uframe | xF0 | - | 1 | Record, 8 bit length | 578 +------------+---------+-------+--------+-----------------------+ 579 | uframe | xF1 | - | 2 | Record, 16 bit length | 580 +------------+---------+-------+--------+-----------------------+ 581 | uframe | xF2 | - | 4 | Record, 32 bit length | 582 +------------+---------+-------+--------+-----------------------+ 583 | uframe | xF3 | - | 8 | Record, 64 bit length | 584 +------------+---------+-------+--------+-----------------------+ 585 | bframe | xF4 | - | 1 | Frame, 8 bit length | 586 +------------+---------+-------+--------+-----------------------+ 587 | bframe | xF5 | - | 2 | Frame, 16 bit length | 588 +------------+---------+-------+--------+-----------------------+ 589 | bframe | xF6 | - | 4 | Frame, 32 bit length | 590 +------------+---------+-------+--------+-----------------------+ 591 | bframe | xF7 | - | 8 | Frame, 64 bit length | 592 +------------+---------+-------+--------+-----------------------+ 593 | | xF8-xFF | - | - | Reserved | 594 +------------+---------+-------+--------+-----------------------+ 596 Table 5 598 The author does not expect additional framing tags to be added but 599 codes F8-FF are reserved in case this is desired. 601 It may prove convenient to represent message digest values as large 602 integers rather than binary strings. While very few platforms or 603 programming languages support mathematical operations on fixed size 604 integers larger than 64, this is not a major concern since message 605 digests are rarely used for any purpose other than comparison for 606 equality. 608 +============+=====+=======+========+==========================+ 609 | Production | Tag | Fixed | Length | Data Description | 610 +============+=====+=======+========+==========================+ 611 | p-int128 | Xa4 | 16 | - | Positive 128 bit Integer | 612 +------------+-----+-------+--------+--------------------------+ 613 | p-int256 | Xa5 | 32 | - | Positive 256 bit Integer | 614 +------------+-----+-------+--------+--------------------------+ 615 | p-int512 | Xa6 | 64 | - | Positive 512 bit Integer | 616 +------------+-----+-------+--------+--------------------------+ 618 Table 6 620 8. Acknowledgements 622 This work was assisted by conversations with Nico Williams and other 623 participants on the applications area mailing list. 625 9. Security Considerations 627 A correctly implemented data encoding mechanism should not introduce 628 new security vulnerabilities. However, experience demonstrates that 629 some data encoding approaches are more prone to introduce 630 vulnerabilities when incorrectly implemented than others. 632 In particular, whenever variable length data formats are used, the 633 possibility of a buffer overrun vulnerability is introduced. While 634 best practice suggests that a coding language with native mechanisms 635 for bounds checking is the best protection against such errors, such 636 approaches are not always followed. While such vulnerabilities are 637 most commonly seen in the design of decoders, it is possible for the 638 same vulnerabilities to be exploited in encoders. 640 A common source of such errors is the case where nested length 641 encodings are used. For example, a decoder relies on an outermost 642 length encoding that specifies a length on 50 bytes to allocate 643 memory for the entire result and then attempts to copy a string with 644 a declared length of 1000 bytes within the sequence. 646 The extensions to the JSON encoding described in this document are 647 designed to avoid such errors. Length encodings are only used to 648 define the length of x-value constructions which are always terminal 649 and cannot have nested data entries. 651 10. IANA Considerations 653 [TBS list out all the code points that require an IANA registration] 655 11. Normative References 657 [draft-hallambaker-udf] 658 Hallam-Baker, P., "Uniform Data Fingerprint (UDF)", Work 659 in Progress, Internet-Draft, draft-hallambaker-udf-12, 6 660 January 2019, 661 . 663 [IEEE754] IEEE Computer Society, "IEEE Standard for Floating-Point 664 Arithmetic", IEEE 754-2008, 665 DOI 10.1109/IEEESTD.2008.4610935, 29 August 2008, 666 . 668 [INTEL] Intel Corp., "Unknown". 670 [RFC7159] Bray, T., "The JavaScript Object Notation (JSON) Data 671 Interchange Format", RFC 7159, DOI 10.17487/RFC7159, March 672 2014, . 674 12. Informative References 676 [draft-hallambaker-mesh-architecture] 677 Hallam-Baker, P., "Mathematical Mesh 3.0 Part I: 678 Architecture Guide", Work in Progress, Internet-Draft, 679 draft-hallambaker-mesh-architecture-13, 9 March 2020, 680 .