• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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 #pragma once
18 
19 #include <cstdint>
20 #include <memory>
21 #include <vector>
22 
23 #include "packets/packet_builder.h"
24 
25 namespace test_vendor_lib {
26 namespace packets {
27 
28 class ResponseBuilder : public PacketBuilder<true> {
29  public:
30   virtual ~ResponseBuilder() = default;
31 
Create(uint16_t opcode,const std::vector<uint64_t> & data)32   static std::unique_ptr<ResponseBuilder> Create(uint16_t opcode, const std::vector<uint64_t>& data) {
33     return std::unique_ptr<ResponseBuilder>(new ResponseBuilder(opcode, data));
34   }
35 
size()36   virtual size_t size() const override {
37     return sizeof(opcode_) + data_.size() * sizeof(uint64_t);
38   }
39 
40  protected:
Serialize(std::back_insert_iterator<std::vector<uint8_t>> it)41   virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override {
42     insert(opcode_, it);
43     insert_vector(data_, it);
44   }
45 
46  private:
ResponseBuilder(uint16_t opcode,const std::vector<uint64_t> data)47   explicit ResponseBuilder(uint16_t opcode, const std::vector<uint64_t> data) : opcode_(opcode), data_(data) {}
48   uint16_t opcode_;
49   std::vector<uint64_t> data_;
50 };
51 
52 }  // namespace packets
53 }  // namespace test_vendor_lib
54