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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 // Constants used when working with native ports. | 7 // Constants used when working with native ports. |
8 // These must match the constants in runtime/bin/dartutils.h class CObject. | 8 // These must match the constants in runtime/bin/dartutils.h class CObject. |
9 const int _SUCCESS_RESPONSE = 0; | 9 const int _SUCCESS_RESPONSE = 0; |
10 const int _ILLEGAL_ARGUMENT_RESPONSE = 1; | 10 const int _ILLEGAL_ARGUMENT_RESPONSE = 1; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 if (value is! int) { | 124 if (value is! int) { |
125 throw new ArgumentError("List element is not an integer at index $j"); | 125 throw new ArgumentError("List element is not an integer at index $j"); |
126 } | 126 } |
127 newBuffer[i] = value; | 127 newBuffer[i] = value; |
128 j++; | 128 j++; |
129 } | 129 } |
130 return new _BufferAndStart(newBuffer, 0); | 130 return new _BufferAndStart(newBuffer, 0); |
131 } | 131 } |
132 | 132 |
133 | 133 |
134 _BufferAndStart _ensureFastAndSerializableByteBuffer( | |
Anders Johnsen
2013/06/12 06:13:58
It's not a byte buffer but a view we returns, but
Søren Gjesse
2013/06/12 08:34:00
Done (just Data instead of TypedData).
| |
135 List buffer, int start, int end) { | |
136 if (buffer is Uint8List) { | |
137 return new _BufferAndStart(buffer, start); | |
138 } | |
139 int length = end - start; | |
140 var newBuffer = new Uint8List(length); | |
141 int j = start; | |
142 for (int i = 0; i < length; i++) { | |
143 int value = buffer[j]; | |
144 if (value is! int || | |
145 value < 0 || 255 < value) { | |
146 throw new ArgumentError( | |
147 "List element is not a byte value (value $value at index $j)"); | |
148 } | |
149 newBuffer[i] = value; | |
150 j++; | |
151 } | |
152 return new _BufferAndStart(newBuffer, 0); | |
153 } | |
154 | |
155 | |
134 // TODO(ager): The only reason for the class here is that | 156 // TODO(ager): The only reason for the class here is that |
135 // we cannot patch a top-level function. | 157 // we cannot patch a top-level function. |
136 class _BufferUtils { | 158 class _BufferUtils { |
137 // Check if a List is a builtin VM List type. Returns true | 159 // Check if a List is a builtin VM List type. Returns true |
138 // if the List is a builtin VM List type and false if it is | 160 // if the List is a builtin VM List type and false if it is |
139 // a user defined List type. | 161 // a user defined List type. |
140 external static bool _isBuiltinList(List buffer); | 162 external static bool _isBuiltinList(List buffer); |
141 } | 163 } |
142 | 164 |
143 class _IOCrypto { | 165 class _IOCrypto { |
144 external static Uint8List getRandomBytes(int count); | 166 external static Uint8List getRandomBytes(int count); |
145 } | 167 } |
OLD | NEW |