1 /*
2  * Copyright (c) 2021, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CPP_TELEMETRY_CARTELEMETRYD_SRC_BUFFEREDCARDATA_H_
18 #define CPP_TELEMETRY_CARTELEMETRYD_SRC_BUFFEREDCARDATA_H_
19 
20 #include <stdint.h>
21 
22 #include <tuple>
23 #include <vector>
24 
25 namespace android {
26 namespace automotive {
27 namespace telemetry {
28 
29 // Internally stored `CarData` with some extras.
30 struct BufferedCarData {
31     BufferedCarData(BufferedCarData&& other) = default;
32     BufferedCarData(const BufferedCarData&) = default;
33     BufferedCarData& operator=(BufferedCarData&& other) = default;
34     BufferedCarData& operator=(const BufferedCarData&) = default;
35 
36     inline bool operator==(const BufferedCarData& rhs) const {
37         return std::tie(mId, mContent, mPublisherUid) ==
38                 std::tie(rhs.mId, rhs.mContent, rhs.mPublisherUid);
39     }
40 
41     // Returns the size of the stored data. Note that it's not the exact size of the struct.
contentSizeInBytesBufferedCarData42     int32_t contentSizeInBytes() const { return mContent.size(); }
43 
44     const int32_t mId;
45     const std::vector<uint8_t> mContent;
46 
47     // The uid of the logging client.
48     const uid_t mPublisherUid;
49 };
50 
51 }  // namespace telemetry
52 }  // namespace automotive
53 }  // namespace android
54 
55 #endif  // CPP_TELEMETRY_CARTELEMETRYD_SRC_BUFFEREDCARDATA_H_
56