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 {
BufferedCarDataBufferedCarData31     BufferedCarData(int32_t id, const std::vector<uint8_t>& content, uid_t publisherUid)
32         : mId(id), mContent(std::move(content)), mPublisherUid(publisherUid) {}
33     BufferedCarData(BufferedCarData&& other) = default;
34     BufferedCarData(const BufferedCarData&) = default;
35     BufferedCarData& operator=(BufferedCarData&& other) = delete;
36     BufferedCarData& operator=(const BufferedCarData&) = delete;
37 
38     inline bool operator==(const BufferedCarData& rhs) const {
39         return std::tie(mId, mContent, mPublisherUid) ==
40                 std::tie(rhs.mId, rhs.mContent, rhs.mPublisherUid);
41     }
42 
43     // Returns the size of the stored data. Note that it's not the exact size of the struct.
contentSizeInBytesBufferedCarData44     int32_t contentSizeInBytes() const { return mContent.size(); }
45 
46     const int32_t mId;
47     const std::vector<uint8_t> mContent;
48 
49     // The uid of the logging client.
50     const uid_t mPublisherUid;
51 };
52 
53 }  // namespace telemetry
54 }  // namespace automotive
55 }  // namespace android
56 
57 #endif  // CPP_TELEMETRY_CARTELEMETRYD_SRC_BUFFEREDCARDATA_H_
58