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