idnits 2.17.1 draft-ietf-cbor-array-tags-00.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 : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (October 22, 2018) is 2013 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Informational ---------------------------------------------------------------------------- -- Looks like a reference, but probably isn't: '2' on line 301 -- Looks like a reference, but probably isn't: '3' on line 220 == Outdated reference: A later version (-08) exists of draft-ietf-cbor-cddl-05 ** Obsolete normative reference: RFC 7049 (Obsoleted by RFC 8949) Summary: 1 error (**), 0 flaws (~~), 2 warnings (==), 4 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Network Working Group J. Roatch 3 Internet-Draft 4 Intended status: Informational C. Bormann 5 Expires: April 25, 2019 Universitaet Bremen TZI 6 October 22, 2018 8 Concise Binary Object Representation (CBOR) Tags for Typed Arrays 9 draft-ietf-cbor-array-tags-00 11 Abstract 13 The Concise Binary Object Representation (CBOR, RFC 7049) is a data 14 format whose design goals include the possibility of extremely small 15 code size, fairly small message size, and extensibility without the 16 need for version negotiation. 18 The present document makes use of this extensibility to define a 19 number of CBOR tags for typed arrays of numeric data, as well as two 20 additional tags for multi-dimensional and homogeneous arrays. It is 21 intended as the reference document for the IANA registration of the 22 CBOR tags defined. 24 Status of This Memo 26 This Internet-Draft is submitted in full conformance with the 27 provisions of BCP 78 and BCP 79. 29 Internet-Drafts are working documents of the Internet Engineering 30 Task Force (IETF). Note that other groups may also distribute 31 working documents as Internet-Drafts. The list of current Internet- 32 Drafts is at https://datatracker.ietf.org/drafts/current/. 34 Internet-Drafts are draft documents valid for a maximum of six months 35 and may be updated, replaced, or obsoleted by other documents at any 36 time. It is inappropriate to use Internet-Drafts as reference 37 material or to cite them other than as "work in progress." 39 This Internet-Draft will expire on April 25, 2019. 41 Copyright Notice 43 Copyright (c) 2018 IETF Trust and the persons identified as the 44 document authors. All rights reserved. 46 This document is subject to BCP 78 and the IETF Trust's Legal 47 Provisions Relating to IETF Documents 48 (https://trustee.ietf.org/license-info) in effect on the date of 49 publication of this document. Please review these documents 50 carefully, as they describe your rights and restrictions with respect 51 to this document. Code Components extracted from this document must 52 include Simplified BSD License text as described in Section 4.e of 53 the Trust Legal Provisions and are provided without warranty as 54 described in the Simplified BSD License. 56 Table of Contents 58 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2 59 1.1. Terminology . . . . . . . . . . . . . . . . . . . . . . . 3 60 2. Typed Arrays . . . . . . . . . . . . . . . . . . . . . . . . 3 61 2.1. Types of numbers . . . . . . . . . . . . . . . . . . . . 3 62 3. Additional Array Tags . . . . . . . . . . . . . . . . . . . . 4 63 3.1. Multi-dimensional Array . . . . . . . . . . . . . . . . . 5 64 3.2. Homogeneous Array . . . . . . . . . . . . . . . . . . . . 6 65 4. Discussion . . . . . . . . . . . . . . . . . . . . . . . . . 7 66 5. CDDL typenames . . . . . . . . . . . . . . . . . . . . . . . 8 67 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 9 68 7. Security Considerations . . . . . . . . . . . . . . . . . . . 10 69 8. References . . . . . . . . . . . . . . . . . . . . . . . . . 11 70 8.1. Normative References . . . . . . . . . . . . . . . . . . 11 71 8.2. Informative References . . . . . . . . . . . . . . . . . 11 72 Contributors . . . . . . . . . . . . . . . . . . . . . . . . . . 12 73 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 12 74 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 12 76 1. Introduction 78 The Concise Binary Object Representation (CBOR, [RFC7049]) provides 79 for the interchange of structured data without a requirement for a 80 pre-agreed schema. RFC 7049 defines a basic set of data types, as 81 well as a tagging mechanism that enables extending the set of data 82 types supported via an IANA registry. 84 Recently, a simple form of typed arrays of numeric data have received 85 interest both in the Web graphics community [TypedArray] and in the 86 JavaScript specification [TypedArrayES6], as well as in corresponding 87 implementations [ArrayBuffer]. 89 Since these typed arrays may carry significant amounts of data, there 90 is interest in interchanging them in CBOR without the need of lengthy 91 conversion of each number in the array. 93 This document defines a number of interrelated CBOR tags that cover 94 these typed arrays, as well as two additional tags for multi- 95 dimensional and homogeneous arrays. It is intended as the reference 96 document for the IANA registration of the tags defined. 98 1.1. Terminology 100 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 101 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 102 "OPTIONAL" in this document are to be interpreted as described in 103 BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all 104 capitals, as shown here. 106 The term "byte" is used in its now customary sense as a synonym for 107 "octet". Where bit arithmetic is explained, this document uses the 108 notation familiar from the programming language C (including C++14's 109 0bnnn binary literals), except that the operator "**" stands for 110 exponentiation. 112 2. Typed Arrays 114 Typed arrays are homogeneous arrays of numbers, all of which are 115 encoded in a single form of binary representation. The concatenation 116 of these representations is encoded as a single CBOR byte string 117 (major type 2), enclosed by a single tag indicating the type and 118 encoding of all the numbers represented in the byte string. 120 2.1. Types of numbers 122 Three classes of numbers are of interest: unsigned integers (uint), 123 signed integers (twos' complement, sint), and IEEE 754 binary 124 floating point numbers (which are always signed). For each of these 125 classes, there are multiple representation lengths in active use: 127 +-----------+--------+--------+-----------+ 128 | Length ll | uint | sint | float | 129 +-----------+--------+--------+-----------+ 130 | 0 | uint8 | sint8 | binary16 | 131 | 1 | uint16 | sint16 | binary32 | 132 | 2 | uint32 | sint32 | binary64 | 133 | 3 | uint64 | sint64 | binary128 | 134 +-----------+--------+--------+-----------+ 136 Table 1: Length values 138 Here, sintN stands for a signed integer of exactly N bits (for 139 instance, sint16), and uintN stands for an unsigned integer of 140 exactly N bits (for instance, uint32). The name binaryN stands for 141 the number form of the same name defined in IEEE 754. 143 Since one objective of these tags is to be able to directly ship the 144 ArrayBuffers underlying the Typed Arrays without re-encoding them, 145 and these may be either in big endian (network byte order) or in 146 little endian form, we need to define tags for both variants. 148 In total, this leads to 24 variants. In the tag, we need to express 149 the choice between integer and floating point, the signedness (for 150 integers), the endianness, and one of the four length values. 152 In order to simplify implementation, a range of tags is being 153 allocated that allows retrieving all this information from the bits 154 of the tag: Tag values from TBD64 to TBD87. 156 The value is split up into 5 bit fields: TDB0b010_f_s_e_ll, as 157 detailed in Table 2. 159 +----------+-------------------------------------------------------+ 160 | Field | Use | 161 +----------+-------------------------------------------------------+ 162 | TBD0b010 | a constant such as '010', to be defined | 163 | f | 0 for integer, 1 for float | 164 | s | 0 for unsigned integer or float, 1 for signed integer | 165 | e | 0 for big endian, 1 for little endian | 166 | ll | A number for the length (Table 1). | 167 +----------+-------------------------------------------------------+ 169 Table 2: Bit fields in the low 8 bits of the tag 171 The number of bytes in each array element can then be calculated by 172 "2**(f + ll)" (or "1 << (f + ll)" in a typical programming language). 173 (Notice that f and ll are the lsb of each nibble (4bit) in the byte.) 175 In the CBOR representation, the total number of elements in the array 176 is not expressed explicitly, but implied from the length of the byte 177 string and the length of each representation. It can be computed 178 inversely to the previous formula: "bytelength >> (f + ll)". 180 For the uint8/sint8 values, the endianness is redundant. Only the 181 big endian variant is used. The little endian variant of sint8 MUST 182 NOT be used, its tag is marked as reserved. As a special case, what 183 would be the little endian variant of uint8 is used to signify that 184 the numbers in the array are using clamped conversion from integers, 185 as described in more detail in Section 7.1 of [TypedArrayUpdate]. 187 3. Additional Array Tags 189 This specification defines two additional array tags. The Multi- 190 dimensional Array tag can be combined with classical CBOR arrays as 191 well as with Typed Arrays in order to build multi-dimensional arrays 192 with constant numbers of elements in the sub-arrays. The Homogeneous 193 Array tag can be used to facilitate the ingestion of homogeneous 194 classical CBOR arrays, providing performance advantages even when a 195 Typed Array does not apply. 197 3.1. Multi-dimensional Array 199 Tag: TBD40 201 Data Item: array (major type 4) of two arrays, one array (major type 202 4) of dimensions, and one array (major type 4, a Typed Array, or a 203 Homogeneous Array) of elements 205 A multi-dimensional array is represented as a tagged array that 206 contains two (one-dimensional) arrays. The first array defines the 207 dimensions of the multi-dimensional array (in the sequence of outer 208 dimensions towards inner dimensions) while the second array 209 represents the contents of the multi-dimensional array. If the 210 second array is itself tagged as a Typed Array then the element type 211 of the multi-dimensional array is known to be the same type as that 212 of the Typed Array. Data in the Typed Array byte string consists of 213 consecutive values where the last dimension is considered contiguous 214 (row-major order). 216 Figure 1 shows a declaration of a two-dimensional array in the C 217 language, a representation of that in CBOR using both a 218 multidimensional array tag and a typed array tag. 220 uint16_t a[2][3] = { 221 {2, 4, 8}, /* row 0 */ 222 {4, 16, 256}, 223 }; 225 # multi-dimensional array tag 226 82 # array(2) 227 82 # array(2) 228 02 # unsigned(2) 1st Dimension 229 03 # unsigned(3) 2nd Dimension 230 # uint16 array 231 4c # byte string(12) 232 0002 # unsigned(2) 233 0004 # unsigned(4) 234 0008 # unsigned(8) 235 0004 # unsigned(4) 236 0010 # unsigned(16) 237 0100 # unsigned(256) 239 Figure 1: Multi-dimensional array in C and CBOR 241 Figure 2 shows the same two-dimensional array using the 242 multidimensional array tag in conjunction with a basic CBOR array 243 (which, with the small numbers chosen for the example, happens to be 244 shorter). 246 # multi-dimensional array tag 247 82 # array(2) 248 82 # array(2) 249 02 # unsigned(2) 1st Dimension 250 03 # unsigned(3) 2nd Dimension 251 86 # array(6) 252 02 # unsigned(2) 253 04 # unsigned(4) 254 08 # unsigned(8) 255 04 # unsigned(4) 256 10 # unsigned(16) 257 19 0100 # unsigned(256) 259 Figure 2: Multi-dimensional array using basic CBOR array 261 Note that these arrays are in "row major" order; if a representation 262 for "column major" order arrays is desired, it can be defined 263 analogously with a new tag (but the present document does not). 265 3.2. Homogeneous Array 267 Tag: TBD41 269 Data Item: array (major type 4) 271 This tag provides a hint to decoders that the array tagged by it has 272 elements that are all of the same application type. The element type 273 of the array is thus determined by the application type of the first 274 array element. This can be used by implementations in strongly typed 275 languages while decoding to create native homogeneous arrays of 276 specific types instead of ordered lists. 278 Which CBOR data items constitute elements of the same application 279 type is specific to the application. However, type systems of 280 programming languages have enough commonality that an application 281 should be able to create portable homogeneous arrays. 283 Figure 3 shows an example for a homogeneous array of booleans in C++ 284 and CBOR. 286 bool boolArray[2] = { true, false }; 288 # Homogeneous Array Tag 289 82 #array(2) 290 F5 # true 291 F4 # false 293 Figure 3: Homogeneous array in C++ and CBOR 295 Figure 4 extends the example with a more complex structure. 297 typedef struct { 298 bool active; 299 int value; 300 } foo; 301 foo myArray[2] = { {true, 3}, {true, -4} }; 303 304 82 # array(2) 305 82 # array(2) 306 F5 # true 307 03 # 3 308 82 # array(2) 309 F5 # true 310 23 # -4 312 Figure 4: Homogeneous array in C++ and CBOR 314 4. Discussion 316 Support for both little- and big-endian representation may seem out 317 of character with CBOR, which is otherwise fully big endian. This 318 support is in line with the intended use of the typed arrays and the 319 objective not to require conversion of each array element. 321 This specification allocates a sizable chunk out of the single-byte 322 tag space. This use of code point space is justified by the wide use 323 of typed arrays in data interchange. 325 Applying a Homogeneous Array tag to a Typed Array would be redundant 326 and is therefore not provided by the present specification. 328 5. CDDL typenames 330 For the use with CDDL [I-D.ietf-cbor-cddl], the typenames defined in 331 Figure 5 are recommended: 333 ta-uint8 = #6.TBD64(bstr) 334 ta-uint16be = #6.TBD65(bstr) 335 ta-uint32be = #6.TBD66(bstr) 336 ta-uint64be = #6.TBD67(bstr) 337 ta-uint8-clamped = #6.TBD68(bstr) 338 ta-uint16le = #6.TBD69(bstr) 339 ta-uint32le = #6.TBD70(bstr) 340 ta-uint64le = #6.TBD71(bstr) 341 ta-sint8 = #6.TBD72(bstr) 342 ta-sint16be = #6.TBD73(bstr) 343 ta-sint32be = #6.TBD74(bstr) 344 ta-sint64be = #6.TBD75(bstr) 345 ; reserved: #6.TBD76(bstr) 346 ta-sint16le = #6.TBD77(bstr) 347 ta-sint32le = #6.TBD78(bstr) 348 ta-sint64le = #6.TBD79(bstr) 349 ta-float16be = #6.TBD80(bstr) 350 ta-float32be = #6.TBD81(bstr) 351 ta-float64be = #6.TBD82(bstr) 352 ta-float128be = #6.TBD83(bstr) 353 ta-float16le = #6.TBD84(bstr) 354 ta-float32le = #6.TBD85(bstr) 355 ta-float64le = #6.TBD86(bstr) 356 ta-float128le = #6.TBD87(bstr) 357 homogeneous = #6.TBD41(array) 358 multi-dim = #6.TBD40([dim, array]) 360 Figure 5: Recommended typenames for CDDL 362 6. IANA Considerations 364 IANA is requested to allocate the tags in Table 3, with the present 365 document as the specification reference. (The reserved value is 366 reserved for a future revision of typed array tags.) 368 +-------+-------------------+---------------------------------------+ 369 | Tag | Data Item | Semantics | 370 +-------+-------------------+---------------------------------------+ 371 | TBD64 | byte string | uint8 Typed Array | 372 | TBD65 | byte string | uint16, big endian, Typed Array | 373 | TBD66 | byte string | uint32, big endian, Typed Array | 374 | TBD67 | byte string | uint64, big endian, Typed Array | 375 | TBD68 | byte string | uint8 Typed Array, clamped arithmetic | 376 | TBD69 | byte string | uint16, little endian, Typed Array | 377 | TBD70 | byte string | uint32, little endian, Typed Array | 378 | TBD71 | byte string | uint64, little endian, Typed Array | 379 | TBD72 | byte string | sint8 Typed Array | 380 | TBD73 | byte string | sint16, big endian, Typed Array | 381 | TBD74 | byte string | sint32, big endian, Typed Array | 382 | TBD75 | byte string | sint64, big endian, Typed Array | 383 | TBD76 | byte string | (reserved) | 384 | TBD77 | byte string | sint16, little endian, Typed Array | 385 | TBD78 | byte string | sint32, little endian, Typed Array | 386 | TBD79 | byte string | sint64, little endian, Typed Array | 387 | TBD80 | byte string | IEEE 754 binary16, big endian, Typed | 388 | | | Array | 389 | TBD81 | byte string | IEEE 754 binary32, big endian, Typed | 390 | | | Array | 391 | TBD82 | byte string | IEEE 754 binary64, big endian, Typed | 392 | | | Array | 393 | TBD83 | byte string | IEEE 754 binary128, big endian, Typed | 394 | | | Array | 395 | TBD84 | byte string | IEEE 754 binary16, little endian, | 396 | | | Typed Array | 397 | TBD85 | byte string | IEEE 754 binary32, little endian, | 398 | | | Typed Array | 399 | TBD86 | byte string | IEEE 754 binary64, little endian, | 400 | | | Typed Array | 401 | TBD87 | byte string | IEEE 754 binary128, little endian, | 402 | | | Typed Array | 403 | TBD40 | array of two | Multi-dimensional Array | 404 | | arrays* | | 405 | TBD41 | array | Homogeneous Array | 406 +-------+-------------------+---------------------------------------+ 408 Table 3: Values for Tags 410 *) TBD40 data item: second element of outer array in data item is 411 native CBOR array (major type 4) or Typed Array (one of Tag 412 TBD64..TBD87) 414 RFC editor note: Please replace TBDnn by the tag numbers allocated by 415 IANA throughout the document and delete this note. IANA note: To 416 make the calculations work, TDB64 to TBD87 need to come from a 417 contiguous range the start of which is divisible by 32. 419 TO DO: The WG needs to figure out whether it is OK to spend 24 "good" 420 (1+1 byte) tags for this, whether this all goes to 1+2 byte tags, or 421 whether maybe the layout of the bits in the tag should change to move 422 the larger datatypes into the 1+2 range and just the 8-bit ones into 423 the 1+1 range. 425 7. Security Considerations 427 The security considerations of RFC 7049 apply; special attention is 428 drawn to the second paragraph of Section 8 of RFC 7049. The tags 429 introduced here are not expected to raise security considerations 430 beyond those. 432 8. References 434 8.1. Normative References 436 [I-D.ietf-cbor-cddl] 437 Birkholz, H., Vigano, C., and C. Bormann, "Concise data 438 definition language (CDDL): a notational convention to 439 express CBOR and JSON data structures", draft-ietf-cbor- 440 cddl-05 (work in progress), August 2018. 442 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 443 Requirement Levels", BCP 14, RFC 2119, 444 DOI 10.17487/RFC2119, March 1997, 445 . 447 [RFC7049] Bormann, C. and P. Hoffman, "Concise Binary Object 448 Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, 449 October 2013, . 451 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 452 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 453 May 2017, . 455 8.2. Informative References 457 [ArrayBuffer] 458 Mozilla Developer Network, "JavaScript typed arrays", 459 2013, . 462 [TypedArray] 463 Vukicevic, V. and K. Russell, "Typed Array Specification", 464 February 2011, 465 . 467 [TypedArrayES6] 468 "22.2 TypedArray Objects", in: ECMA-262 6th Edition, The 469 ECMAScript 2015 Language Specification, June 2015, 470 . 473 [TypedArrayUpdate] 474 Herman, D. and K. Russell, "Typed Array Specification", 475 July 2013, 476 . 479 Contributors 481 Glenn Engel suggested the tags for multi-dimensional arrays and 482 homogeneous arrays. 484 Acknowledgements 486 TBD 488 Authors' Addresses 490 Johnathan Roatch 492 Email: jroatch@gmail.com 494 Carsten Bormann 495 Universitaet Bremen TZI 496 Postfach 330440 497 Bremen D-28359 498 Germany 500 Phone: +49-421-218-63921 501 Email: cabo@tzi.org