xref: /aosp_15_r20/external/pigweed/pw_transfer/public/pw_transfer/internal/protocol.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2022 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::transfer {
19 
20 enum class ProtocolVersion {
21   // Protocol version not known or not set.
22   kUnknown,
23 
24   // The original transfer protocol, prior to transfer start/end handshakes.
25   kLegacy,
26 
27   // Second version of the transfer protocol. Guarantees type fields on all
28   // chunks, deprecates pending_bytes in favor of window_end_offset, splits
29   // transfer resource IDs from ephemeral session IDs, and adds a handshake
30   // to the start and end of all transfer sessions.
31   kVersionTwo,
32 
33   // Alias to the most up-to-date version of the transfer protocol.
34   kLatest = kVersionTwo,
35 };
36 
ValidProtocolVersion(ProtocolVersion version)37 constexpr bool ValidProtocolVersion(ProtocolVersion version) {
38   return version > ProtocolVersion::kUnknown &&
39          version <= ProtocolVersion::kLatest;
40 }
41 
ValidProtocolVersion(uint32_t version)42 constexpr bool ValidProtocolVersion(uint32_t version) {
43   return ValidProtocolVersion(static_cast<ProtocolVersion>(version));
44 }
45 
46 }  // namespace pw::transfer
47