• 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 <forward_list>
21 
22 #include "iterator.h"
23 #include "view.h"
24 
25 namespace test_vendor_lib {
26 namespace packets {
27 
28 // Abstract base class that is subclassed to provide type-specifc accessors.
29 // Holds a shared pointer to the underlying data.
30 // The template parameter little_endian controls the generation of extract().
31 template <bool little_endian>
32 class PacketView {
33  public:
34   PacketView(const std::forward_list<class View> fragments);
35   PacketView(const PacketView& PacketView) = default;
36   virtual ~PacketView() = default;
37 
38   virtual Iterator<little_endian> begin() const;
39 
40   virtual Iterator<little_endian> end() const;
41 
42   uint8_t operator[](size_t i) const;
43 
44   uint8_t at(size_t index) const;
45 
46   size_t size() const;
47 
48   PacketView<true> SubViewLittleEndian(size_t begin, size_t end) const;
49 
50   PacketView<false> SubViewBigEndian(size_t begin, size_t end) const;
51 
52  protected:
53   PacketView(std::shared_ptr<std::vector<uint8_t>> packet);
54 
55  private:
56   std::forward_list<View> fragments_;
57   size_t length_;
58   PacketView<little_endian>() = delete;
59   std::forward_list<View> SubViewList(size_t begin, size_t end) const;
60 };
61 
62 }  // namespace packets
63 }  // namespace test_vendor_lib
64