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 interface ByteArray extends List default _InternalByteArray { | 5 interface ByteArray extends List default _InternalByteArray { |
jat
2012/02/01 23:09:29
How will this interoperate with WebGL buffers? Ca
Anders Johnsen
2012/02/01 23:19:30
I believe that an ExternalByteArray could be used
Ivan Posva
2012/02/02 08:26:43
The plan was that if an internal ByteArray is hand
| |
6 ByteArray(int length); | 6 ByteArray(int length); |
7 | 7 |
8 int get length(); | 8 int get length(); |
9 | 9 |
jat
2012/02/01 23:09:29
Should there be some method for encoding/decoding
Anders Johnsen
2012/02/01 23:19:30
One could create a class to operate on top of a By
| |
10 int getInt8(int byteOffset); | 10 int getInt8(int byteOffset); |
11 | 11 |
12 void setInt8(int byteOffset, int value); | 12 void setInt8(int byteOffset, int value); |
13 | 13 |
14 int getUint8(int byteOffset); | 14 int getUint8(int byteOffset); |
15 | 15 |
16 void setUint8(int byteOffset, int value); | 16 void setUint8(int byteOffset, int value); |
17 | 17 |
18 int getInt16(int byteOffset); | 18 int getInt16(int byteOffset); |
19 | 19 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 | 134 |
135 int removeLast() { | 135 int removeLast() { |
136 throw const UnsupportedOperationException( | 136 throw const UnsupportedOperationException( |
137 "Cannot remove from a byte array"); | 137 "Cannot remove from a byte array"); |
138 } | 138 } |
139 | 139 |
140 int last() { | 140 int last() { |
141 return this[length - 1]; | 141 return this[length - 1]; |
142 } | 142 } |
143 | 143 |
144 void setRange(int start, int length, List<int> from, [int startFrom = 0]) { | |
145 if (length < 0) { | |
146 throw new IllegalArgumentException("negative length $length"); | |
147 } | |
148 if (from is ByteArray) { | |
149 _setRange(start, length, from, startFrom); | |
150 } else { | |
151 Arrays.copy(from, startFrom, this, start, length); | |
152 } | |
153 } | |
154 | |
155 List getRange(int start, int length) { | |
156 if (length == 0) return []; | |
157 Arrays.rangeCheck(this, start, length); | |
158 ByteArray list = new ByteArray(length); | |
159 list._setRange(0, length, this, start); | |
160 return list; | |
161 } | |
162 | |
163 | |
144 // Implementation | 164 // Implementation |
145 | 165 |
146 int _length() native "ByteArray_getLength"; | 166 int _length() native "ByteArray_getLength"; |
167 | |
168 void _setRange(int start, int length, ByteArray from, int startFrom) | |
169 native "ByteArray_setRange"; | |
170 | |
147 } | 171 } |
148 | 172 |
149 | 173 |
150 class _ByteArrayIterator implements Iterator { | 174 class _ByteArrayIterator implements Iterator { |
151 _ByteArrayIterator(List byteArray) | 175 _ByteArrayIterator(List byteArray) |
152 : _byteArray = byteArray, _length = byteArray.length, _pos = 0 { | 176 : _byteArray = byteArray, _length = byteArray.length, _pos = 0 { |
153 assert(byteArray is ByteArray); | 177 assert(byteArray is ByteArray); |
154 } | 178 } |
155 | 179 |
156 bool hasNext() { | 180 bool hasNext() { |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 | 504 |
481 void _setFloat32(int byteOffset, double value) | 505 void _setFloat32(int byteOffset, double value) |
482 native "ExternalByteArray_setFloat32"; | 506 native "ExternalByteArray_setFloat32"; |
483 | 507 |
484 double _getFloat64(int byteOffset) | 508 double _getFloat64(int byteOffset) |
485 native "ExternalByteArray_getFloat64"; | 509 native "ExternalByteArray_getFloat64"; |
486 | 510 |
487 void _setFloat64(int byteOffset, double value) | 511 void _setFloat64(int byteOffset, double value) |
488 native "ExternalByteArray_setFloat64"; | 512 native "ExternalByteArray_setFloat64"; |
489 } | 513 } |
OLD | NEW |