| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 part of dart.typeddata; |
| 6 |
| 7 /** |
| 8 * A sequence of bytes underlying a typed data object. |
| 9 * Used to process large quantities of binary or numerical data |
| 10 * more efficiently using a typed view. |
| 11 */ |
| 12 abstract class ByteBuffer { |
| 13 /** |
| 14 * Returns the length of this byte buffer, in bytes. |
| 15 */ |
| 16 int get lengthInBytes; |
| 17 |
| 18 } |
| 19 |
| 20 |
| 21 /** |
| 22 * A typed view of a sequence of bytes. |
| 23 */ |
| 24 abstract class TypedData { |
| 25 /** |
| 26 * Returns the number of bytes in the representation of each element in this |
| 27 * list. |
| 28 */ |
| 29 int get elementSizeInBytes; |
| 30 |
| 31 /** |
| 32 * Returns the offset in bytes into the underlying byte buffer of this view. |
| 33 */ |
| 34 int get offsetInBytes; |
| 35 |
| 36 /** |
| 37 * Returns the length of this view, in bytes. |
| 38 */ |
| 39 int get lengthInBytes; |
| 40 |
| 41 /** |
| 42 * Returns the byte buffer associated with this object. |
| 43 */ |
| 44 ByteBuffer get buffer; |
| 45 } |
| 46 |
| 47 |
| 48 /** |
| 49 * A fixed-length, random-access sequence of bytes that also provides random |
| 50 * and unaligned access to the fixed-width integers and floating point |
| 51 * numbers represented by those bytes. |
| 52 * ByteData may be used to pack and unpack data from external sources |
| 53 * (such as networks or files systems), and to process large quantities |
| 54 * of numerical data more efficiently than would be possible |
| 55 * with ordinary [List] implementations. ByteData can save space, by |
| 56 * eliminating the need for object headers, and time, by eliminating the |
| 57 * need for data copies. Finally, ByteData may be used to intentionally |
| 58 * reinterpret the bytes representing one arithmetic type as another. |
| 59 * For example this code fragment determine what 32-bit signed integer |
| 60 * is represented by the bytes of a 32-bit floating point number: |
| 61 * |
| 62 * var buffer = new Uint8List(8).buffer; |
| 63 * var bdata = new ByteData.view(buffer); |
| 64 * bdata.setFloat32(0, 3.04); |
| 65 * int huh = bdata.getInt32(0); |
| 66 */ |
| 67 abstract class ByteData implements TypedData { |
| 68 /** |
| 69 * Creates a [ByteData] of the specified length (in elements), all of |
| 70 * whose elements are initially zero. |
| 71 */ |
| 72 external factory ByteData(int length); |
| 73 |
| 74 /** |
| 75 * Creates an [ByteData] _view_ of the specified region in the specified |
| 76 * byte buffer. Changes in the [ByteData] will be visible in the byte |
| 77 * buffer and vice versa. If the [offsetInBytes] index of the region is not |
| 78 * specified, it defaults to zero (the first byte in the byte buffer). |
| 79 * If the length is not specified, it defaults to null, which indicates |
| 80 * that the view extends to the end of the byte buffer. |
| 81 * |
| 82 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or |
| 83 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than |
| 84 * the length of [buffer]. |
| 85 */ |
| 86 external factory ByteData.view(ByteBuffer buffer, |
| 87 [int offsetInBytes = 0, int length]); |
| 88 |
| 89 /** |
| 90 * Returns the (possibly negative) integer represented by the byte at the |
| 91 * specified [byteOffset] in this object, in two's complement binary |
| 92 * representation. The return value will be between -128 and 127, inclusive. |
| 93 * |
| 94 * Throws [RangeError] if [byteOffset] is negative, or |
| 95 * greater than or equal to the length of this object. |
| 96 */ |
| 97 int getInt8(int byteOffset); |
| 98 |
| 99 /** |
| 100 * Sets the byte at the specified [byteOffset] in this object to the |
| 101 * two's complement binary representation of the specified [value], which |
| 102 * must fit in a single byte. In other words, [value] must be between |
| 103 * -128 and 127, inclusive. |
| 104 * |
| 105 * Throws [RangeError] if [byteOffset] is negative, or |
| 106 * greater than or equal to the length of this object. |
| 107 */ |
| 108 void setInt8(int byteOffset, int value); |
| 109 |
| 110 /** |
| 111 * Returns the positive integer represented by the byte at the specified |
| 112 * [byteOffset] in this object, in unsigned binary form. The |
| 113 * return value will be between 0 and 255, inclusive. |
| 114 * |
| 115 * Throws [RangeError] if [byteOffset] is negative, or |
| 116 * greater than or equal to the length of this object. |
| 117 */ |
| 118 int getUint8(int byteOffset); |
| 119 |
| 120 /** |
| 121 * Sets the byte at the specified [byteOffset] in this object to the |
| 122 * unsigned binary representation of the specified [value], which must fit |
| 123 * in a single byte. in other words, [value] must be between 0 and 255, |
| 124 * inclusive. |
| 125 * |
| 126 * Throws [RangeError] if [byteOffset] is negative, |
| 127 * or greater than or equal to the length of this object. |
| 128 */ |
| 129 void setUint8(int byteOffset, int value); |
| 130 |
| 131 /** |
| 132 * Returns the (possibly negative) integer represented by the two bytes at |
| 133 * the specified [byteOffset] in this object, in two's complement binary |
| 134 * form. |
| 135 * The return value will be between 2<sup>15</sup> and 2<sup>15</sup> - 1, |
| 136 * inclusive. |
| 137 * |
| 138 * Throws [RangeError] if [byteOffset] is negative, or |
| 139 * `byteOffset + 2` is greater than the length of this object. |
| 140 */ |
| 141 int getInt16(int byteOffset); |
| 142 |
| 143 /** |
| 144 * Sets the two bytes starting at the specified [byteOffset] in this |
| 145 * object to the two's complement binary representation of the specified |
| 146 * [value], which must fit in two bytes. In other words, [value] must lie |
| 147 * between 2<sup>15</sup> and 2<sup>15</sup> - 1, inclusive. |
| 148 * |
| 149 * Throws [RangeError] if [byteOffset] is negative, or |
| 150 * `byteOffset + 2` is greater than the length of this object. |
| 151 */ |
| 152 void setInt16(int byteOffset, int value); |
| 153 |
| 154 /** |
| 155 * Returns the positive integer represented by the two bytes starting |
| 156 * at the specified [byteOffset] in this object, in unsigned binary |
| 157 * form. |
| 158 * The return value will be between 0 and 2<sup>16</sup> - 1, inclusive. |
| 159 * |
| 160 * Throws [RangeError] if [byteOffset] is negative, or |
| 161 * `byteOffset + 2` is greater than the length of this object. |
| 162 */ |
| 163 int getUint16(int byteOffset); |
| 164 |
| 165 /** |
| 166 * Sets the two bytes starting at the specified [byteOffset] in this object |
| 167 * to the unsigned binary representation of the specified [value], |
| 168 * which must fit in two bytes. in other words, [value] must be between |
| 169 * 0 and 2<sup>16</sup> - 1, inclusive. |
| 170 * |
| 171 * Throws [RangeError] if [byteOffset] is negative, or |
| 172 * `byteOffset + 2` is greater than the length of this object. |
| 173 */ |
| 174 void setUint16(int byteOffset, int value); |
| 175 |
| 176 /** |
| 177 * Returns the (possibly negative) integer represented by the four bytes at |
| 178 * the specified [byteOffset] in this object, in two's complement binary |
| 179 * form. |
| 180 * The return value will be between 2<sup>31</sup> and 2<sup>31</sup> - 1, |
| 181 * inclusive. |
| 182 * |
| 183 * Throws [RangeError] if [byteOffset] is negative, or |
| 184 * `byteOffset + 4` is greater than the length of this object. |
| 185 */ |
| 186 int getInt32(int byteOffset); |
| 187 |
| 188 /** |
| 189 * Sets the four bytes starting at the specified [byteOffset] in this |
| 190 * object to the two's complement binary representation of the specified |
| 191 * [value], which must fit in four bytes. In other words, [value] must lie |
| 192 * between 2<sup>31</sup> and 2<sup>31</sup> - 1, inclusive. |
| 193 * |
| 194 * Throws [RangeError] if [byteOffset] is negative, or |
| 195 * `byteOffset + 4` is greater than the length of this object. |
| 196 */ |
| 197 void setInt32(int byteOffset, int value); |
| 198 |
| 199 /** |
| 200 * Returns the positive integer represented by the four bytes starting |
| 201 * at the specified [byteOffset] in this object, in unsigned binary |
| 202 * form. |
| 203 * The return value will be between 0 and 2<sup>32</sup> - 1, inclusive. |
| 204 * |
| 205 */ |
| 206 int getUint32(int byteOffset); |
| 207 |
| 208 /** |
| 209 * Sets the four bytes starting at the specified [byteOffset] in this object |
| 210 * to the unsigned binary representation of the specified [value], |
| 211 * which must fit in four bytes. in other words, [value] must be between |
| 212 * 0 and 2<sup>32</sup> - 1, inclusive. |
| 213 * |
| 214 * Throws [RangeError] if [byteOffset] is negative, or |
| 215 * `byteOffset + 4` is greater than the length of this object. |
| 216 */ |
| 217 void setUint32(int byteOffset, int value); |
| 218 |
| 219 /** |
| 220 * Returns the (possibly negative) integer represented by the eight bytes at |
| 221 * the specified [byteOffset] in this object, in two's complement binary |
| 222 * form. |
| 223 * The return value will be between 2<sup>63</sup> and 2<sup>63</sup> - 1, |
| 224 * inclusive. |
| 225 * |
| 226 * Throws [RangeError] if [byteOffset] is negative, or |
| 227 * `byteOffset + 8` is greater than the length of this object. |
| 228 */ |
| 229 int getInt64(int byteOffset); |
| 230 |
| 231 /** |
| 232 * Sets the eight bytes starting at the specified [byteOffset] in this |
| 233 * object to the two's complement binary representation of the specified |
| 234 * [value], which must fit in eight bytes. In other words, [value] must lie |
| 235 * between 2<sup>63</sup> and 2<sup>63</sup> - 1, inclusive. |
| 236 * |
| 237 * Throws [RangeError] if [byteOffset] is negative, or |
| 238 * `byteOffset + 8` is greater than the length of this object. |
| 239 */ |
| 240 void setInt64(int byteOffset, int value); |
| 241 |
| 242 /** |
| 243 * Returns the positive integer represented by the eight bytes starting |
| 244 * at the specified [byteOffset] in this object, in unsigned binary |
| 245 * form. |
| 246 * The return value will be between 0 and 2<sup>64</sup> - 1, inclusive. |
| 247 * |
| 248 * Throws [RangeError] if [byteOffset] is negative, or |
| 249 * `byteOffset + 8` is greater than the length of this object. |
| 250 */ |
| 251 int getUint64(int byteOffset); |
| 252 |
| 253 /** |
| 254 * Sets the eight bytes starting at the specified [byteOffset] in this object |
| 255 * to the unsigned binary representation of the specified [value], |
| 256 * which must fit in eight bytes. in other words, [value] must be between |
| 257 * 0 and 2<sup>64</sup> - 1, inclusive. |
| 258 * |
| 259 * Throws [RangeError] if [byteOffset] is negative, or |
| 260 * `byteOffset + 8` is greater than the length of this object. |
| 261 */ |
| 262 void setUint64(int byteOffset, int value); |
| 263 |
| 264 /** |
| 265 * Returns the floating point number represented by the four bytes at |
| 266 * the specified [byteOffset] in this object, in IEEE 754 |
| 267 * single-precision binary floating-point format (binary32). |
| 268 * |
| 269 * Throws [RangeError] if [byteOffset] is negative, or |
| 270 * `byteOffset + 4` is greater than the length of this object. |
| 271 */ |
| 272 double getFloat32(int byteOffset); |
| 273 |
| 274 /** |
| 275 * Sets the four bytes starting at the specified [byteOffset] in this |
| 276 * object to the IEEE 754 single-precision binary floating-point |
| 277 * (binary32) representation of the specified [value]. |
| 278 * |
| 279 * **Note that this method can lose precision.** The input [value] is |
| 280 * a 64-bit floating point value, which will be converted to 32-bit |
| 281 * floating point value by IEEE 754 rounding rules before it is stored. |
| 282 * If [value] cannot be represented exactly as a binary32, it will be |
| 283 * converted to the nearest binary32 value. If two binary32 values are |
| 284 * equally close, the one whose least significant bit is zero will be used. |
| 285 * Note that finite (but large) values can be converted to infinity, and |
| 286 * small non-zero values can be converted to zero. |
| 287 * |
| 288 * Throws [RangeError] if [byteOffset] is negative, or |
| 289 * `byteOffset + 4` is greater than the length of this object. |
| 290 */ |
| 291 void setFloat32(int byteOffset, double value); |
| 292 |
| 293 /** |
| 294 * Returns the floating point number represented by the eight bytes at |
| 295 * the specified [byteOffset] in this object, in IEEE 754 |
| 296 * double-precision binary floating-point format (binary64). |
| 297 * |
| 298 * Throws [RangeError] if [byteOffset] is negative, or |
| 299 * `byteOffset + 8` is greater than the length of this object. |
| 300 */ |
| 301 double getFloat64(int byteOffset); |
| 302 |
| 303 /** |
| 304 * Sets the eight bytes starting at the specified [byteOffset] in this |
| 305 * object to the IEEE 754 double-precision binary floating-point |
| 306 * (binary64) representation of the specified [value]. |
| 307 * |
| 308 * Throws [RangeError] if [byteOffset] is negative, or |
| 309 * `byteOffset + 8` is greater than the length of this object. |
| 310 */ |
| 311 void setFloat64(int byteOffset, double value); |
| 312 } |
| 313 |
| 314 |
| 315 /** |
| 316 * A fixed-length list of 8-bit signed integers. |
| 317 * For long lists, this implementation can be considerably |
| 318 * more space- and time-efficient than the default [List] implementation. |
| 319 */ |
| 320 abstract class Int8List implements List<int>, TypedData { |
| 321 /** |
| 322 * Creates an [Int8List] of the specified length (in elements), all of |
| 323 * whose elements are initially zero. |
| 324 */ |
| 325 external factory Int8List(int length); |
| 326 |
| 327 /** |
| 328 * Creates an [Int8List] _view_ of the specified region in the specified |
| 329 * byte buffer. Changes in the [Int8List] will be visible in the byte |
| 330 * buffer and vice versa. If the [offsetInBytes] index of the region is not |
| 331 * specified, it defaults to zero (the first byte in the byte buffer). |
| 332 * If the length is not specified, it defaults to null, which indicates |
| 333 * that the view extends to the end of the byte buffer. |
| 334 * |
| 335 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or |
| 336 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than |
| 337 * the length of [buffer]. |
| 338 */ |
| 339 external factory Int8List.view(ByteBuffer buffer, |
| 340 [int offsetInBytes = 0, int length]); |
| 341 |
| 342 static const int BYTES_PER_ELEMENT = 1; |
| 343 } |
| 344 |
| 345 |
| 346 /** |
| 347 * A fixed-length list of 8-bit unsigned integers. |
| 348 * For long lists, this implementation can be considerably |
| 349 * more space- and time-efficient than the default [List] implementation. |
| 350 */ |
| 351 abstract class Uint8List implements List<int>, TypedData { |
| 352 /** |
| 353 * Creates a [Uint8List] of the specified length (in elements), all of |
| 354 * whose elements are initially zero. |
| 355 */ |
| 356 external factory Uint8List(int length); |
| 357 |
| 358 /** |
| 359 * Creates a [Uint8List] _view_ of the specified region in the specified |
| 360 * byte buffer. Changes in the [Uint8List] will be visible in the byte |
| 361 * buffer and vice versa. If the [offsetInBytes] index of the region is not |
| 362 * specified, it defaults to zero (the first byte in the byte buffer). |
| 363 * If the length is not specified, it defaults to null, which indicates |
| 364 * that the view extends to the end of the byte buffer. |
| 365 * |
| 366 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or |
| 367 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than |
| 368 * the length of [buffer]. |
| 369 */ |
| 370 external factory Uint8List.view(ByteBuffer buffer, |
| 371 [int offsetInBytes = 0, int length]); |
| 372 |
| 373 static const int BYTES_PER_ELEMENT = 1; |
| 374 } |
| 375 |
| 376 |
| 377 /** |
| 378 * A fixed-length list of 8-bit unsigned integers. |
| 379 * For long lists, this implementation can be considerably |
| 380 * more space- and time-efficient than the default [List] implementation. |
| 381 * Indexed store clamps the value to range 0..0xFF. |
| 382 */ |
| 383 abstract class Uint8ClampedList implements List<int>, TypedData { |
| 384 /** |
| 385 * Creates a [Uint8ClampedList] of the specified length (in elements), all of |
| 386 * whose elements are initially zero. |
| 387 */ |
| 388 external factory Uint8ClampedList(int length); |
| 389 |
| 390 /** |
| 391 * Creates a [Uint8ClampedList] _view_ of the specified region in the |
| 392 * specified byte [buffer]. Changes in the [Uint8List] will be visible in the |
| 393 * byte buffer and vice versa. If the [offsetInBytes] index of the region is |
| 394 * not specified, it defaults to zero (the first byte in the byte buffer). |
| 395 * If the length is not specified, it defaults to null, which indicates that |
| 396 * the view extends to the end of the byte buffer. |
| 397 * |
| 398 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or |
| 399 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than |
| 400 * the length of [buffer]. |
| 401 */ |
| 402 external factory Uint8ClampedList.view(ByteBuffer buffer, |
| 403 [int offsetInBytes = 0, int length]); |
| 404 |
| 405 static const int BYTES_PER_ELEMENT = 1; |
| 406 } |
| 407 |
| 408 |
| 409 /** |
| 410 * A fixed-length list of 16-bit signed integers that is viewable as a |
| 411 * [TypedData]. For long lists, this implementation can be considerably |
| 412 * more space- and time-efficient than the default [List] implementation. |
| 413 */ |
| 414 abstract class Int16List implements List<int>, TypedData { |
| 415 /** |
| 416 * Creates an [Int16List] of the specified length (in elements), all of |
| 417 * whose elements are initially zero. |
| 418 */ |
| 419 external factory Int16List(int length); |
| 420 |
| 421 /** |
| 422 * Creates an [Int16List] _view_ of the specified region in the specified |
| 423 * byte buffer. Changes in the [Int16List] will be visible in the byte |
| 424 * buffer and vice versa. If the [offsetInBytes] index of the region is not |
| 425 * specified, it defaults to zero (the first byte in the byte buffer). |
| 426 * If the length is not specified, it defaults to null, which indicates |
| 427 * that the view extends to the end of the byte buffer. |
| 428 * |
| 429 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or |
| 430 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than |
| 431 * the length of [buffer]. |
| 432 * |
| 433 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of |
| 434 * BYTES_PER_ELEMENT. |
| 435 */ |
| 436 external factory Int16List.view(ByteBuffer buffer, |
| 437 [int offsetInBytes = 0, int length]); |
| 438 |
| 439 static const int BYTES_PER_ELEMENT = 2; |
| 440 } |
| 441 |
| 442 |
| 443 /** |
| 444 * A fixed-length list of 16-bit unsigned integers that is viewable as a |
| 445 * [TypedData]. For long lists, this implementation can be considerably |
| 446 * more space- and time-efficient than the default [List] implementation. |
| 447 */ |
| 448 abstract class Uint16List implements List<int>, TypedData { |
| 449 /** |
| 450 * Creates a [Uint16List] of the specified length (in elements), all |
| 451 * of whose elements are initially zero. |
| 452 */ |
| 453 external factory Uint16List(int length); |
| 454 |
| 455 /** |
| 456 * Creates a [Uint16List] _view_ of the specified region in |
| 457 * the specified byte buffer. Changes in the [Uint16List] will be |
| 458 * visible in the byte buffer and vice versa. If the [offsetInBytes] index |
| 459 * of the region is not specified, it defaults to zero (the first byte in |
| 460 * the byte buffer). If the length is not specified, it defaults to null, |
| 461 * which indicates that the view extends to the end of the byte buffer. |
| 462 * |
| 463 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or |
| 464 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than |
| 465 * the length of [buffer]. |
| 466 * |
| 467 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of |
| 468 * BYTES_PER_ELEMENT. |
| 469 */ |
| 470 external factory Uint16List.view(ByteBuffer buffer, |
| 471 [int offsetInBytes = 0, int length]); |
| 472 |
| 473 static const int BYTES_PER_ELEMENT = 2; |
| 474 } |
| 475 |
| 476 |
| 477 /** |
| 478 * A fixed-length list of 32-bit signed integers that is viewable as a |
| 479 * [TypedData]. For long lists, this implementation can be considerably |
| 480 * more space- and time-efficient than the default [List] implementation. |
| 481 */ |
| 482 abstract class Int32List implements List<int>, TypedData { |
| 483 /** |
| 484 * Creates an [Int32List] of the specified length (in elements), all of |
| 485 * whose elements are initially zero. |
| 486 */ |
| 487 external factory Int32List(int length); |
| 488 |
| 489 /** |
| 490 * Creates an [Int32List] _view_ of the specified region in the specified |
| 491 * byte buffer. Changes in the [Int32List] will be visible in the byte |
| 492 * buffer and vice versa. If the [offsetInBytes] index of the region is not |
| 493 * specified, it defaults to zero (the first byte in the byte buffer). |
| 494 * If the length is not specified, it defaults to null, which indicates |
| 495 * that the view extends to the end of the byte buffer. |
| 496 * |
| 497 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or |
| 498 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than |
| 499 * the length of [buffer]. |
| 500 * |
| 501 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of |
| 502 * BYTES_PER_ELEMENT. |
| 503 */ |
| 504 external factory Int32List.view(ByteBuffer buffer, |
| 505 [int offsetInBytes = 0, int length]); |
| 506 |
| 507 static const int BYTES_PER_ELEMENT = 4; |
| 508 } |
| 509 |
| 510 |
| 511 /** |
| 512 * A fixed-length list of 32-bit unsigned integers that is viewable as a |
| 513 * [TypedData]. For long lists, this implementation can be considerably |
| 514 * more space- and time-efficient than the default [List] implementation. |
| 515 */ |
| 516 abstract class Uint32List implements List<int>, TypedData { |
| 517 /** |
| 518 * Creates a [Uint32List] of the specified length (in elements), all |
| 519 * of whose elements are initially zero. |
| 520 */ |
| 521 external factory Uint32List(int length); |
| 522 |
| 523 /** |
| 524 * Creates a [Uint32List] _view_ of the specified region in |
| 525 * the specified byte buffer. Changes in the [Uint32] will be |
| 526 * visible in the byte buffer and vice versa. If the [offsetInBytes] index |
| 527 * of the region is not specified, it defaults to zero (the first byte in |
| 528 * the byte buffer). If the length is not specified, it defaults to null, |
| 529 * which indicates that the view extends to the end of the byte buffer. |
| 530 * |
| 531 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or |
| 532 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than |
| 533 * the length of [buffer]. |
| 534 * |
| 535 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of |
| 536 * BYTES_PER_ELEMENT. |
| 537 */ |
| 538 external factory Uint32List.view(ByteBuffer buffer, |
| 539 [int offsetInBytes = 0, int length]); |
| 540 |
| 541 static const int BYTES_PER_ELEMENT = 4; |
| 542 } |
| 543 |
| 544 |
| 545 /** |
| 546 * A fixed-length list of 64-bit signed integers that is viewable as a |
| 547 * [TypedData]. For long lists, this implementation can be considerably |
| 548 * more space- and time-efficient than the default [List] implementation. |
| 549 */ |
| 550 abstract class Int64List implements List<int>, TypedData { |
| 551 /** |
| 552 * Creates an [Int64List] of the specified length (in elements), all of |
| 553 * whose elements are initially zero. |
| 554 */ |
| 555 external factory Int64List(int length); |
| 556 |
| 557 /** |
| 558 * Creates an [Int64List] _view_ of the specified region in the specified |
| 559 * byte buffer. Changes in the [Int64List] will be visible in the byte buffer |
| 560 * and vice versa. If the [offsetInBytes] index of the region is not |
| 561 * specified, it defaults to zero (the first byte in the byte buffer). |
| 562 * If the length is not specified, it defaults to null, which indicates that |
| 563 * the view extends to the end of the byte buffer. |
| 564 * |
| 565 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or |
| 566 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than |
| 567 * the length of [buffer]. |
| 568 * |
| 569 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of |
| 570 * BYTES_PER_ELEMENT. |
| 571 */ |
| 572 external factory Int64List.view(ByteBuffer buffer, |
| 573 [int offsetInBytes = 0, int length]); |
| 574 |
| 575 static const int BYTES_PER_ELEMENT = 8; |
| 576 } |
| 577 |
| 578 |
| 579 /** |
| 580 * A fixed-length list of 64-bit unsigned integers that is viewable as a |
| 581 * [TypedData]. For long lists, this implementation can be considerably |
| 582 * more space- and time-efficient than the default [List] implementation. |
| 583 */ |
| 584 abstract class Uint64List implements List<int>, TypedData { |
| 585 /** |
| 586 * Creates a [Uint64List] of the specified length (in elements), all |
| 587 * of whose elements are initially zero. |
| 588 */ |
| 589 external factory Uint64List(int length); |
| 590 |
| 591 /** |
| 592 * Creates an [Uint64List] _view_ of the specified region in |
| 593 * the specified byte buffer. Changes in the [Uint64List] will be |
| 594 * visible in the byte buffer and vice versa. If the [offsetInBytes] |
| 595 * index of the region is not specified, it defaults to zero (the first |
| 596 * byte in the byte buffer). If the length is not specified, it defaults |
| 597 * to null, which indicates that the view extends to the end of the byte |
| 598 * buffer. |
| 599 * |
| 600 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or |
| 601 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than |
| 602 * the length of [buffer]. |
| 603 * |
| 604 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of |
| 605 * BYTES_PER_ELEMENT. |
| 606 */ |
| 607 external factory Uint64List.view(ByteBuffer buffer, |
| 608 [int offsetInBytes = 0, int length]); |
| 609 |
| 610 static const int BYTES_PER_ELEMENT = 8; |
| 611 } |
| 612 |
| 613 |
| 614 /** |
| 615 * A fixed-length list of IEEE 754 single-precision binary floating-point |
| 616 * numbers that is viewable as a [TypedData]. For long lists, this |
| 617 * implementation can be considerably more space- and time-efficient than |
| 618 * the default [List] implementation. |
| 619 */ |
| 620 abstract class Float32List implements List<double>, TypedData { |
| 621 /** |
| 622 * Creates a [Float32List] of the specified length (in elements), all of |
| 623 * whose elements are initially zero. |
| 624 */ |
| 625 external factory Float32List(int length); |
| 626 |
| 627 /** |
| 628 * Creates a [Float32List] _view_ of the specified region in the specified |
| 629 * byte buffer. Changes in the [Float32List] will be visible in the byte |
| 630 * buffer and vice versa. If the [offsetInBytes] index of the region is not |
| 631 * specified, it defaults to zero (the first byte in the byte buffer). |
| 632 * If the length is not specified, it defaults to null, which indicates |
| 633 * that the view extends to the end of the byte buffer. |
| 634 * |
| 635 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or |
| 636 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than |
| 637 * the length of [buffer]. |
| 638 * |
| 639 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of |
| 640 * BYTES_PER_ELEMENT. |
| 641 */ |
| 642 external factory Float32List.view(ByteBuffer buffer, |
| 643 [int offsetInBytes = 0, int length]); |
| 644 |
| 645 static const int BYTES_PER_ELEMENT = 4; |
| 646 } |
| 647 |
| 648 |
| 649 /** |
| 650 * A fixed-length list of IEEE 754 double-precision binary floating-point |
| 651 * numbers that is viewable as a [TypedData]. For long lists, this |
| 652 * implementation can be considerably more space- and time-efficient than |
| 653 * the default [List] implementation. |
| 654 */ |
| 655 abstract class Float64List implements List<double>, TypedData { |
| 656 /** |
| 657 * Creates a [Float64List] of the specified length (in elements), all of |
| 658 * whose elements are initially zero. |
| 659 */ |
| 660 external factory Float64List(int length); |
| 661 |
| 662 /** |
| 663 * Creates a [Float64List] _view_ of the specified region in the specified |
| 664 * byte buffer. Changes in the [Float64List] will be visible in the byte |
| 665 * buffer and vice versa. If the [offsetInBytes] index of the region is not |
| 666 * specified, it defaults to zero (the first byte in the byte buffer). |
| 667 * If the length is not specified, it defaults to null, which indicates |
| 668 * that the view extends to the end of the byte buffer. |
| 669 * |
| 670 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or |
| 671 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than |
| 672 * the length of [buffer]. |
| 673 * |
| 674 * Throws [ArgumentError] if [offsetInBytes] is not a multiple of |
| 675 * BYTES_PER_ELEMENT. |
| 676 */ |
| 677 external factory Float64List.view(ByteBuffer buffer, |
| 678 [int offsetInBytes = 0, int length]); |
| 679 |
| 680 static const int BYTES_PER_ELEMENT = 8; |
| 681 } |
| OLD | NEW |