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 const int _SUCCESS_RESPONSE = 0; | 8 const int _SUCCESS_RESPONSE = 0; |
9 const int _ILLEGAL_ARGUMENT_RESPONSE = 1; | 9 const int _ILLEGAL_ARGUMENT_RESPONSE = 1; |
10 const int _OSERROR_RESPONSE = 2; | 10 const int _OSERROR_RESPONSE = 2; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 // Ensure that the input List can be serialized through a native port. | 67 // Ensure that the input List can be serialized through a native port. |
68 // Only builtin Lists can be serialized through. If user-defined Lists | 68 // Only builtin Lists can be serialized through. If user-defined Lists |
69 // get here, the contents is copied to a Uint8List. This has the added | 69 // get here, the contents is copied to a Uint8List. This has the added |
70 // benefit that it is faster to access from the C code as well. | 70 // benefit that it is faster to access from the C code as well. |
71 _BufferAndOffset _ensureFastAndSerializableBuffer( | 71 _BufferAndOffset _ensureFastAndSerializableBuffer( |
72 List buffer, int offset, int bytes) { | 72 List buffer, int offset, int bytes) { |
73 if (buffer is Uint8List || | 73 if (buffer is Uint8List || |
74 buffer is Int8List || | 74 buffer is Int8List || |
75 buffer is Uint16List || | 75 buffer is Uint16List || |
76 buffer is Int16List || | 76 buffer is Int16List || |
| 77 buffer is Uint32List || |
| 78 buffer is Int32List || |
| 79 buffer is Uint64List || |
| 80 buffer is Int64List || |
| 81 buffer is ByteData || |
| 82 buffer is Float32List || |
| 83 buffer is Float64List || |
77 _BufferUtils._isBuiltinList(buffer)) { | 84 _BufferUtils._isBuiltinList(buffer)) { |
78 return new _BufferAndOffset(buffer, offset); | 85 return new _BufferAndOffset(buffer, offset); |
79 } | 86 } |
80 var newBuffer = new Uint8List(bytes); | 87 var newBuffer = new Uint8List(bytes); |
81 int j = offset; | 88 int j = offset; |
82 for (int i = 0; i < bytes; i++) { | 89 for (int i = 0; i < bytes; i++) { |
83 int value = buffer[j]; | 90 int value = buffer[j]; |
84 if (value is! int) { | 91 if (value is! int) { |
85 throw new ArgumentError("List element is not an integer at index $j"); | 92 throw new ArgumentError("List element is not an integer at index $j"); |
86 } | 93 } |
87 newBuffer[i] = value; | 94 newBuffer[i] = value; |
88 j++; | 95 j++; |
89 } | 96 } |
90 return new _BufferAndOffset(newBuffer, 0); | 97 return new _BufferAndOffset(newBuffer, 0); |
91 } | 98 } |
92 | 99 |
93 | 100 |
94 // TODO(ager): The only reason for the class here is that | 101 // TODO(ager): The only reason for the class here is that |
95 // we cannot patch a top-level function. | 102 // we cannot patch a top-level function. |
96 class _BufferUtils { | 103 class _BufferUtils { |
97 // Check if a List is a builtin VM List type. Returns true | 104 // Check if a List is a builtin VM List type. Returns true |
98 // if the List is a builtin VM List type and false if it is | 105 // if the List is a builtin VM List type and false if it is |
99 // a user defined List type. | 106 // a user defined List type. |
100 external static bool _isBuiltinList(List buffer); | 107 external static bool _isBuiltinList(List buffer); |
101 } | 108 } |
102 | 109 |
103 class _IOCrypto { | 110 class _IOCrypto { |
104 external static Uint8List getRandomBytes(int count); | 111 external static Uint8List getRandomBytes(int count); |
105 } | 112 } |
OLD | NEW |