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

Side by Side Diff: mojo/public/dart/src/codec.dart

Issue 795593004: Update mojo sdk to rev cc531b32182099a5a034a99daff35ed5d38a61c8 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More workarounds for MSVC Created 5 years, 11 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 unified diff | Download patch
« no previous file with comments | « mojo/public/dart/src/client.dart ('k') | mojo/public/dart/src/handle.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // TODO(zra): Rewrite MojoDecoder and MojoEncoder using Dart idioms, and make 5 // TODO(zra): Rewrite MojoDecoder and MojoEncoder using Dart idioms, and make
6 // corresponding changes to the bindings generation script. 6 // corresponding changes to the bindings generation script.
7 7
8 part of bindings; 8 part of bindings;
9 9
10 const int kAlignment = 8; 10 const int kAlignment = 8;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 return 0; 148 return 0;
149 } 149 }
150 return offsetPointer + offset; 150 return offsetPointer + offset;
151 } 151 }
152 152
153 MojoDecoder decodeAndCreateDecoder(int offset) { 153 MojoDecoder decodeAndCreateDecoder(int offset) {
154 return new MojoDecoder(buffer, handles, offset); 154 return new MojoDecoder(buffer, handles, offset);
155 } 155 }
156 156
157 core.RawMojoHandle decodeHandle() { 157 core.RawMojoHandle decodeHandle() {
158 return handles[readUint32()]; 158 int handleIndex = readUint32();
159 return (handleIndex == kEncodedInvalidHandleValue) ?
160 new core.RawMojoHandle(core.RawMojoHandle.INVALID) :
161 handles[handleIndex];
159 } 162 }
160 163
161 String decodeString() { 164 String decodeString() {
162 int numBytes = readUint32(); 165 int numBytes = readUint32();
163 int numElements = readUint32(); 166 int numElements = readUint32();
164 int base = next; 167 int base = next;
165 next += numElements; 168 next += numElements;
166 return stringOfUtf8(buffer.buffer.asUint8List(base, numElements)); 169 return stringOfUtf8(buffer.buffer.asUint8List(base, numElements));
167 } 170 }
168 171
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 if (pointer == null) { 319 if (pointer == null) {
317 writeUint64(0); 320 writeUint64(0);
318 return; 321 return;
319 } 322 }
320 int offset = pointer - next; 323 int offset = pointer - next;
321 writeUint64(offset); 324 writeUint64(offset);
322 } 325 }
323 326
324 void grow(int new_size) { 327 void grow(int new_size) {
325 Uint8List new_buffer = new Uint8List(new_size); 328 Uint8List new_buffer = new Uint8List(new_size);
326 new_buffer.setRange(0, next, buffer.buffer.asUint8List()); 329 new_buffer.setRange(0, buffer.lengthInBytes, buffer.buffer.asUint8List());
327 buffer = new_buffer.buffer.asByteData(); 330 buffer = new_buffer.buffer.asByteData();
328 } 331 }
329 332
330 int alloc(int size_request) { 333 int alloc(int size_request) {
331 int pointer = extent; 334 int pointer = extent;
332 extent += size_request; 335 extent += size_request;
333 if (extent > buffer.lengthInBytes) { 336 if (extent > buffer.lengthInBytes) {
334 int new_size = buffer.lengthInBytes + size_request; 337 int new_size = buffer.lengthInBytes + size_request;
335 new_size += new_size ~/ 2; 338 new_size += new_size ~/ 2;
336 grow(new_size); 339 grow(new_size);
337 } 340 }
338 return pointer; 341 return pointer;
339 } 342 }
340 343
341 MojoEncoder createAndEncodeEncoder(int size) { 344 MojoEncoder createAndEncodeEncoder(int size) {
342 int pointer = alloc(align(size)); 345 int pointer = alloc(align(size));
343 encodePointer(pointer); 346 encodePointer(pointer);
344 return new MojoEncoder(buffer, handles, pointer, extent); 347 return new MojoEncoder(buffer, handles, pointer, extent);
345 } 348 }
346 349
347 void encodeHandle(core.RawMojoHandle handle) { 350 void encodeHandle(core.RawMojoHandle handle) {
348 handles.add(handle); 351 if (handle.isValid) {
349 writeUint32(handles.length - 1); 352 handles.add(handle);
353 writeUint32(handles.length - 1);
354 } else {
355 writeUint32(kEncodedInvalidHandleValue);
356 }
350 } 357 }
351 358
352 void encodeString(String val) { 359 void encodeString(String val) {
353 Uint8List utf8string = utf8OfString(val); 360 Uint8List utf8string = utf8OfString(val);
354 int numElements = utf8string.lengthInBytes; 361 int numElements = utf8string.lengthInBytes;
355 int numBytes = kArrayHeaderSize + numElements; 362 int numBytes = kArrayHeaderSize + numElements;
356 writeUint32(numBytes); 363 writeUint32(numBytes);
357 writeUint32(numElements); 364 writeUint32(numElements);
358 buffer.buffer.asUint8List().setRange(next, next + numElements, utf8string); 365 buffer.buffer.asUint8List().setRange(next, next + numElements, utf8string);
359 next += numElements; 366 next += numElements;
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 encoder.encodeHandle(val); 741 encoder.encodeHandle(val);
735 } 742 }
736 } 743 }
737 744
738 745
739 class NullableHandle { 746 class NullableHandle {
740 static const int encodedSize = Handle.encodedSize; 747 static const int encodedSize = Handle.encodedSize;
741 static const decode = Handle.decode; 748 static const decode = Handle.decode;
742 static const encode = Handle.encode; 749 static const encode = Handle.encode;
743 } 750 }
751
752
753 class MapOf {
754 Object key;
755 Object val;
756
757 MapOf(this.key, this.val);
758
759 int encodedSize = 8;
760 Map decode(MojoDecoder decoder) => decoder.decodeMapPointer(key, val);
761 void encode(MojoEncoder encoder, Map map) {
762 encoder.encodeMapPointer(key, val, map);
763 }
764 }
765
766
767 class NullableMapOf extends MapOf {
768 NullableMapOf(Object key, Object val) : super(key, val);
769 }
OLDNEW
« no previous file with comments | « mojo/public/dart/src/client.dart ('k') | mojo/public/dart/src/handle.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698