Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.5.5

* Use real generic syntax instead of comment-based.
* Support v2 dev SDKs.

## 0.5.4

* Unknown enum values are ignored when parsing JSON, instead of throwing an
Expand Down
43 changes: 18 additions & 25 deletions lib/src/protobuf/builder_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

part of protobuf;

/**
* Per-message type setup.
*/
/// Per-message type setup.
class BuilderInfo {
final String messageName;
final Map<int, FieldInfo> fieldInfo = new Map<int, FieldInfo>();
Expand All @@ -18,22 +16,17 @@ class BuilderInfo {

BuilderInfo(this.messageName);

void add/*<T>*/(
int tagNumber,
String name,
int fieldType,
dynamic defaultOrMaker,
CreateBuilderFunc subBuilder,
ValueOfFunc valueOf) {
void add<T>(int tagNumber, String name, int fieldType, dynamic defaultOrMaker,
CreateBuilderFunc subBuilder, ValueOfFunc valueOf) {
var index = fieldInfo.length;
addField(new FieldInfo/*<T>*/(name, tagNumber, index, fieldType,
defaultOrMaker, subBuilder, valueOf));
addField(new FieldInfo<T>(name, tagNumber, index, fieldType, defaultOrMaker,
subBuilder, valueOf));
}

void addRepeated/*<T>*/(int tagNumber, String name, int fieldType,
void addRepeated<T>(int tagNumber, String name, int fieldType,
CheckFunc check, CreateBuilderFunc subBuilder, ValueOfFunc valueOf) {
var index = fieldInfo.length;
addField(new FieldInfo/*<T>*/ .repeated(
addField(new FieldInfo<T>.repeated(
name, tagNumber, index, fieldType, check, subBuilder, valueOf));
}

Expand All @@ -43,39 +36,39 @@ class BuilderInfo {
byName[fi.name] = fi;
}

void a/*<T>*/(int tagNumber, String name, int fieldType,
void a<T>(int tagNumber, String name, int fieldType,
[dynamic defaultOrMaker,
CreateBuilderFunc subBuilder,
ValueOfFunc valueOf]) {
add/*<T>*/(tagNumber, name, fieldType, defaultOrMaker, subBuilder, valueOf);
add<T>(tagNumber, name, fieldType, defaultOrMaker, subBuilder, valueOf);
}

// Enum.
void e/*<T>*/(int tagNumber, String name, int fieldType,
dynamic defaultOrMaker, ValueOfFunc valueOf) {
add/*<T>*/(tagNumber, name, fieldType, defaultOrMaker, null, valueOf);
void e<T>(int tagNumber, String name, int fieldType, dynamic defaultOrMaker,
ValueOfFunc valueOf) {
add<T>(tagNumber, name, fieldType, defaultOrMaker, null, valueOf);
}

// Repeated message.
// TODO(skybrian): migrate to pp() and remove.
void m/*<T>*/(int tagNumber, String name, CreateBuilderFunc subBuilder,
void m<T>(int tagNumber, String name, CreateBuilderFunc subBuilder,
MakeDefaultFunc makeDefault) {
add/*<T>*/(tagNumber, name, PbFieldType._REPEATED_MESSAGE, makeDefault,
add<T>(tagNumber, name, PbFieldType._REPEATED_MESSAGE, makeDefault,
subBuilder, null);
}

// Repeated, not a message, group, or enum.
void p/*<T>*/(int tagNumber, String name, int fieldType) {
void p<T>(int tagNumber, String name, int fieldType) {
assert(!_isGroupOrMessage(fieldType) && !_isEnum(fieldType));
addRepeated/*<T>*/(
addRepeated<T>(
tagNumber, name, fieldType, getCheckFunction(fieldType), null, null);
}

// Repeated message, group, or enum.
void pp/*<T>*/(int tagNumber, String name, int fieldType, CheckFunc check,
void pp<T>(int tagNumber, String name, int fieldType, CheckFunc check,
[CreateBuilderFunc subBuilder, ValueOfFunc valueOf]) {
assert(_isGroupOrMessage(fieldType) || _isEnum(fieldType));
addRepeated/*<T>*/(tagNumber, name, fieldType, check, subBuilder, valueOf);
addRepeated<T>(tagNumber, name, fieldType, check, subBuilder, valueOf);
}

bool containsTagNumber(int tagNumber) => fieldInfo.containsKey(tagNumber);
Expand Down
4 changes: 1 addition & 3 deletions lib/src/protobuf/extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

part of protobuf;

/**
* An object representing an extension field.
*/
/// An object representing an extension field.
class Extension<T> extends FieldInfo<T> {
final String extendee;

Expand Down
4 changes: 2 additions & 2 deletions lib/src/protobuf/extension_field_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ class _ExtensionFieldSet {
///
/// If it doesn't exist, creates the list and saves the extension.
/// Suitable for public API and decoders.
List/*<T>*/ _ensureRepeatedField/*<T>*/(Extension/*<T>*/ fi) {
List<T> _ensureRepeatedField<T>(Extension<T> fi) {
assert(fi.isRepeated);
assert(fi.extendee == _parent._messageName);

var list = _values[fi.tagNumber];
if (list != null) return list as List/*<T>*/;
if (list != null) return list as List<T>;

// Add info and create list.
_validateInfo(fi);
Expand Down
18 changes: 6 additions & 12 deletions lib/src/protobuf/extension_registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,23 @@

part of protobuf;

/**
* A collection of [Extension] objects, organized by the message type they
* extend.
*/
/// A collection of [Extension] objects, organized by the message type they
/// extend.
class ExtensionRegistry {
final Map<String, Map<int, Extension>> _extensions =
<String, Map<int, Extension>>{};

static const ExtensionRegistry EMPTY = const _EmptyExtensionRegistry();

/**
* Store an extension in the registry.
*/
/// Stores an [extension] in the registry.
void add(Extension extension) {
var map = _extensions.putIfAbsent(
extension.extendee, () => new Map<int, Extension>());
map[extension.tagNumber] = extension;
}

/**
* Retrieve an extension from the registry that adds the given tag
* number to the given message type.
*/
/// Retrieve an extension from the registry that adds tag number [tagNumber]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retrieves

/// to the [messageName] message type.
Extension getExtension(String messageName, int tagNumber) {
var map = _extensions[messageName];
if (map != null) {
Expand All @@ -39,7 +33,7 @@ class ExtensionRegistry {
class _EmptyExtensionRegistry implements ExtensionRegistry {
const _EmptyExtensionRegistry();

// needed to quite missing member warning
// Needed to quiet missing member warning.
get _extensions => null;

void add(Extension extension) {
Expand Down
6 changes: 2 additions & 4 deletions lib/src/protobuf/field_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

part of protobuf;

/**
* An object representing a protobuf message field.
*/
/// An object representing a protobuf message field.
class FieldInfo<T> {
final String name;
final int tagNumber;
Expand Down Expand Up @@ -127,7 +125,7 @@ class FieldInfo<T> {
/// be overridden by a mixin.
List<T> _createRepeatedField(GeneratedMessage m) {
assert(isRepeated);
return m.createRepeatedField/*<T>*/(tagNumber, this);
return m.createRepeatedField<T>(tagNumber, this);
}

String toString() => name;
Expand Down
10 changes: 5 additions & 5 deletions lib/src/protobuf/field_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ class _FieldSet {
/// Creates and stores the repeated field if it doesn't exist.
/// If it's an extension and the list doesn't exist, validates and stores it.
/// Suitable for decoders.
List/*<T>*/ _ensureRepeatedField/*<T>*/(FieldInfo/*<T>*/ fi) {
List<T> _ensureRepeatedField<T>(FieldInfo<T> fi) {
assert(!_isReadOnly);
assert(fi.isRepeated);
if (fi.index == null) {
return _ensureExtensions()._ensureRepeatedField(fi);
}
var value = _getFieldOrNull(fi);
if (value != null) return value as List/*<T>*/;
if (value != null) return value as List<T>;

var newValue = fi._createRepeatedField(_message);
_setNonExtensionFieldUnchecked(fi, newValue);
Expand All @@ -235,12 +235,12 @@ class _FieldSet {
// Generated method implementations

/// The implementation of a generated getter.
/*=T*/ _$get/*<T>*/(int index, int tagNumber, /*=T*/ defaultValue) {
T _$get<T>(int index, int tagNumber, T defaultValue) {
assert(_nonExtensionInfo(tagNumber).index == index);
var value = _values[index];
if (value != null) return value as dynamic/*=T*/;
if (value != null) return value as T;
if (defaultValue != null) return defaultValue;
return _getDefault(_nonExtensionInfo(tagNumber)) as dynamic/*=T*/;
return _getDefault(_nonExtensionInfo(tagNumber)) as T;
}

/// The implementation of a generated has method.
Expand Down
8 changes: 4 additions & 4 deletions lib/src/protobuf/generated_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ abstract class GeneratedMessage {
/// that the protobuf can be encoded correctly, the returned List must
/// validate all items added to it. This can most easily be done
/// using the FieldInfo.check function.
List/*<T>*/ createRepeatedField/*<T>*/(int tagNumber, FieldInfo/*<T>*/ fi) {
return new PbList/*<T>*/(check: fi.check);
List<T> createRepeatedField<T>(int tagNumber, FieldInfo<T> fi) {
return new PbList<T>(check: fi.check);
}

/// Returns the value of a field, ignoring any defaults.
Expand Down Expand Up @@ -279,8 +279,8 @@ abstract class GeneratedMessage {
void setField(int tagNumber, value) => _fieldSet._setField(tagNumber, value);

/// For generated code only.
/*=T*/ $_get/*<T>*/(int index, int tagNumber, /*=T*/ defaultValue) =>
_fieldSet._$get/*<T>*/(index, tagNumber, defaultValue);
T $_get<T>(int index, int tagNumber, T defaultValue) =>
_fieldSet._$get<T>(index, tagNumber, defaultValue);

/// For generated code only.
bool $_has(int index, int tagNumber) => _fieldSet._$has(index, tagNumber);
Expand Down
93 changes: 32 additions & 61 deletions lib/src/protobuf/pb_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,120 +37,91 @@ class PbList<E> extends Object with ListMixin<E> implements List<E> {
return hash;
}

/**
* Returns an [Iterator] for the list.
*/
/// Returns an [Iterator] for the list.
Iterator<E> get iterator => _wrappedList.iterator;

/**
* Returns a new lazy [Iterable] with elements that are created by calling `f`
* on each element of this `PbList` in iteration order.
*/
Iterable/*<T>*/ map/*<T>*/(/*=T*/ f(E e)) => _wrappedList.map/*<T>*/(f);
/// Returns a new lazy [Iterable] with elements that are created by calling
/// `f` on each element of this `PbList` in iteration order.
Iterable<T> map<T>(T f(E e)) => _wrappedList.map<T>(f);

/**
* Applies the function [f] to each element of this list in iteration order.
*/
/// Applies the function [f] to each element of this list in iteration order.
void forEach(void f(E element)) {
_wrappedList.forEach(f);
}

/**
* Returns the element at the given [index] in the list or throws
* an [IndexOutOfRangeException] if [index] is out of bounds.
*/
/// Returns the element at the given [index] in the list or throws an
/// [IndexOutOfRangeException] if [index] is out of bounds.
E operator [](int index) => _wrappedList[index];

/**
* Sets the entry at the given [index] in the list to [value].
* Throws an [IndexOutOfRangeException] if [index] is out of bounds.
*/
/// Sets the entry at the given [index] in the list to [value].
/// Throws an [IndexOutOfRangeException] if [index] is out of bounds.
void operator []=(int index, E value) {
_validate(value);
_wrappedList[index] = value;
}

/**
* Unsupported -- violated non-null constraint imposed by protobufs.
*
* Changes the length of the list. If [newLength] is greater than
* the current [length], entries are initialized to [:null:]. Throws
* an [UnsupportedError] if the list is not extendable.
*/
/// Unsupported -- violated non-null constraint imposed by protobufs.
///
/// Changes the length of the list. If [newLength] is greater than the current
/// [length], entries are initialized to [:null:]. Throws an
/// [UnsupportedError] if the list is not extendable.
void set length(int newLength) {
if (newLength > length) {
throw new ArgumentError('Extending protobuf lists is not supported');
}
_wrappedList.length = newLength;
}

/**
* Adds [value] at the end of the list, extending the length by
* one. Throws an [UnsupportedError] if the list is not
* extendable.
*/
/// Adds [value] at the end of the list, extending the length by one.
/// Throws an [UnsupportedError] if the list is not extendable.
void add(E value) {
_validate(value);
_wrappedList.add(value);
}

/**
* Appends all elements of the [collection] to the end of list.
* Extends the length of the list by the length of [collection].
* Throws an [UnsupportedError] if the list is not
* extendable.
*/
/// Appends all elements of the [collection] to the end of list.
/// Extends the length of the list by the length of [collection].
/// Throws an [UnsupportedError] if the list is not extendable.
void addAll(Iterable<E> collection) {
collection.forEach(_validate);
_wrappedList.addAll(collection);
}

/**
* Copies [:end - start:] elements of the [from] array, starting
* from [skipCount], into [:this:], starting at [start].
* Throws an [UnsupportedError] if the list is
* not extendable.
*/
/// Copies [:end - start:] elements of the [from] array, starting from
/// [skipCount], into [:this:], starting at [start].
/// Throws an [UnsupportedError] if the list is not extendable.
void setRange(int start, int end, Iterable<E> from, [int skipCount = 0]) {
// NOTE: In case `take()` returns less than `end - start` elements, the
// _wrappedList will fail with a `StateError`.
from.skip(skipCount).take(end - start).forEach(_validate);
_wrappedList.setRange(start, end, from, skipCount);
}

/**
* Inserts a new element in the list.
* The element must be valid (and not nullable) for the PbList type.
*/
/// Inserts a new element in the list.
/// The element must be valid (and not nullable) for the PbList type.
void insert(int index, E element) {
_validate(element);
_wrappedList.insert(index, element);
}

/**
* Inserts all elements of [iterable] at position [index] in the list.
*
* Elements in [iterable] must be valid and not nullable for the PbList type.
*/
/// Inserts all elements of [iterable] at position [index] in the list.
///
/// Elements in [iterable] must be valid and not nullable for the PbList type.
void insertAll(int index, Iterable<E> iterable) {
iterable.forEach(_validate);
_wrappedList.insertAll(index, iterable);
}

/**
* Overwrites elements of `this` with elements of [iterable] starting at
* position [index] in the list.
*
* Elements in [iterable] must be valid and not nullable for the PbList type.
*/
/// Overwrites elements of `this` with elements of [iterable] starting at
/// position [index] in the list.
///
/// Elements in [iterable] must be valid and not nullable for the PbList type.
void setAll(int index, Iterable<E> iterable) {
iterable.forEach(_validate);
_wrappedList.setAll(index, iterable);
}

/**
* Returns the number of elements in this collection.
*/
/// Returns the number of elements in this collection.
int get length => _wrappedList.length;

void _validate(E val) {
Expand Down
Loading