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

Side by Side Diff: pkg/analyzer/lib/src/summary/flat_buffers.dart

Issue 1612533002: Add support for Uint32 fields and lists in Flat Buffers. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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 | « no previous file | pkg/analyzer/test/src/summary/flat_buffers_test.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 (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 library analyzer.src.summary.flat_buffers; 5 library analyzer.src.summary.flat_buffers;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:math'; 9 import 'dart:math';
10 import 'dart:typed_data'; 10 import 'dart:typed_data';
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 throw new StateError('Start a table before adding values.'); 171 throw new StateError('Start a table before adding values.');
172 } 172 }
173 if (offset != null) { 173 if (offset != null) {
174 _prepare(4, 1); 174 _prepare(4, 1);
175 _trackField(field); 175 _trackField(field);
176 _setUint32AtTail(_buf, _tail, _tail - offset._tail); 176 _setUint32AtTail(_buf, _tail, _tail - offset._tail);
177 } 177 }
178 } 178 }
179 179
180 /** 180 /**
181 * Add the [field] with the given 32-bit unsigned integer [value]. The field
182 * is not added if the [value] is equal to [def].
183 */
184 void addUint32(int field, int value, [int def]) {
185 if (_currentVTable == null) {
186 throw new StateError('Start a table before adding values.');
187 }
188 if (value != null && value != def) {
189 int size = 4;
190 _prepare(size, 1);
191 _trackField(field);
192 _setUint32AtTail(_buf, _tail, value);
193 }
194 }
195
196 /**
181 * End the current table and return its offset. 197 * End the current table and return its offset.
182 */ 198 */
183 Offset endTable() { 199 Offset endTable() {
184 if (_currentVTable == null) { 200 if (_currentVTable == null) {
185 throw new StateError('Start a table before ending it.'); 201 throw new StateError('Start a table before ending it.');
186 } 202 }
187 // Prepare the size of the current table. 203 // Prepare the size of the current table.
188 _currentVTable.tableSize = _tail - _currentTableEndTail; 204 _currentVTable.tableSize = _tail - _currentTableEndTail;
189 // Prepare for writing the VTable. 205 // Prepare for writing the VTable.
190 _prepare(4, 1); 206 _prepare(4, 1);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 _setUint32AtTail(_buf, tail, values.length); 351 _setUint32AtTail(_buf, tail, values.length);
336 tail -= 4; 352 tail -= 4;
337 for (int value in values) { 353 for (int value in values) {
338 _setInt32AtTail(_buf, tail, value); 354 _setInt32AtTail(_buf, tail, value);
339 tail -= 4; 355 tail -= 4;
340 } 356 }
341 return result; 357 return result;
342 } 358 }
343 359
344 /** 360 /**
361 * Write the given list of unsigned 32-bit integer [values].
362 */
363 Offset writeListUint32(List<int> values) {
364 if (_currentVTable != null) {
365 throw new StateError(
366 'Cannot write a non-scalar value while writing a table.');
367 }
368 _prepare(4, 1 + values.length);
369 Offset result = new Offset(_tail);
370 int tail = _tail;
371 _setUint32AtTail(_buf, tail, values.length);
372 tail -= 4;
373 for (int value in values) {
374 _setUint32AtTail(_buf, tail, value);
375 tail -= 4;
376 }
377 return result;
378 }
379
380 /**
345 * Write the given string [value] and return its [Offset], or `null` if 381 * Write the given string [value] and return its [Offset], or `null` if
346 * the [value] is equal to [def]. 382 * the [value] is equal to [def].
347 */ 383 */
348 Offset<String> writeString(String value, [String def]) { 384 Offset<String> writeString(String value, [String def]) {
349 if (_currentVTable != null) { 385 if (_currentVTable != null) {
350 throw new StateError( 386 throw new StateError(
351 'Cannot write a non-scalar value while writing a table.'); 387 'Cannot write a non-scalar value while writing a table.');
352 } 388 }
353 if (value != def) { 389 if (value != def) {
354 // TODO(scheglov) optimize for ASCII strings 390 // TODO(scheglov) optimize for ASCII strings
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 const Float64ListReader(); 464 const Float64ListReader();
429 465
430 @override 466 @override
431 int get size => 4; 467 int get size => 4;
432 468
433 @override 469 @override
434 List<double> read(BufferPointer bp) => new _FbFloat64List(bp.derefObject()); 470 List<double> read(BufferPointer bp) => new _FbFloat64List(bp.derefObject());
435 } 471 }
436 472
437 /** 473 /**
438 * The reader of 32-bit signed integers. 474 * The reader of signed 32-bit integers.
439 */ 475 */
440 class Int32Reader extends Reader<int> { 476 class Int32Reader extends Reader<int> {
441 const Int32Reader() : super(); 477 const Int32Reader() : super();
442 478
443 @override 479 @override
444 int get size => 4; 480 int get size => 4;
445 481
446 @override 482 @override
447 int read(BufferPointer bp) => bp._getInt32(); 483 int read(BufferPointer bp) => bp._getInt32();
448 } 484 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 T createObject(BufferPointer bp); 591 T createObject(BufferPointer bp);
556 592
557 @override 593 @override
558 T read(BufferPointer bp) { 594 T read(BufferPointer bp) {
559 bp = bp.derefObject(); 595 bp = bp.derefObject();
560 return createObject(bp); 596 return createObject(bp);
561 } 597 }
562 } 598 }
563 599
564 /** 600 /**
601 * The reader of unsigned 32-bit integers.
602 */
603 class Uint32Reader extends Reader<int> {
604 const Uint32Reader() : super();
605
606 @override
607 int get size => 4;
608
609 @override
610 int read(BufferPointer bp) => bp._getUint32();
611 }
612
613 /**
565 * The list backed by 64-bit values - Uint64 length and Float64. 614 * The list backed by 64-bit values - Uint64 length and Float64.
566 */ 615 */
567 class _FbFloat64List extends _FbList<double> { 616 class _FbFloat64List extends _FbList<double> {
568 final BufferPointer bp; 617 final BufferPointer bp;
569 618
570 int _length; 619 int _length;
571 List<double> _items; 620 List<double> _items;
572 621
573 _FbFloat64List(this.bp); 622 _FbFloat64List(this.bp);
574 623
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 // Table size. 751 // Table size.
703 buf.setUint16(bufOffset, tableSize, Endianness.LITTLE_ENDIAN); 752 buf.setUint16(bufOffset, tableSize, Endianness.LITTLE_ENDIAN);
704 bufOffset += 2; 753 bufOffset += 2;
705 // Field offsets. 754 // Field offsets.
706 for (int fieldOffset in fieldOffsets) { 755 for (int fieldOffset in fieldOffsets) {
707 buf.setUint16(bufOffset, fieldOffset, Endianness.LITTLE_ENDIAN); 756 buf.setUint16(bufOffset, fieldOffset, Endianness.LITTLE_ENDIAN);
708 bufOffset += 2; 757 bufOffset += 2;
709 } 758 }
710 } 759 }
711 } 760 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/flat_buffers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698