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 <stdbool.h> 21 #include "memory.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #define PARCEL_DEFAULT_LENGTH 0 28 #define PARCEL_DEFAULT_ALLOC_UNIT 0 29 30 typedef struct { 31 char *data; 32 unsigned int beginPos; 33 unsigned int endPos; 34 unsigned int length; 35 unsigned int allocUnit; 36 } HcParcel; 37 38 HcParcel CreateParcel(uint32_t size, uint32_t allocUnit); 39 void DeleteParcel(HcParcel *parcel); 40 bool ParcelWrite(HcParcel *parcel, const void *src, uint32_t dataSize); 41 uint32_t GetParcelDataSize(const HcParcel *parcel); 42 const char *GetParcelData(const HcParcel *parcel); 43 44 bool ParcelWriteInt8(HcParcel *parcel, char src); 45 bool ParcelPopBack(HcParcel *parcel, uint32_t size); 46 47 #ifdef __cplusplus 48 } 49 #endif 50 #endif 51