1 /* 2 * Copyright (C) 2016 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 #include "log.h" 18 #include "logevent.h" 19 20 namespace android { 21 22 /* LogEvent *******************************************************************/ 23 FromBytes(const std::vector<uint8_t> & buffer)24std::unique_ptr<LogEvent> LogEvent::FromBytes( 25 const std::vector<uint8_t>& buffer) { 26 auto event = std::unique_ptr<LogEvent>(new LogEvent()); 27 event->Populate(buffer); 28 29 return event; 30 } 31 GetMessage() const32std::string LogEvent::GetMessage() const { 33 constexpr size_t kHeaderSize = sizeof(uint32_t) // Message type. 34 + sizeof(char) // Log level. 35 + sizeof(char); // Beginning of log message. 36 37 if (event_data.size() < kHeaderSize) { 38 LOGW("Invalid/short LogEvent event of size %zu", event_data.size()); 39 return std::string(); 40 } else { 41 const char *message = reinterpret_cast<const char *>( 42 event_data.data() + sizeof(uint32_t)); 43 return std::string(message); 44 } 45 } 46 47 } // namespace android 48