• 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 HC_PARCEL_H
17 #define HC_PARCEL_H
18 
19 #include <stdint.h>
20 #include "hc_types.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #define PARCEL_DEFAULT_LENGTH 0
27 #define PARCEL_DEFAULT_ALLOC_UNIT 0
28 
29 typedef struct {
30     char *data;
31     unsigned int beginPos;
32     unsigned int endPos;
33     unsigned int length;
34     unsigned int allocUnit;
35 } HcParcel;
36 
37 HcParcel CreateParcel(uint32_t size, uint32_t allocUnit);
38 void DeleteParcel(HcParcel *parcel);
39 void ClearParcel(HcParcel *parcel);
40 void ResetParcel(HcParcel *parcel, uint32_t size, uint32_t allocUnit);
41 HcBool ParcelReadWithoutPopData(HcParcel *parcel, void *dst, uint32_t dataSize);
42 HcBool ParcelRead(HcParcel *parcel, void *dst, uint32_t dataSize);
43 HcBool ParcelWrite(HcParcel *parcel, const void *src, uint32_t dataSize);
44 HcBool ParcelReadRevert(HcParcel *parcel, void *dst, uint32_t dataSize);
45 HcBool ParcelWriteRevert(HcParcel *parcel, const void *src, uint32_t dataSize);
46 uint32_t GetParcelDataSize(const HcParcel *parcel);
47 const char *GetParcelData(const HcParcel *parcel);
48 const char* GetParcelLastChar(const HcParcel *parcel);
49 
50 HcBool ParcelReadInt32(HcParcel *parcel, int *dst);
51 HcBool ParcelReadUint32(HcParcel *parcel, uint32_t *dst);
52 HcBool ParcelReadInt16(HcParcel *parcel, short *dst);
53 HcBool ParcelReadUint16(HcParcel *parcel, uint16_t *dst);
54 HcBool ParcelReadInt8(HcParcel *parcel, char *dst);
55 HcBool ParcelReadUint8(HcParcel *parcel, uint8_t *dst);
56 HcBool ParcelReadUint64(HcParcel *parcel, uint64_t *dst);
57 HcBool ParcelReadInt64(HcParcel *parcel, int64_t *dst);
58 HcBool ParcelWriteInt32(HcParcel *parcel, int src);
59 HcBool ParcelWriteUint32(HcParcel *parcel, uint32_t src);
60 HcBool ParcelWriteInt16(HcParcel *parcel, short src);
61 HcBool ParcelWriteUint16(HcParcel *parcel, uint16_t src);
62 HcBool ParcelWriteInt8(HcParcel *parcel, char src);
63 HcBool ParcelWriteUint8(HcParcel *parcel, uint8_t src);
64 HcBool ParcelWriteUint64(HcParcel *parcel, uint64_t src);
65 HcBool ParcelWriteInt64(HcParcel *parcel, int64_t src);
66 HcBool ParcelWriteString(HcParcel *parcel, const char *str);
67 HcBool ParcelReadString(HcParcel *parcel, char **str);
68 HcBool ParcelReadParcel(HcParcel *src, HcParcel *dst, uint32_t size, HcBool copy);
69 HcBool ParcelCopy(HcParcel *src, HcParcel *dst);
70 
71 HcBool ParcelReadInt32Revert(HcParcel *parcel, int32_t *dst);
72 HcBool ParcelReadUint32Revert(HcParcel *parcel, uint32_t *dst);
73 HcBool ParcelReadInt16Revert(HcParcel *parcel, short *dst);
74 HcBool ParcelReadUint16Revert(HcParcel *parcel, uint16_t *dst);
75 HcBool ParcelReadInt8Revert(HcParcel *parcel, char *dst);
76 HcBool ParcelReadUint8Revert(HcParcel *parcel, uint8_t *dst);
77 HcBool ParcelReadUint64Revert(HcParcel *parcel, uint64_t *dst);
78 HcBool ParcelReadInt64Revert(HcParcel *parcel, int64_t *dst);
79 HcBool ParcelWriteInt32Revert(HcParcel *parcel, int src);
80 HcBool ParcelWriteUint32Revert(HcParcel *parcel, uint32_t src);
81 HcBool ParcelWriteInt16Revert(HcParcel *parcel, short src);
82 HcBool ParcelWriteUint16Revert(HcParcel *parcel, uint16_t src);
83 HcBool ParcelWriteInt8Revert(HcParcel *parcel, char src);
84 HcBool ParcelWriteUint8Revert(HcParcel *parcel, uint8_t src);
85 HcBool ParcelWriteUint64Revert(HcParcel *parcel, uint64_t src);
86 HcBool ParcelWriteInt64Revert(HcParcel *parcel, int64_t src);
87 
88 void DataRevert(void *data, uint32_t length);
89 HcBool ParcelPopBack(HcParcel *parcel, uint32_t size);
90 HcBool ParcelPopFront(HcParcel *parcel, uint32_t size);
91 HcBool ParcelEraseBlock(HcParcel *parcel, uint32_t start, uint32_t dataSize, void *dst);
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 #endif
97