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 bool _isRepeated(int fieldType) => (fieldType & PbFieldType._REPEATED_BIT) != 0; | 7 bool _isRepeated(int fieldType) => (fieldType & PbFieldType._REPEATED_BIT) != 0; |
8 | 8 |
9 bool _isRequired(int fieldType) => (fieldType & PbFieldType._REQUIRED_BIT) != 0; | 9 bool _isRequired(int fieldType) => (fieldType & PbFieldType._REQUIRED_BIT) != 0; |
10 | 10 |
11 bool _isEnum(int fieldType) => | 11 bool _isEnum(int fieldType) => |
12 PbFieldType._baseType(fieldType) == PbFieldType._ENUM_BIT; | 12 PbFieldType._baseType(fieldType) == PbFieldType._ENUM_BIT; |
13 | 13 |
14 bool _isGroupOrMessage(int fieldType) => | 14 bool _isGroupOrMessage(int fieldType) => |
15 (fieldType & (PbFieldType._GROUP_BIT | PbFieldType._MESSAGE_BIT)) != 0; | 15 (fieldType & (PbFieldType._GROUP_BIT | PbFieldType._MESSAGE_BIT)) != 0; |
16 | 16 |
17 /// Defines constants and functions for dealing with fieldType bits. | 17 /// Defines constants and functions for dealing with fieldType bits. |
18 class PbFieldType { | 18 class PbFieldType { |
19 | |
20 /// Returns the base field type without any of the required, repeated | 19 /// Returns the base field type without any of the required, repeated |
21 /// and packed bits. | 20 /// and packed bits. |
22 static int _baseType(int fieldType) => | 21 static int _baseType(int fieldType) => |
23 fieldType & ~(_REQUIRED_BIT | _REPEATED_BIT | _PACKED_BIT); | 22 fieldType & ~(_REQUIRED_BIT | _REPEATED_BIT | _PACKED_BIT); |
24 | 23 |
25 static MakeDefaultFunc _defaultForType(int type) { | 24 static MakeDefaultFunc _defaultForType(int type) { |
26 switch (type) { | 25 switch (type) { |
27 case _OPTIONAL_BOOL: | 26 case _OPTIONAL_BOOL: |
28 case _REQUIRED_BOOL: | 27 case _REQUIRED_BOOL: |
29 return _BOOL_FALSE; | 28 return _BOOL_FALSE; |
(...skipping 29 matching lines...) Expand all Loading... |
59 case _OPTIONAL_SFIXED64: | 58 case _OPTIONAL_SFIXED64: |
60 case _REQUIRED_SFIXED64: | 59 case _REQUIRED_SFIXED64: |
61 return _INT_ZERO; | 60 return _INT_ZERO; |
62 default: | 61 default: |
63 return null; | 62 return null; |
64 } | 63 } |
65 } | 64 } |
66 | 65 |
67 // Closures commonly used by initializers. | 66 // Closures commonly used by initializers. |
68 static String _STRING_EMPTY() => ''; | 67 static String _STRING_EMPTY() => ''; |
69 static List<int> _BYTES_EMPTY() => new PbList(check: _checkInt); | 68 static List<int> _BYTES_EMPTY() => new PbList<int>(check: _checkInt); |
70 static bool _BOOL_FALSE() => false; | 69 static bool _BOOL_FALSE() => false; |
71 static int _INT_ZERO() => 0; | 70 static int _INT_ZERO() => 0; |
72 static double _DOUBLE_ZERO() => 0.0; | 71 static double _DOUBLE_ZERO() => 0.0; |
73 | 72 |
74 static const int _REQUIRED_BIT = 0x1; | 73 static const int _REQUIRED_BIT = 0x1; |
75 static const int _REPEATED_BIT = 0x2; | 74 static const int _REPEATED_BIT = 0x2; |
76 static const int _PACKED_BIT = 0x4; | 75 static const int _PACKED_BIT = 0x4; |
77 | 76 |
78 static const int _BOOL_BIT = 0x10; | 77 static const int _BOOL_BIT = 0x10; |
79 static const int _BYTES_BIT = 0x20; | 78 static const int _BYTES_BIT = 0x20; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 static const int K6 = _PACKED_INT64; | 238 static const int K6 = _PACKED_INT64; |
240 static const int KS3 = _PACKED_SINT32; | 239 static const int KS3 = _PACKED_SINT32; |
241 static const int KS6 = _PACKED_SINT64; | 240 static const int KS6 = _PACKED_SINT64; |
242 static const int KU3 = _PACKED_UINT32; | 241 static const int KU3 = _PACKED_UINT32; |
243 static const int KU6 = _PACKED_UINT64; | 242 static const int KU6 = _PACKED_UINT64; |
244 static const int KF3 = _PACKED_FIXED32; | 243 static const int KF3 = _PACKED_FIXED32; |
245 static const int KF6 = _PACKED_FIXED64; | 244 static const int KF6 = _PACKED_FIXED64; |
246 static const int KSF3 = _PACKED_SFIXED32; | 245 static const int KSF3 = _PACKED_SFIXED32; |
247 static const int KSF6 = _PACKED_SFIXED64; | 246 static const int KSF6 = _PACKED_SFIXED64; |
248 } | 247 } |
OLD | NEW |