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 protobuf; | 5 part of protobuf; |
6 | 6 |
7 /** | 7 /** |
8 * An object representing a protobuf message field. | 8 * An object representing a protobuf message field. |
9 */ | 9 */ |
10 class FieldInfo { | 10 class FieldInfo<T> { |
11 final String name; | 11 final String name; |
12 final int tagNumber; | 12 final int tagNumber; |
13 final int index; // index of the field's value. Null for extensions. | 13 final int index; // index of the field's value. Null for extensions. |
14 final int type; | 14 final int type; |
15 | 15 |
16 // Constructs the default value of a field. | 16 // Constructs the default value of a field. |
17 // (Only used for repeated fields where check is null.) | 17 // (Only used for repeated fields where check is null.) |
18 final MakeDefaultFunc makeDefault; | 18 final MakeDefaultFunc makeDefault; |
19 | 19 |
20 // Creates an empty message or group when decoding a message. | 20 // Creates an empty message or group when decoding a message. |
(...skipping 18 matching lines...) Expand all Loading... | |
39 assert(type != 0); | 39 assert(type != 0); |
40 assert(!_isGroupOrMessage(type) || subBuilder != null); | 40 assert(!_isGroupOrMessage(type) || subBuilder != null); |
41 assert(!_isEnum(type) || valueOf != null); | 41 assert(!_isEnum(type) || valueOf != null); |
42 } | 42 } |
43 | 43 |
44 FieldInfo.repeated(this.name, this.tagNumber, this.index, int type, | 44 FieldInfo.repeated(this.name, this.tagNumber, this.index, int type, |
45 CheckFunc check, this.subBuilder, | 45 CheckFunc check, this.subBuilder, |
46 [this.valueOf]) | 46 [this.valueOf]) |
47 : this.type = type, | 47 : this.type = type, |
48 this.check = check, | 48 this.check = check, |
49 this.makeDefault = (() => new PbList(check: check)) { | 49 this.makeDefault = (() => new PbList<T>(check: check)) { |
skybrian
2016/04/01 18:01:40
This is a bit inconsistent.
For a non-repeated fi
| |
50 assert(name != null); | 50 assert(name != null); |
51 assert(tagNumber != null); | 51 assert(tagNumber != null); |
52 assert(_isRepeated(type)); | 52 assert(_isRepeated(type)); |
53 assert(check != null); | 53 assert(check != null); |
54 assert(!_isEnum(type) || valueOf != null); | 54 assert(!_isEnum(type) || valueOf != null); |
55 } | 55 } |
56 | 56 |
57 static MakeDefaultFunc findMakeDefault(int type, dynamic defaultOrMaker) { | 57 static MakeDefaultFunc findMakeDefault(int type, dynamic defaultOrMaker) { |
58 if (defaultOrMaker == null) return PbFieldType._defaultForType(type); | 58 if (defaultOrMaker == null) return PbFieldType._defaultForType(type); |
59 if (defaultOrMaker is MakeDefaultFunc) return defaultOrMaker; | 59 if (defaultOrMaker is MakeDefaultFunc) return defaultOrMaker; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 // Recurse on each item in the list. | 114 // Recurse on each item in the list. |
115 int position = 0; | 115 int position = 0; |
116 for (GeneratedMessage message in list) { | 116 for (GeneratedMessage message in list) { |
117 message._fieldSet | 117 message._fieldSet |
118 ._appendInvalidFields(problems, '$prefix$name[$position].'); | 118 ._appendInvalidFields(problems, '$prefix$name[$position].'); |
119 position++; | 119 position++; |
120 } | 120 } |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 /// Creates a repeated field to be attached to the given message. | |
125 /// | |
126 /// Delegates actual list creation to the message, so that it can | |
127 /// be overridden by a mixin. | |
128 List<T> _createRepeatedField(GeneratedMessage m) { | |
129 assert(isRepeated); | |
130 return m.createRepeatedField/*<T>*/(tagNumber, this); | |
131 } | |
132 | |
124 String toString() => name; | 133 String toString() => name; |
125 } | 134 } |
OLD | NEW |