2 // Copyright 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 #define LOG_TAG "packet"
19 #include "vendor_libs/test_vendor_lib/include/packet.h"
24 #include "osi/include/log.h"
27 namespace test_vendor_lib {
29 Packet::Packet(serial_data_type_t type) : type_(type) {}
31 bool Packet::Encode(const std::vector<uint8_t>& header,
32 const std::vector<uint8_t>& payload) {
33 if (header.back() != payload.size()) {
41 const std::vector<uint8_t>& Packet::GetHeader() const {
42 // Every packet must have a header.
43 assert(GetHeaderSize() > 0);
47 uint8_t Packet::GetHeaderSize() const {
48 return header_.size();
51 size_t Packet::GetPacketSize() const {
52 return header_.size() + payload_.size() + sizeof(type_);
55 const std::vector<uint8_t>& Packet::GetPayload() const {
59 uint8_t Packet::GetPayloadSize() const {
60 return payload_.size();
63 serial_data_type_t Packet::GetType() const {
67 } // namespace test_vendor_lib