1 /*
2  * Copyright (C) 2022 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 #ifndef FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_HEADER_DATA_H_
16 #define FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_HEADER_DATA_H_
17 #include <stdint.h>
18 #include <vector>
19 #include "mtp_operation_context.h"
20 namespace OHOS {
21 namespace Media {
22 class HeaderData {
23 public:
24     HeaderData(std::shared_ptr<MtpOperationContext> &context);
25     HeaderData(uint16_t containerType, uint16_t code, uint32_t transactionID);
26     ~HeaderData();
27     int Parser(std::vector<uint8_t> &buffer, uint32_t readSize);
28     int Maker(std::vector<uint8_t> &outBuffer);
29     uint16_t GetCode() const;
30     void SetCode(uint16_t code);
31     uint32_t GetContainerLength() const;
32     void SetContainerLength(uint32_t containerLength);
33     uint16_t GetContainerType() const;
34     void SetContainerType(uint16_t containerType);
35     uint32_t GetTransactionId() const;
36     void SetTransactionId(uint32_t transactionId);
37     void Reset();
38 
39     static uint32_t sTransactionID_;
40 private:
41     std::shared_ptr<MtpOperationContext> context_;
42     uint32_t containerLength_ {0};
43     uint16_t containerType_ {0};
44     uint16_t code_ {0};
45     uint32_t transactionID_ {0};
46 };
47 } // namespace Media
48 } // namespace OHOS
49 #endif  // FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_PACKET_HEADER_H_
50