2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef SIMPLE_PERF_BUILD_ID_H_
18 #define SIMPLE_PERF_BUILD_ID_H_
22 #include <base/stringprintf.h>
24 constexpr size_t BUILD_ID_SIZE = 20;
28 static size_t Size() {
33 memset(data_, '\0', BUILD_ID_SIZE);
36 BuildId(const void* data, size_t len = BUILD_ID_SIZE) : BuildId() {
37 memcpy(data_, data, std::min(len, BUILD_ID_SIZE));
40 const unsigned char* Data() const {
44 std::string ToString() const {
46 for (size_t i = 0; i < BUILD_ID_SIZE; ++i) {
47 s += android::base::StringPrintf("%02x", data_[i]);
52 bool operator==(const BuildId& build_id) const {
53 return memcmp(data_, build_id.data_, BUILD_ID_SIZE) == 0;
56 bool IsEmpty() const {
57 static BuildId empty_build_id;
58 return *this == empty_build_id;
62 unsigned char data_[BUILD_ID_SIZE];
65 #endif // SIMPLE_PERF_BUILD_ID_H_