1 // Copyright 2020 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #pragma once
15
16 #include <cstdint>
17
18 namespace pw::protobuf {
19
20 enum class WireType {
21 kVarint = 0,
22 kFixed64 = 1,
23 kDelimited = 2,
24 // Wire types 3 and 4 are deprecated per the protobuf specification.
25 kFixed32 = 5,
26 };
27
28 inline constexpr unsigned int kFieldNumberShift = 3u;
29 inline constexpr unsigned int kWireTypeMask = (1u << kFieldNumberShift) - 1u;
30
MakeKey(uint32_t field_number,WireType wire_type)31 constexpr uint32_t MakeKey(uint32_t field_number, WireType wire_type) {
32 return (field_number << kFieldNumberShift | static_cast<uint32_t>(wire_type));
33 }
34
35 } // namespace pw::protobuf
36