• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_BRIDGE_CODEC_STANDARD_CODEC_BUFFER_OPERATOR_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_CODEC_STANDARD_CODEC_BUFFER_OPERATOR_H
18 
19 #include <vector>
20 
21 #include "base/utils/noncopyable.h"
22 #include "frameworks/bridge/codec/byte_buffer_operator.h"
23 #include "frameworks/bridge/codec/codec_data.h"
24 
25 namespace OHOS::Ace::Framework {
26 
27 class ACE_EXPORT StandardCodecBufferReader final {
28 public:
StandardCodecBufferReader(const std::vector<uint8_t> & buffer)29     explicit StandardCodecBufferReader(const std::vector<uint8_t>& buffer) : byteBufferReader_(buffer) {};
30     ~StandardCodecBufferReader() = default;
31 
32     bool ReadData(CodecData& resultData);
33     bool ReadDataList(std::vector<CodecData>& resultDataList);
34     bool ReadMapSize(int32_t& size);
35 
36 private:
37     bool ReadType(BufferDataType& type);
38 
39     ByteBufferReader byteBufferReader_;
40 
41     ACE_DISALLOW_COPY_AND_MOVE(StandardCodecBufferReader);
42 };
43 
44 class StandardCodecBufferWriter final {
45 public:
StandardCodecBufferWriter(std::vector<uint8_t> & buffer)46     explicit StandardCodecBufferWriter(std::vector<uint8_t>& buffer) : byteBufferWriter_(buffer) {};
47     ~StandardCodecBufferWriter() = default;
48 
49     void WriteData(const CodecData& data);
50     void WriteDataList(const std::vector<CodecData>& dataList);
51 
52 private:
53     void WriteType(BufferDataType type);
54 
55     ByteBufferWriter byteBufferWriter_;
56 
57     ACE_DISALLOW_COPY_AND_MOVE(StandardCodecBufferWriter);
58 };
59 
60 } // namespace OHOS::Ace::Framework
61 
62 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_CODEC_STANDARD_CODEC_BUFFER_OPERATOR_H
63