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

Side by Side Diff: lib/src/protobuf/wire_format.dart

Issue 1277863003: cleanup: move fieldType constants and functions to a separate file (Closed) Base URL: git@github.com:dart-lang/dart-protobuf.git@master
Patch Set: _validateMessage should call _baseType, not callers Created 5 years, 4 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 | « lib/src/protobuf/unknown_field_set.dart ('k') | no next file » | 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) 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 const int TAG_TYPE_BITS = 3; 7 const int TAG_TYPE_BITS = 3;
8 const int TAG_TYPE_MASK = (1 << TAG_TYPE_BITS) - 1; 8 const int TAG_TYPE_MASK = (1 << TAG_TYPE_BITS) - 1;
9 9
10 const int WIRETYPE_VARINT = 0; 10 const int WIRETYPE_VARINT = 0;
11 const int WIRETYPE_FIXED64 = 1; 11 const int WIRETYPE_FIXED64 = 1;
12 const int WIRETYPE_LENGTH_DELIMITED = 2; 12 const int WIRETYPE_LENGTH_DELIMITED = 2;
13 const int WIRETYPE_START_GROUP = 3; 13 const int WIRETYPE_START_GROUP = 3;
14 const int WIRETYPE_END_GROUP = 4; 14 const int WIRETYPE_END_GROUP = 4;
15 const int WIRETYPE_FIXED32 = 5; 15 const int WIRETYPE_FIXED32 = 5;
16 16
17 int getTagFieldNumber(int tag) => (tag & 0x7fffffff) >> TAG_TYPE_BITS; 17 int getTagFieldNumber(int tag) => (tag & 0x7fffffff) >> TAG_TYPE_BITS;
18 18
19 int getTagWireType(int tag) => tag & TAG_TYPE_MASK; 19 int getTagWireType(int tag) => tag & TAG_TYPE_MASK;
20 20
21 int makeTag(int fieldNumber, int tag) => (fieldNumber << TAG_TYPE_BITS) | tag; 21 int makeTag(int fieldNumber, int tag) => (fieldNumber << TAG_TYPE_BITS) | tag;
22
23 /// Returns true if the wireType can be merged into the given fieldType.
24 bool _wireTypeMatches(int fieldType, int wireType) {
25 switch (FieldType._baseType(fieldType)) {
26 case FieldType._BOOL_BIT:
27 case FieldType._ENUM_BIT:
28 case FieldType._INT32_BIT:
29 case FieldType._INT64_BIT:
30 case FieldType._SINT32_BIT:
31 case FieldType._SINT64_BIT:
32 case FieldType._UINT32_BIT:
33 case FieldType._UINT64_BIT:
34 return wireType == WIRETYPE_VARINT ||
35 wireType == WIRETYPE_LENGTH_DELIMITED;
36 case FieldType._FLOAT_BIT:
37 case FieldType._FIXED32_BIT:
38 case FieldType._SFIXED32_BIT:
39 return wireType == WIRETYPE_FIXED32 ||
40 wireType == WIRETYPE_LENGTH_DELIMITED;
41 case FieldType._DOUBLE_BIT:
42 case FieldType._FIXED64_BIT:
43 case FieldType._SFIXED64_BIT:
44 return wireType == WIRETYPE_FIXED64 ||
45 wireType == WIRETYPE_LENGTH_DELIMITED;
46 case FieldType._BYTES_BIT:
47 case FieldType._STRING_BIT:
48 case FieldType._MESSAGE_BIT:
49 return wireType == WIRETYPE_LENGTH_DELIMITED;
50 case FieldType._GROUP_BIT:
51 return wireType == WIRETYPE_START_GROUP;
52 default:
53 return false;
54 }
55 }
OLDNEW
« no previous file with comments | « lib/src/protobuf/unknown_field_set.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698