• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2019, The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <teeui/generic_messages.h>
19 
20 namespace teeui {
21 
readU32(ReadStream in)22 std::tuple<ReadStream, uint32_t> readU32(ReadStream in) {
23     volatile const uint32_t* pos = reinterpret_cast<volatile const uint32_t*>(in.pos());
24     in += sizeof(uint32_t);
25     if (!in) return {in, 0};
26     return {in, *pos};
27 }
28 
readCommand(ReadStream in)29 std::tuple<ReadStream, Command> readCommand(ReadStream in) {
30     return readCmd<Command>(in);
31 }
32 
peakCommand(ReadStream in)33 Command peakCommand(ReadStream in) {
34     auto [_, cmd] = readCommand(in);
35     return cmd;
36 }
37 
readProtocol(ReadStream in)38 std::tuple<ReadStream, Protocol> readProtocol(ReadStream in) {
39     return readCmd<Protocol, kProtoInvalid>(in);
40 }
41 
peakProtocol(ReadStream in)42 Protocol peakProtocol(ReadStream in) {
43     auto [_, proto] = readProtocol(in);
44     return proto;
45 }
46 
47 }  // namespace teeui
48