| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 typedef GeneratedMessage CreateBuilderFunc(); | 7 typedef GeneratedMessage CreateBuilderFunc(); |
| 8 typedef Object MakeDefaultFunc(); | 8 typedef Object MakeDefaultFunc(); |
| 9 typedef ProtobufEnum ValueOfFunc(int value); | 9 typedef ProtobufEnum ValueOfFunc(int value); |
| 10 | 10 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 /// Returns the value of the field associated with [tagNumber], or the | 210 /// Returns the value of the field associated with [tagNumber], or the |
| 211 /// default value if it is not set. | 211 /// default value if it is not set. |
| 212 getField(int tagNumber) => _fieldSet._getField(tagNumber); | 212 getField(int tagNumber) => _fieldSet._getField(tagNumber); |
| 213 | 213 |
| 214 /// Creates List implementing a mutable repeated field. | 214 /// Creates List implementing a mutable repeated field. |
| 215 /// | 215 /// |
| 216 /// Mixins may override this method to change the List type. To ensure | 216 /// Mixins may override this method to change the List type. To ensure |
| 217 /// that the protobuf can be encoded correctly, the returned List must | 217 /// that the protobuf can be encoded correctly, the returned List must |
| 218 /// validate all items added to it. This can most easily be done | 218 /// validate all items added to it. This can most easily be done |
| 219 /// using the FieldInfo.check function. | 219 /// using the FieldInfo.check function. |
| 220 List createRepeatedField(int tagNumber, FieldInfo fi) { | 220 List/*<T>*/ createRepeatedField/*<T>*/(int tagNumber, FieldInfo/*<T>*/ fi) { |
| 221 if (fi.check != null) { | 221 return new PbList/*<T>*/(check: fi.check); |
| 222 // new way | |
| 223 return new PbList(check: fi.check); | |
| 224 } else { | |
| 225 // old way; remove after all generated code is upgraded. | |
| 226 return fi.makeDefault(); | |
| 227 } | |
| 228 } | 222 } |
| 229 | 223 |
| 230 /// Returns the value of a field, ignoring any defaults. | 224 /// Returns the value of a field, ignoring any defaults. |
| 231 /// | 225 /// |
| 232 /// For unset or cleared fields, returns null. | 226 /// For unset or cleared fields, returns null. |
| 233 /// Also returns null for unknown tag numbers. | 227 /// Also returns null for unknown tag numbers. |
| 234 getFieldOrNull(int tagNumber) => _fieldSet._getFieldOrNullByTag(tagNumber); | 228 getFieldOrNull(int tagNumber) => _fieldSet._getFieldOrNullByTag(tagNumber); |
| 235 | 229 |
| 236 /// Returns the default value for the given field. | 230 /// Returns the default value for the given field. |
| 237 /// | 231 /// |
| 238 /// For repeated fields, returns an immutable empty list | 232 /// For repeated fields, returns an immutable empty list |
| 239 /// (unlike [getField]). For all other fields, returns | 233 /// (unlike [getField]). For all other fields, returns |
| 240 /// the same thing that getField() would for a cleared field. | 234 /// the same thing that getField() would for a cleared field. |
| 241 getDefaultForField(int tagNumber) => | 235 getDefaultForField(int tagNumber) => |
| 242 _fieldSet._ensureInfo(tagNumber).readonlyDefault; | 236 _fieldSet._ensureInfo(tagNumber).readonlyDefault; |
| 243 | 237 |
| 244 /// Returns [:true:] if a value of [extension] is present. | 238 /// Returns [:true:] if a value of [extension] is present. |
| 245 bool hasExtension(Extension extension) => _fieldSet._hasExtensions && | 239 bool hasExtension(Extension extension) => |
| 240 _fieldSet._hasExtensions && |
| 246 _fieldSet._extensions._getFieldOrNull(extension) != null; | 241 _fieldSet._extensions._getFieldOrNull(extension) != null; |
| 247 | 242 |
| 248 /// Returns [:true:] if this message has a field associated with [tagNumber]. | 243 /// Returns [:true:] if this message has a field associated with [tagNumber]. |
| 249 bool hasField(int tagNumber) => _fieldSet._hasField(tagNumber); | 244 bool hasField(int tagNumber) => _fieldSet._hasField(tagNumber); |
| 250 | 245 |
| 251 /// Merges the contents of the [other] into this message. | 246 /// Merges the contents of the [other] into this message. |
| 252 /// | 247 /// |
| 253 /// Singular fields that are set in [other] overwrite the corresponding fields | 248 /// Singular fields that are set in [other] overwrite the corresponding fields |
| 254 /// in this message. Repeated fields are appended. Singular sub-messages are | 249 /// in this message. Repeated fields are appended. Singular sub-messages are |
| 255 /// recursively merged. | 250 /// recursively merged. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 273 /// Sets the value of a field by its [tagNumber]. | 268 /// Sets the value of a field by its [tagNumber]. |
| 274 /// | 269 /// |
| 275 /// Throws an [:ArgumentError:] if [value] does not match the type | 270 /// Throws an [:ArgumentError:] if [value] does not match the type |
| 276 /// associated with [tagNumber]. | 271 /// associated with [tagNumber]. |
| 277 /// | 272 /// |
| 278 /// Throws an [:ArgumentError:] if [value] is [:null:]. To clear a field of | 273 /// Throws an [:ArgumentError:] if [value] is [:null:]. To clear a field of |
| 279 /// it's current value, use [clearField] instead. | 274 /// it's current value, use [clearField] instead. |
| 280 void setField(int tagNumber, value) => _fieldSet._setField(tagNumber, value); | 275 void setField(int tagNumber, value) => _fieldSet._setField(tagNumber, value); |
| 281 | 276 |
| 282 /// For generated code only. | 277 /// For generated code only. |
| 283 $_get(int index, int tagNumber, defaultValue) => | 278 /*T*/ $_get/*<T>*/(int index, int tagNumber, /*T*/ defaultValue) => |
| 284 _fieldSet._$get(index, tagNumber, defaultValue); | 279 _fieldSet._$get/*<T>*/(index, tagNumber, defaultValue); |
| 285 | 280 |
| 286 /// For generated code only. | 281 /// For generated code only. |
| 287 bool $_has(int index, int tagNumber) => _fieldSet._$has(index, tagNumber); | 282 bool $_has(int index, int tagNumber) => _fieldSet._$has(index, tagNumber); |
| 288 | 283 |
| 289 /// For generated code only. | 284 /// For generated code only. |
| 290 void $_setBool(int index, int tagNumber, bool value) => | 285 void $_setBool(int index, int tagNumber, bool value) => |
| 291 _fieldSet._$set(index, tagNumber, value); | 286 _fieldSet._$set(index, tagNumber, value); |
| 292 | 287 |
| 293 /// For generated code only. | 288 /// For generated code only. |
| 294 void $_setBytes(int index, int tagNumber, List<int> value) => | 289 void $_setBytes(int index, int tagNumber, List<int> value) => |
| (...skipping 28 matching lines...) Expand all Loading... |
| 323 if (value == null || !_isUnsigned32(value)) { | 318 if (value == null || !_isUnsigned32(value)) { |
| 324 _fieldSet._$check(tagNumber, value); | 319 _fieldSet._$check(tagNumber, value); |
| 325 } | 320 } |
| 326 _fieldSet._$set(index, tagNumber, value); | 321 _fieldSet._$set(index, tagNumber, value); |
| 327 } | 322 } |
| 328 | 323 |
| 329 /// For generated code only. | 324 /// For generated code only. |
| 330 void $_setInt64(int index, int tagNumber, Int64 value) => | 325 void $_setInt64(int index, int tagNumber, Int64 value) => |
| 331 _fieldSet._$set(index, tagNumber, value); | 326 _fieldSet._$set(index, tagNumber, value); |
| 332 } | 327 } |
| OLD | NEW |