| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** |
| 6 * A random-access sequence of bytes that also provides random access to |
| 7 * the fixed-width integers and floating point numbers represented by |
| 8 * those bytes. Byte arrays may be used to pack and unpack data from |
| 9 * external sources (such as networks or files systems), and to process |
| 10 * large quantities of numerical data more efficiently than would be possible |
| 11 * with ordinary [List] implementations. Byte arrays can save space, by |
| 12 * eliminating the need for object headers, and time, by eliminating the |
| 13 * need for data copies. Finally, Byte arrays may be used to intentionally |
| 14 * reinterpret the bytes representing one arithmetic type as another. |
| 15 * For example this code fragment determine what 64-bit signed integer |
| 16 * is represented by the bytes of a 64-bit floating point number: |
| 17 * |
| 18 * var ba = new ByteArray(8); |
| 19 * ba.setFloat64(0, 3.14159265358979323846); |
| 20 * int huh = ba.getInt64(0); |
| 21 */ |
| 5 interface ByteArray { | 22 interface ByteArray { |
| 23 /** |
| 24 * Returns the length of this byte array, in bytes. |
| 25 */ |
| 6 int lengthInBytes(); | 26 int lengthInBytes(); |
| 7 | 27 |
| 28 /** |
| 29 * Returns a [ByteArray] _view_ of a portion of this byte array. |
| 30 * The returned byte array consists of [length] bytes starting |
| 31 * at position [start] in this byte array. The returned byte array |
| 32 * is backed by the same data as this byte array. In other words, |
| 33 * changes to the returned byte array are visible in this byte array |
| 34 * and vice-versa. |
| 35 * |
| 36 * Throws [IndexOutOfRangeException] if [start] is negative, or if |
| 37 * `start + length` is greater than the length of this byte array. |
| 38 * |
| 39 * Throws [IllegalArgumentException] if [length] is negative. |
| 40 */ |
| 8 ByteArray subByteArray([int start, int length]); | 41 ByteArray subByteArray([int start, int length]); |
| 9 | 42 |
| 43 /** |
| 44 * Returns the (possibly negative) integer represented by the byte at the |
| 45 * specified [byteOffset] in this byte array, in two's complement binary |
| 46 * representation. The return value will be between -128 and 127, inclusive. |
| 47 * |
| 48 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 49 * greater than or equal to the length of this byte array. |
| 50 */ |
| 10 int getInt8(int byteOffset); | 51 int getInt8(int byteOffset); |
| 11 | 52 |
| 12 void setInt8(int byteOffset, int value); | 53 /** |
| 13 | 54 * Sets the byte at the specified [byteOffset] in this byte array to the |
| 55 * two's complement binary representation of the specified [value], which |
| 56 * must fit in a single byte. In other words, [value] must be between |
| 57 * -128 and 127, inclusive. |
| 58 * |
| 59 * Returns `byteOffset + 1`, which is the offset of the first byte in the |
| 60 * array after the byte that was set by this call. This return value can |
| 61 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. |
| 62 * |
| 63 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 64 * greater than or equal to the length of this byte array. |
| 65 * |
| 66 * Throws [IllegalArgumentException] if [value] is less than -128 or |
| 67 * greater than 127. |
| 68 */ |
| 69 int setInt8(int byteOffset, int value); |
| 70 |
| 71 /** |
| 72 * Returns the positive integer represented by the byte at the specified |
| 73 * [byteOffset] in this byte array, in unsigned binary form. The |
| 74 * return value will be between 0 and 255, inclusive. |
| 75 * |
| 76 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 77 * greater than or equal to the length of this byte array. |
| 78 */ |
| 14 int getUint8(int byteOffset); | 79 int getUint8(int byteOffset); |
| 15 | 80 |
| 16 void setUint8(int byteOffset, int value); | 81 /** |
| 17 | 82 * Sets the byte at the specified [byteOffset] in this byte array to the |
| 83 * unsigned binary representation of the specified [value], which must fit |
| 84 * in a single byte. in other words, [value] must be between 0 and 255, |
| 85 * inclusive. |
| 86 * |
| 87 * Returns `byteOffset + 1`, which is the offset of the first byte in the |
| 88 * array after the byte that was set by this call. This return value can |
| 89 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. |
| 90 * |
| 91 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, |
| 92 * or greater than or equal to the length of this byte array. |
| 93 * |
| 94 * Throws [IllegalArgumentException] if [value] is negative or |
| 95 * greater than 255. |
| 96 */ |
| 97 int setUint8(int byteOffset, int value); |
| 98 |
| 99 /** |
| 100 * Returns the (possibly negative) integer represented by the two bytes at |
| 101 * the specified [byteOffset] in this byte array, in two's complement binary |
| 102 * form. The return value will be between 2<sup>15</sup> and 2<sup>15 - 1, |
| 103 * inclusive. |
| 104 * |
| 105 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 106 * `byteOffset + 2` is greater than the length of this byte array. |
| 107 */ |
| 18 int getInt16(int byteOffset); | 108 int getInt16(int byteOffset); |
| 19 | 109 |
| 20 void setInt16(int byteOffset, int value); | 110 /** |
| 21 | 111 * Sets the two bytes starting at the specified [byteOffset] in this |
| 112 * byte array to the two's complement binary representation of the specified |
| 113 * [value], which must fit in two bytes. In other words, [value] must lie |
| 114 * between 2<sup>15</sup> and 2<sup>15 - 1, inclusive. |
| 115 * |
| 116 * Returns `byteOffset + 2`, which is the offset of the first byte in the |
| 117 * array after the last byte that was set by this call. This return value can |
| 118 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. |
| 119 * |
| 120 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 121 * `byteOffset + 2` is greater than the length of this byte array. |
| 122 * |
| 123 * Throws [IllegalArgumentException] if [value] is less than 2<sup>15</sup> |
| 124 * or greater than 2<sup>15 - 1. |
| 125 */ |
| 126 int setInt16(int byteOffset, int value); |
| 127 |
| 128 /** |
| 129 * Returns the positive integer represented by the two bytes starting |
| 130 * at the specified [byteOffset] in this byte array, in unsigned binary |
| 131 * form. The return value will be between 0 and 2<sup>16 - 1, inclusive. |
| 132 * |
| 133 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 134 * `byteOffset + 2` is greater than the length of this byte array. |
| 135 */ |
| 22 int getUint16(int byteOffset); | 136 int getUint16(int byteOffset); |
| 23 | 137 |
| 24 void setUint16(int byteOffset, int value); | 138 /** |
| 25 | 139 * Sets the two bytes starting at the specified [byteOffset] in this byte |
| 140 * array to the unsigned binary representation of the specified [value], |
| 141 * which must fit in two bytes. in other words, [value] must be between |
| 142 * 0 and 2<sup>16 - 1, inclusive. |
| 143 * |
| 144 * Returns `byteOffset + 2`, which is the offset of the first byte in the |
| 145 * array after the last byte that was set by this call. This return value can |
| 146 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. |
| 147 * |
| 148 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 149 * `byteOffset + 2` is greater than the length of this byte array. |
| 150 * |
| 151 * Throws [IllegalArgumentException] if [value] is negative or |
| 152 * greater than 2<sup>16 - 1. |
| 153 */ |
| 154 int setUint16(int byteOffset, int value); |
| 155 |
| 156 /** |
| 157 * Returns the (possibly negative) integer represented by the four bytes at |
| 158 * the specified [byteOffset] in this byte array, in two's complement binary |
| 159 * form. The return value will be between 2<sup>31</sup> and 2<sup>31 - 1, |
| 160 * inclusive. |
| 161 * |
| 162 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 163 * `byteOffset + 4` is greater than the length of this byte array. |
| 164 */ |
| 26 int getInt32(int byteOffset); | 165 int getInt32(int byteOffset); |
| 27 | 166 |
| 28 void setInt32(int byteOffset, int value); | 167 /** |
| 29 | 168 * Sets the four bytes starting at the specified [byteOffset] in this |
| 169 * byte array to the two's complement binary representation of the specified |
| 170 * [value], which must fit in four bytes. In other words, [value] must lie |
| 171 * between 2<sup>31</sup> and 2<sup>31 - 1, inclusive. |
| 172 * |
| 173 * Returns `byteOffset + 4`, which is the offset of the first byte in the |
| 174 * array after the last byte that was set by this call. This return value can |
| 175 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. |
| 176 * |
| 177 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 178 * `byteOffset + 4` is greater than the length of this byte array. |
| 179 * |
| 180 * Throws [IllegalArgumentException] if [value] is less than 2<sup>31</sup> |
| 181 * or greater than 2<sup>31 - 1. |
| 182 */ |
| 183 int setInt32(int byteOffset, int value); |
| 184 |
| 185 /** |
| 186 * Returns the positive integer represented by the four bytes starting |
| 187 * at the specified [byteOffset] in this byte array, in unsigned binary |
| 188 * form. The return value will be between 0 and 2<sup>32 - 1, inclusive. |
| 189 * |
| 190 */ |
| 30 int getUint32(int byteOffset); | 191 int getUint32(int byteOffset); |
| 31 | 192 |
| 32 void setUint32(int byteOffset, int value); | 193 /** |
| 33 | 194 * Sets the four bytes starting at the specified [byteOffset] in this byte |
| 195 * array to the unsigned binary representation of the specified [value], |
| 196 * which must fit in four bytes. in other words, [value] must be between |
| 197 * 0 and 2<sup>32 - 1, inclusive. |
| 198 * |
| 199 * Returns `byteOffset + 4`, which is the offset of the first byte in the |
| 200 * array after the last byte that was set by this call. This return value can |
| 201 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. |
| 202 * |
| 203 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 204 * `byteOffset + 4` is greater than the length of this byte array. |
| 205 * |
| 206 * Throws [IllegalArgumentException] if [value] is negative or |
| 207 * greater than 2<sup>32 - 1. |
| 208 */ |
| 209 int setUint32(int byteOffset, int value); |
| 210 |
| 211 /** |
| 212 * Returns the (possibly negative) integer represented by the eight bytes at |
| 213 * the specified [byteOffset] in this byte array, in two's complement binary |
| 214 * form. The return value will be between 2<sup>63</sup> and 2<sup>63 - 1, |
| 215 * inclusive. |
| 216 * |
| 217 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 218 * `byteOffset + 8` is greater than the length of this byte array. |
| 219 */ |
| 34 int getInt64(int byteOffset); | 220 int getInt64(int byteOffset); |
| 35 | 221 |
| 36 void setInt64(int byteOffset, int value); | 222 /** |
| 37 | 223 * Sets the eight bytes starting at the specified [byteOffset] in this |
| 224 * byte array to the two's complement binary representation of the specified |
| 225 * [value], which must fit in eight bytes. In other words, [value] must lie |
| 226 * between 2<sup>63</sup> and 2<sup>63 - 1, inclusive. |
| 227 * |
| 228 * Returns `byteOffset + 8`, which is the offset of the first byte in the |
| 229 * array after the last byte that was set by this call. This return value can |
| 230 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. |
| 231 * |
| 232 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 233 * `byteOffset + 8` is greater than the length of this byte array. |
| 234 * |
| 235 * Throws [IllegalArgumentException] if [value] is less than 2<sup>63</sup> |
| 236 * or greater than 2<sup>63 - 1. |
| 237 */ |
| 238 int setInt64(int byteOffset, int value); |
| 239 |
| 240 /** |
| 241 * Returns the positive integer represented by the eight bytes starting |
| 242 * at the specified [byteOffset] in this byte array, in unsigned binary |
| 243 * form. The return value will be between 0 and 2<sup>64 - 1, inclusive. |
| 244 * |
| 245 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 246 * `byteOffset + 8` is greater than the length of this byte array. |
| 247 */ |
| 38 int getUint64(int byteOffset); | 248 int getUint64(int byteOffset); |
| 39 | 249 |
| 40 void setUint64(int byteOffset, int value); | 250 /** |
| 41 | 251 * Sets the eight bytes starting at the specified [byteOffset] in this byte |
| 252 * array to the unsigned binary representation of the specified [value], |
| 253 * which must fit in eight bytes. in other words, [value] must be between |
| 254 * 0 and 2<sup>64 - 1, inclusive. |
| 255 * |
| 256 * Returns `byteOffset + 8`, which is the offset of the first byte in the |
| 257 * array after the last byte that was set by this call. This return value can |
| 258 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. |
| 259 * |
| 260 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 261 * `byteOffset + 8` is greater than the length of this byte array. |
| 262 * |
| 263 * Throws [IllegalArgumentException] if [value] is negative or |
| 264 * greater than 2<sup>64 - 1. |
| 265 */ |
| 266 int setUint64(int byteOffset, int value); |
| 267 |
| 268 /** |
| 269 * Returns the floating point number represented by the four bytes at |
| 270 * the specified [byteOffset] in this byte array, in IEEE 754 |
| 271 * single-precision binary floating-point format (binary32). |
| 272 * |
| 273 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 274 * `byteOffset + 4` is greater than the length of this byte array. |
| 275 */ |
| 42 double getFloat32(int byteOffset); | 276 double getFloat32(int byteOffset); |
| 43 | 277 |
| 44 void setFloat32(int byteOffset, double value); | 278 /** |
| 45 | 279 * Sets the four bytes starting at the specified [byteOffset] in this |
| 280 * byte array to the IEEE 754 single-precision binary floating-point |
| 281 * (binary32) representation of the specified [value]. |
| 282 * |
| 283 * **Note that this method can lose precision.** The input [value] is |
| 284 * a 64-bit floating point value, which will be converted to 32-bit |
| 285 * floating point value by IEEE 754 rounding rules before it is stored. |
| 286 * If [value] cannot be represented exactly as a binary32, it will be |
| 287 * converted to the nearest binary32 value. If two binary32 values are |
| 288 * equally close, the one whose least significant bit is zero will be used. |
| 289 * Note that finite (but large) values can be converted to infinity, and |
| 290 * small non-zero values can be converted to zero. |
| 291 * |
| 292 * Returns `byteOffset + 4`, which is the offset of the first byte in the |
| 293 * array after the last byte that was set by this call. This return value can |
| 294 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. |
| 295 * |
| 296 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 297 * `byteOffset + 4` is greater than the length of this byte array. |
| 298 */ |
| 299 int setFloat32(int byteOffset, double value); |
| 300 |
| 301 /** |
| 302 * Returns the floating point number represented by the eight bytes at |
| 303 * the specified [byteOffset] in this byte array, in IEEE 754 |
| 304 * double-precision binary floating-point format (binary64). |
| 305 * |
| 306 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 307 * `byteOffset + 8` is greater than the length of this byte array. |
| 308 */ |
| 46 double getFloat64(int byteOffset); | 309 double getFloat64(int byteOffset); |
| 47 | 310 |
| 48 void setFloat64(int byteOffset, double value); | 311 /** |
| 49 } | 312 * Sets the eight bytes starting at the specified [byteOffset] in this |
| 50 | 313 * byte array to the IEEE 754 double-precision binary floating-point |
| 51 | 314 * (binary64) representation of the specified [value]. |
| 315 * |
| 316 * Returns `byteOffset + 8`, which is the offset of the first byte in the |
| 317 * array after the last byte that was set by this call. This return value can |
| 318 * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. |
| 319 * |
| 320 * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or |
| 321 * `byteOffset + 8` is greater than the length of this byte array. |
| 322 */ |
| 323 int setFloat64(int byteOffset, double value); |
| 324 } |
| 325 |
| 326 /** |
| 327 * A "mixin" interface that allows a type, typically but not necessarily |
| 328 * a [List], to be viewed as a [ByteArray]. |
| 329 */ |
| 52 interface ByteArrayViewable { | 330 interface ByteArrayViewable { |
| 331 /** |
| 332 * Returns the number of bytes in the representation of each element in |
| 333 * this list, or the number bytes in the representation of the entire |
| 334 * object if it is not a list. |
| 335 */ |
| 53 int bytesPerElement(); | 336 int bytesPerElement(); |
| 54 | 337 |
| 338 /** |
| 339 * Returns the length of this view, in bytes. |
| 340 */ |
| 55 int lengthInBytes(); | 341 int lengthInBytes(); |
| 56 | 342 |
| 343 /** |
| 344 * Returns the byte array view of this object. This view allows the |
| 345 * byte representation of the object to be read and written directly. |
| 346 */ |
| 57 ByteArray asByteArray([int start, int length]); | 347 ByteArray asByteArray([int start, int length]); |
| 58 } | 348 } |
| 59 | 349 |
| 60 | 350 |
| 351 /** |
| 352 * A fixed-length list of 8-bit signed integers that is viewable as a |
| 353 * [ByteArray]. For long lists, this implementation will be considerably |
| 354 * more space- and time-efficient than the default [List] implementation. |
| 355 */ |
| 61 interface Int8List extends List<int>, ByteArrayViewable | 356 interface Int8List extends List<int>, ByteArrayViewable |
| 62 default _Int8ArrayFactory { | 357 default _Int8ArrayFactory { |
| 358 /** |
| 359 * Creates an [Int8List] of the specified length (in elements), all of |
| 360 * whose elements are initially zero. |
| 361 */ |
| 63 Int8List(int length); | 362 Int8List(int length); |
| 363 |
| 364 /** |
| 365 * Creates an [Int8List] _view_ of the specified region in the specified |
| 366 * byte [array]. Changes in the [Int8List] will be visible in the byte |
| 367 * array and vice versa. If the [start] index of the region is not specified, |
| 368 * it defaults to zero (the first byte in the byte array). If the length is |
| 369 * not specified, it defaults to null, which indicates that the view extends |
| 370 * to the end of the byte array. |
| 371 */ |
| 64 Int8List.view(ByteArray array, [int start, int length]); | 372 Int8List.view(ByteArray array, [int start, int length]); |
| 65 } | 373 } |
| 66 | 374 |
| 67 | 375 |
| 376 /** |
| 377 * A fixed-length list of 8-bit unsigned integers that is viewable as a |
| 378 * [ByteArray]. For long lists, this implementation will be considerably |
| 379 * more space- and time-efficient than the default [List] implementation. |
| 380 */ |
| 68 interface Uint8List extends List<int>, ByteArrayViewable | 381 interface Uint8List extends List<int>, ByteArrayViewable |
| 69 default _Uint8ArrayFactory { | 382 default _Uint8ArrayFactory { |
| 383 /** |
| 384 * Creates a [Uint8List] of the specified length (in elements), all of |
| 385 * whose elements are initially zero. |
| 386 */ |
| 70 Uint8List(int length); | 387 Uint8List(int length); |
| 388 |
| 389 /** |
| 390 * Creates a [Uint8List] _view_ of the specified region in the specified |
| 391 * byte [array]. Changes in the [Uint8List] will be visible in the byte |
| 392 * array and vice versa. If the [start] index of the region is not specified, |
| 393 * it defaults to zero (the first byte in the byte array). If the length is |
| 394 * not specified, it defaults to null, which indicates that the view extends |
| 395 * to the end of the byte array. |
| 396 */ |
| 71 Uint8List.view(ByteArray array, [int start, int length]); | 397 Uint8List.view(ByteArray array, [int start, int length]); |
| 72 } | 398 } |
| 73 | 399 |
| 74 | 400 |
| 401 /** |
| 402 * A fixed-length list of 16-bit signed integers that is viewable as a |
| 403 * [ByteArray]. For long lists, this implementation will be considerably |
| 404 * more space- and time-efficient than the default [List] implementation. |
| 405 */ |
| 75 interface Int16List extends List<int>, ByteArrayViewable | 406 interface Int16List extends List<int>, ByteArrayViewable |
| 76 default _Int16ArrayFactory { | 407 default _Int16ArrayFactory { |
| 408 /** |
| 409 * Creates an [Int16List] of the specified length (in elements), all of |
| 410 * whose elements are initially zero. |
| 411 */ |
| 77 Int16List(int length); | 412 Int16List(int length); |
| 413 |
| 414 /** |
| 415 * Creates an [Int16List] _view_ of the specified region in the specified |
| 416 * byte [array]. Changes in the [Int16List] will be visible in the byte |
| 417 * array and vice versa. If the [start] index of the region is not specified, |
| 418 * it defaults to zero (the first byte in the byte array). If the length is |
| 419 * not specified, it defaults to null, which indicates that the view extends |
| 420 * to the end of the byte array. |
| 421 * |
| 422 * Throws [IllegalArgumentException] if the length of the specified region |
| 423 * is not divisible by 2 (the size of an "int16" in bytes), or if the |
| 424 * [start] of the region is not divisible by 2. If, however, [array] |
| 425 * is a view of another byte array, this constructor will throw |
| 426 * [IllegalArgumentException] if the implicit starting position in the |
| 427 * "ultimately backing" byte array is not divisible by 2. In plain terms, |
| 428 * this constructor throws [IllegalArgumentException] if the specified |
| 429 * region does not contain an integral number of "int16s," or if it |
| 430 * is not "int16-aligned." |
| 431 */ |
| 78 Int16List.view(ByteArray array, [int start, int length]); | 432 Int16List.view(ByteArray array, [int start, int length]); |
| 79 } | 433 } |
| 80 | 434 |
| 81 | 435 |
| 436 /** |
| 437 * A fixed-length list of 16-bit unsigned integers that is viewable as a |
| 438 * [ByteArray]. For long lists, this implementation will be considerably |
| 439 * more space- and time-efficient than the default [List] implementation. |
| 440 */ |
| 82 interface Uint16List extends List<int>, ByteArrayViewable | 441 interface Uint16List extends List<int>, ByteArrayViewable |
| 83 default _Uint16ArrayFactory { | 442 default _Uint16ArrayFactory { |
| 443 /** |
| 444 * Creates a [Uint16List] of the specified length (in elements), all |
| 445 * of whose elements are initially zero. |
| 446 */ |
| 84 Uint16List(int length); | 447 Uint16List(int length); |
| 448 |
| 449 /** |
| 450 * Creates a [Uint16List] _view_ of the specified region in |
| 451 * the specified byte [array]. Changes in the [Uint16List] will be |
| 452 * visible in the byte array and vice versa. If the [start] index of the |
| 453 * region is not specified, it defaults to zero (the first byte in the byte |
| 454 * array). If the length is not specified, it defaults to null, which |
| 455 * indicates that the view extends to the end of the byte array. |
| 456 * |
| 457 * Throws [IllegalArgumentException] if the length of the specified region |
| 458 * is not divisible by 2 (the size of a "uint16" in bytes), or if the |
| 459 * [start] of the region is not divisible by 2. If, however, [array] |
| 460 * is a view of another byte array, this constructor will throw |
| 461 * [IllegalArgumentException] if the implicit starting position in the |
| 462 * "ultimately backing" byte array is not divisible by 2. In plain terms, |
| 463 * this constructor throws [IllegalArgumentException] if the specified |
| 464 * region does not contain an integral number of "uint16s," or if it |
| 465 * is not "uint16-aligned." |
| 466 */ |
| 85 Uint16List.view(ByteArray array, [int start, int length]); | 467 Uint16List.view(ByteArray array, [int start, int length]); |
| 86 } | 468 } |
| 87 | 469 |
| 88 | 470 |
| 471 /** |
| 472 * A fixed-length list of 32-bit signed integers that is viewable as a |
| 473 * [ByteArray]. For long lists, this implementation will be considerably |
| 474 * more space- and time-efficient than the default [List] implementation. |
| 475 */ |
| 89 interface Int32List extends List<int>, ByteArrayViewable | 476 interface Int32List extends List<int>, ByteArrayViewable |
| 90 default _Int32ArrayFactory { | 477 default _Int32ArrayFactory { |
| 478 /** |
| 479 * Creates an [Int32List] of the specified length (in elements), all of |
| 480 * whose elements are initially zero. |
| 481 */ |
| 91 Int32List(int length); | 482 Int32List(int length); |
| 483 |
| 484 /** |
| 485 * Creates an [Int32List] _view_ of the specified region in the specified |
| 486 * byte [array]. Changes in the [Int32List] will be visible in the byte |
| 487 * array and vice versa. If the [start] index of the region is not specified, |
| 488 * it defaults to zero (the first byte in the byte array). If the length is |
| 489 * not specified, it defaults to null, which indicates that the view extends |
| 490 * to the end of the byte array. |
| 491 * |
| 492 * Throws [IllegalArgumentException] if the length of the specified region |
| 493 * is not divisible by 4 (the size of an "int32" in bytes), or if the |
| 494 * [start] of the region is not divisible by 4. If, however, [array] |
| 495 * is a view of another byte array, this constructor will throw |
| 496 * [IllegalArgumentException] if the implicit starting position in the |
| 497 * "ultimately backing" byte array is not divisible by 4. In plain terms, |
| 498 * this constructor throws [IllegalArgumentException] if the specified |
| 499 * region does not contain an integral number of "int32s," or if it |
| 500 * is not "int32-aligned." |
| 501 */ |
| 92 Int32List.view(ByteArray array, [int start, int length]); | 502 Int32List.view(ByteArray array, [int start, int length]); |
| 93 } | 503 } |
| 94 | 504 |
| 95 | 505 |
| 506 /** |
| 507 * A fixed-length list of 32-bit unsigned integers that is viewable as a |
| 508 * [ByteArray]. For long lists, this implementation will be considerably |
| 509 * more space- and time-efficient than the default [List] implementation. |
| 510 */ |
| 96 interface Uint32List extends List<int>, ByteArrayViewable | 511 interface Uint32List extends List<int>, ByteArrayViewable |
| 97 default _Uint32ArrayFactory { | 512 default _Uint32ArrayFactory { |
| 513 /** |
| 514 * Creates a [Uint32List] of the specified length (in elements), all |
| 515 * of whose elements are initially zero. |
| 516 */ |
| 98 Uint32List(int length); | 517 Uint32List(int length); |
| 518 |
| 519 /** |
| 520 * Creates a [Uint32List] _view_ of the specified region in |
| 521 * the specified byte [array]. Changes in the [Uint32] will be |
| 522 * visible in the byte array and vice versa. If the [start] index of the |
| 523 * region is not specified, it defaults to zero (the first byte in the byte |
| 524 * array). If the length is not specified, it defaults to null, which |
| 525 * indicates that the view extends to the end of the byte array. |
| 526 * |
| 527 * Throws [IllegalArgumentException] if the length of the specified region |
| 528 * is not divisible by 4 (the size of a "uint32" in bytes), or if the |
| 529 * [start] of the region is not divisible by 4. If, however, [array] |
| 530 * is a view of another byte array, this constructor will throw |
| 531 * [IllegalArgumentException] if the implicit starting position in the |
| 532 * "ultimately backing" byte array is not divisible by 4. In plain terms, |
| 533 * this constructor throws [IllegalArgumentException] if the specified |
| 534 * region does not contain an integral number of "uint32s," or if it |
| 535 * is not "uint32-aligned." |
| 536 */ |
| 99 Uint32List.view(ByteArray array, [int start, int length]); | 537 Uint32List.view(ByteArray array, [int start, int length]); |
| 100 | 538 } |
| 101 } | 539 |
| 102 | 540 |
| 103 | 541 /** |
| 542 * A fixed-length list of 64-bit signed integers that is viewable as a |
| 543 * [ByteArray]. For long lists, this implementation will be considerably |
| 544 * more space- and time-efficient than the default [List] implementation. |
| 545 */ |
| 104 interface Int64List extends List<int>, ByteArrayViewable | 546 interface Int64List extends List<int>, ByteArrayViewable |
| 105 default _Int64ArrayFactory { | 547 default _Int64ArrayFactory { |
| 548 /** |
| 549 * Creates an [Int64List] of the specified length (in elements), all of |
| 550 * whose elements are initially zero. |
| 551 */ |
| 106 Int64List(int length); | 552 Int64List(int length); |
| 553 |
| 554 /** |
| 555 * Creates an [Int64List] _view_ of the specified region in the specified |
| 556 * byte [array]. Changes in the [Int64List] will be visible in the byte |
| 557 * array and vice versa. If the [start] index of the region is not specified, |
| 558 * it defaults to zero (the first byte in the byte array). If the length is |
| 559 * not specified, it defaults to null, which indicates that the view extends |
| 560 * to the end of the byte array. |
| 561 * |
| 562 * Throws [IllegalArgumentException] if the length of the specified region |
| 563 * is not divisible by 8 (the size of an "int64" in bytes), or if the |
| 564 * [start] of the region is not divisible by 8. If, however, [array] |
| 565 * is a view of another byte array, this constructor will throw |
| 566 * [IllegalArgumentException] if the implicit starting position in the |
| 567 * "ultimately backing" byte array is not divisible by 8. In plain terms, |
| 568 * this constructor throws [IllegalArgumentException] if the specified |
| 569 * region does not contain an integral number of "int64s," or if it |
| 570 * is not "int64-aligned." |
| 571 */ |
| 107 Int64List.view(ByteArray array, [int start, int length]); | 572 Int64List.view(ByteArray array, [int start, int length]); |
| 108 } | 573 } |
| 109 | 574 |
| 110 | 575 |
| 576 /** |
| 577 * A fixed-length list of 64-bit unsigned integers that is viewable as a |
| 578 * [ByteArray]. For long lists, this implementation will be considerably |
| 579 * more space- and time-efficient than the default [List] implementation. |
| 580 */ |
| 111 interface Uint64List extends List<int>, ByteArrayViewable | 581 interface Uint64List extends List<int>, ByteArrayViewable |
| 112 default _Uint64ArrayFactory { | 582 default _Uint64ArrayFactory { |
| 583 /** |
| 584 * Creates a [Uint64List] of the specified length (in elements), all |
| 585 * of whose elements are initially zero. |
| 586 */ |
| 113 Uint64List(int length); | 587 Uint64List(int length); |
| 588 |
| 589 /** |
| 590 * Creates an [Uint64List] _view_ of the specified region in |
| 591 * the specified byte [array]. Changes in the [Uint64List] will be |
| 592 * visible in the byte array and vice versa. If the [start] index of the |
| 593 * region is not specified, it defaults to zero (the first byte in the byte |
| 594 * array). If the length is not specified, it defaults to null, which |
| 595 * indicates that the view extends to the end of the byte array. |
| 596 * |
| 597 * Throws [IllegalArgumentException] if the length of the specified region |
| 598 * is not divisible by 8 (the size of a "uint64" in bytes), or if the |
| 599 * [start] of the region is not divisible by 8. If, however, [array] |
| 600 * is a view of another byte array, this constructor will throw |
| 601 * [IllegalArgumentException] if the implicit starting position in the |
| 602 * "ultimately backing" byte array is not divisible by 8. In plain terms, |
| 603 * this constructor throws [IllegalArgumentException] if the specified |
| 604 * region does not contain an integral number of "uint64s," or if it |
| 605 * is not "uint64-aligned." |
| 606 */ |
| 114 Uint64List.view(ByteArray array, [int start, int length]); | 607 Uint64List.view(ByteArray array, [int start, int length]); |
| 115 } | 608 } |
| 116 | 609 |
| 117 | 610 |
| 611 /** |
| 612 * A fixed-length list of IEEE 754 single-precision binary floating-point |
| 613 * numbers that is viewable as a [ByteArray]. For long lists, this |
| 614 * implementation will be considerably more space- and time-efficient than |
| 615 * the default [List] implementation. |
| 616 */ |
| 118 interface Float32List extends List<double>, ByteArrayViewable | 617 interface Float32List extends List<double>, ByteArrayViewable |
| 119 default _Float32ArrayFactory { | 618 default _Float32ArrayFactory { |
| 619 /** |
| 620 * Creates a [Float32List] of the specified length (in elements), all of |
| 621 * whose elements are initially zero. |
| 622 */ |
| 120 Float32List(int length); | 623 Float32List(int length); |
| 624 |
| 625 /** |
| 626 * Creates a [Float32List] _view_ of the specified region in the specified |
| 627 * byte [array]. Changes in the [Float32List] will be visible in the byte |
| 628 * array and vice versa. If the [start] index of the region is not specified, |
| 629 * it defaults to zero (the first byte in the byte array). If the length is |
| 630 * not specified, it defaults to null, which indicates that the view extends |
| 631 * to the end of the byte array. |
| 632 * |
| 633 * Throws [IllegalArgumentException] if the length of the specified region |
| 634 * is not divisible by 4 (the size of a "float32" in bytes), or if the |
| 635 * [start] of the region is not divisible by 4. If, however, [array] |
| 636 * is a view of another byte array, this constructor will throw |
| 637 * [IllegalArgumentException] if the implicit starting position in the |
| 638 * "ultimately backing" byte array is not divisible by 4. In plain terms, |
| 639 * this constructor throws [IllegalArgumentException] if the specified |
| 640 * region does not contain an integral number of "float32s," or if it |
| 641 * is not "float32-aligned." |
| 642 */ |
| 121 Float32List.view(ByteArray array, [int start, int length]); | 643 Float32List.view(ByteArray array, [int start, int length]); |
| 122 } | 644 } |
| 123 | 645 |
| 124 | 646 |
| 647 /** |
| 648 * A fixed-length list of IEEE 754 double-precision binary floating-point |
| 649 * numbers that is viewable as a [ByteArray]. For long lists, this |
| 650 * implementation will be considerably more space- and time-efficient than |
| 651 * the default [List] implementation. |
| 652 */ |
| 125 interface Float64List extends List<double>, ByteArrayViewable | 653 interface Float64List extends List<double>, ByteArrayViewable |
| 126 default _Float64ArrayFactory { | 654 default _Float64ArrayFactory { |
| 655 /** |
| 656 * Creates a [Float64List] of the specified length (in elements), all of |
| 657 * whose elements are initially zero. |
| 658 */ |
| 127 Float64List(int length); | 659 Float64List(int length); |
| 660 |
| 661 /** |
| 662 * Creates a [Float64List] _view_ of the specified region in the specified |
| 663 * byte [array]. Changes in the [Float64List] will be visible in the byte |
| 664 * array and vice versa. If the [start] index of the region is not specified, |
| 665 * it defaults to zero (the first byte in the byte array). If the length is |
| 666 * not specified, it defaults to null, which indicates that the view extends |
| 667 * to the end of the byte array. |
| 668 * |
| 669 * Throws [IllegalArgumentException] if the length of the specified region |
| 670 * is not divisible by 8 (the size of a "float64" in bytes), or if the |
| 671 * [start] of the region is not divisible by 8. If, however, [array] |
| 672 * is a view of another byte array, this constructor will throw |
| 673 * [IllegalArgumentException] if the implicit starting position in the |
| 674 * "ultimately backing" byte array is not divisible by 8. In plain terms, |
| 675 * this constructor throws [IllegalArgumentException] if the specified |
| 676 * region does not contain an integral number of "float64s," or if it |
| 677 * is not "float64-aligned." |
| 678 */ |
| 128 Float64List.view(ByteArray array, [int start, int length]); | 679 Float64List.view(ByteArray array, [int start, int length]); |
| 129 } | 680 } |
| 130 | 681 |
| 131 | 682 |
| 132 class _Int8ArrayFactory { | 683 class _Int8ArrayFactory { |
| 133 factory Int8List(int length) { | 684 factory Int8List(int length) { |
| 134 return new _Int8Array(length); | 685 return new _Int8Array(length); |
| 135 } | 686 } |
| 136 | 687 |
| 137 factory Int8List.view(ByteArray array, [int start, int length]) { | 688 factory Int8List.view(ByteArray array, [int start, int length]) { |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 return new _ByteArrayView(this, start, length); | 893 return new _ByteArrayView(this, start, length); |
| 343 } | 894 } |
| 344 | 895 |
| 345 int _length() native "ByteArray_getLength"; | 896 int _length() native "ByteArray_getLength"; |
| 346 | 897 |
| 347 void _setRange(int startInBytes, int lengthInBytes, | 898 void _setRange(int startInBytes, int lengthInBytes, |
| 348 _ByteArrayBase from, int startFromInBytes) | 899 _ByteArrayBase from, int startFromInBytes) |
| 349 native "ByteArray_setRange"; | 900 native "ByteArray_setRange"; |
| 350 | 901 |
| 351 int _getInt8(int byteOffset) native "ByteArray_getInt8"; | 902 int _getInt8(int byteOffset) native "ByteArray_getInt8"; |
| 352 void _setInt8(int byteOffset, int value) native "ByteArray_setInt8"; | 903 int _setInt8(int byteOffset, int value) native "ByteArray_setInt8"; |
| 353 | 904 |
| 354 int _getUint8(int byteOffset) native "ByteArray_getUint8"; | 905 int _getUint8(int byteOffset) native "ByteArray_getUint8"; |
| 355 void _setUint8(int byteOffset, int value) native "ByteArray_setUint8"; | 906 int _setUint8(int byteOffset, int value) native "ByteArray_setUint8"; |
| 356 | 907 |
| 357 int _getInt16(int byteOffset) native "ByteArray_getInt16"; | 908 int _getInt16(int byteOffset) native "ByteArray_getInt16"; |
| 358 void _setInt16(int byteOffset, int value) native "ByteArray_setInt16"; | 909 int _setInt16(int byteOffset, int value) native "ByteArray_setInt16"; |
| 359 | 910 |
| 360 int _getUint16(int byteOffset) native "ByteArray_getUint16"; | 911 int _getUint16(int byteOffset) native "ByteArray_getUint16"; |
| 361 void _setUint16(int byteOffset, int value) native "ByteArray_setUint16"; | 912 int _setUint16(int byteOffset, int value) native "ByteArray_setUint16"; |
| 362 | 913 |
| 363 int _getInt32(int byteOffset) native "ByteArray_getInt32"; | 914 int _getInt32(int byteOffset) native "ByteArray_getInt32"; |
| 364 void _setInt32(int byteOffset, int value) native "ByteArray_setInt32"; | 915 int _setInt32(int byteOffset, int value) native "ByteArray_setInt32"; |
| 365 | 916 |
| 366 int _getUint32(int byteOffset) native "ByteArray_getUint32"; | 917 int _getUint32(int byteOffset) native "ByteArray_getUint32"; |
| 367 void _setUint32(int byteOffset, int value) native "ByteArray_setUint32"; | 918 int _setUint32(int byteOffset, int value) native "ByteArray_setUint32"; |
| 368 | 919 |
| 369 int _getInt64(int byteOffset) native "ByteArray_getInt64"; | 920 int _getInt64(int byteOffset) native "ByteArray_getInt64"; |
| 370 void _setInt64(int byteOffset, int value) native "ByteArray_setInt64"; | 921 int _setInt64(int byteOffset, int value) native "ByteArray_setInt64"; |
| 371 | 922 |
| 372 int _getUint64(int byteOffset) native "ByteArray_getUint64"; | 923 int _getUint64(int byteOffset) native "ByteArray_getUint64"; |
| 373 void _setUint64(int byteOffset, int value) native "ByteArray_setUint64"; | 924 int _setUint64(int byteOffset, int value) native "ByteArray_setUint64"; |
| 374 | 925 |
| 375 double _getFloat32(int byteOffset) native "ByteArray_getFloat32"; | 926 double _getFloat32(int byteOffset) native "ByteArray_getFloat32"; |
| 376 void _setFloat32(int byteOffset, double value) native "ByteArray_setFloat32"; | 927 int _setFloat32(int byteOffset, double value) native "ByteArray_setFloat32"; |
| 377 | 928 |
| 378 double _getFloat64(int byteOffset) native "ByteArray_getFloat64"; | 929 double _getFloat64(int byteOffset) native "ByteArray_getFloat64"; |
| 379 void _setFloat64(int byteOffset, double value) native "ByteArray_setFloat64"; | 930 int _setFloat64(int byteOffset, double value) native "ByteArray_setFloat64"; |
| 380 } | 931 } |
| 381 | 932 |
| 382 | 933 |
| 383 int _toInt(int value, int mask) { | 934 int _toInt(int value, int mask) { |
| 384 value &= mask; | 935 value &= mask; |
| 385 if (value > (mask >> 1)) value -= mask + 1; | 936 if (value > (mask >> 1)) value -= mask + 1; |
| 386 return value; | 937 return value; |
| 387 } | 938 } |
| 388 | 939 |
| 389 int _toInt8(int value) { | 940 int _toInt8(int value) { |
| (...skipping 2139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2529 } | 3080 } |
| 2530 _rangeCheck(start, length); | 3081 _rangeCheck(start, length); |
| 2531 return _array.subByteArray(_offset + start, length); | 3082 return _array.subByteArray(_offset + start, length); |
| 2532 } | 3083 } |
| 2533 | 3084 |
| 2534 static final int _BYTES_PER_ELEMENT = 8; | 3085 static final int _BYTES_PER_ELEMENT = 8; |
| 2535 final ByteArray _array; | 3086 final ByteArray _array; |
| 2536 final int _offset; | 3087 final int _offset; |
| 2537 final int _length; | 3088 final int _length; |
| 2538 } | 3089 } |
| OLD | NEW |