Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1350)

Unified Diff: runtime/vm/dart_api_message.cc

Issue 9348019: Add support for byte arrays to native messages (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/dart_api_message.h ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_message.cc
diff --git a/runtime/vm/dart_api_message.cc b/runtime/vm/dart_api_message.cc
index cef65c67e1b7dcba785bc5d613ed87adaa6799f4..e125b0565a204f4037077e41b3360b64f0c71e02 100644
--- a/runtime/vm/dart_api_message.cc
+++ b/runtime/vm/dart_api_message.cc
@@ -100,6 +100,25 @@ Dart_CObject* ApiMessageReader::AllocateDartCObjectString(intptr_t length) {
}
+Dart_CObject* ApiMessageReader::AllocateDartCObjectByteArray(intptr_t length) {
+ // Allocate a Dart_CObject structure followed by an array of bytes
+ // for the byte array content. The pointer to the byte array content
+ // is set up to this area.
+ Dart_CObject* value =
+ reinterpret_cast<Dart_CObject*>(
+ alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1));
siva 2012/02/09 01:58:57 (sizeof(Dart_Cobject) + length + 1) what is the +
Søren Gjesse 2012/02/09 09:34:16 Removed the + 1 (copy/paset from string allocation
+ value->type = Dart_CObject::kByteArray;
+ value->value.as_array.length = length;
+ if (length > 0) {
+ value->value.as_byte_array.values =
+ reinterpret_cast<uint8_t*>(value) + sizeof(*value);
+ } else {
+ value->value.as_byte_array.values = NULL;
+ }
+ return value;
+}
+
+
Dart_CObject* ApiMessageReader::AllocateDartCObjectArray(intptr_t length) {
// Allocate a Dart_CObject structure followed by an array of
// pointers to Dart_CObject structures. The pointer to the array
@@ -197,6 +216,20 @@ Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) {
// Four byte strings not supported.
return NULL;
break;
+ case ObjectStore::kInternalByteArrayClass: {
+ intptr_t len = ReadSmiValue();
+ Dart_CObject* object = AllocateDartCObjectByteArray(len);
+ AddBackwardReference(object_id, object);
+ if (len > 0) {
+ uint8_t* p = object->value.as_byte_array.values;
+ for (intptr_t i = 0; i < len; i++) {
+ *p = Read<uint8_t>();
siva 2012/02/09 01:58:57 p[i] = Read<uint8_t>(); would avoid the need for
Søren Gjesse 2012/02/09 09:34:16 Done (for string as well).
+ p++;
+ }
+ }
+ return object;
+ break;
+ }
default:
// Everything else not supported.
return NULL;
@@ -215,7 +248,8 @@ Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) {
object_id == ObjectStore::kDoubleInterface ||
object_id == ObjectStore::kIntInterface ||
object_id == ObjectStore::kBoolInterface ||
- object_id == ObjectStore::kStringInterface) {
+ object_id == ObjectStore::kStringInterface ||
+ object_id == ObjectStore::kByteArrayInterface) {
// Always return dynamic type (this is only a marker).
return &dynamic_type_marker;
} else {
« no previous file with comments | « runtime/vm/dart_api_message.h ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698