1 /* 2 * Copyright (C) 2019 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 INCLUDE_PERFETTO_PROTOZERO_CPP_MESSAGE_OBJ_H_ 18 #define INCLUDE_PERFETTO_PROTOZERO_CPP_MESSAGE_OBJ_H_ 19 20 #include <stdint.h> 21 22 #include <string> 23 #include <vector> 24 25 #include "perfetto/base/export.h" 26 27 namespace protozero { 28 29 // Base class for generated .gen.h classes, which are full C++ objects that 30 // support both ser and deserialization (but are not zero-copy). 31 // This is only used by the "cpp" targets not the "pbzero" ones. 32 class PERFETTO_EXPORT CppMessageObj { 33 public: 34 virtual ~CppMessageObj(); 35 virtual std::string SerializeAsString() const = 0; 36 virtual std::vector<uint8_t> SerializeAsArray() const = 0; 37 virtual bool ParseFromArray(const void*, size_t) = 0; 38 ParseFromString(const std::string & str)39 bool ParseFromString(const std::string& str) { 40 return ParseFromArray(str.data(), str.size()); 41 } 42 }; 43 44 } // namespace protozero 45 46 #endif // INCLUDE_PERFETTO_PROTOZERO_CPP_MESSAGE_OBJ_H_ 47