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 16 #ifndef TLV_WRAPPER_H 17 #define TLV_WRAPPER_H 18 19 #include <stdint.h> 20 21 #include "tlv_base.h" 22 #include "buffer.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 #define MAX_BUFFER_SIZE 512000 29 #define TLV_HEADER_LEN (sizeof(int32_t) + sizeof(uint32_t)) 30 31 int32_t ParseTlvWrapper(const uint8_t *buffer, uint32_t bufferSize, TlvListNode *head); 32 int32_t ParseGetHeadTag(const TlvListNode *node, int32_t *tag); 33 34 int32_t ParseUint64Para(TlvListNode *node, int32_t msgType, uint64_t *retVal); 35 int32_t ParseInt64Para(TlvListNode *node, int32_t msgType, int64_t *retVal); 36 int32_t ParseUint32Para(TlvListNode *node, int32_t msgType, uint32_t *retVal); 37 int32_t ParseInt32Para(TlvListNode *node, int32_t msgType, int32_t *retVal); 38 Buffer *ParseBuffPara(TlvListNode *node, int32_t msgType); 39 int32_t ParseUint8Para(TlvListNode *node, int32_t msgType, uint8_t *retVal); 40 41 int32_t GetUint64Para(TlvListNode *head, int32_t msgType, uint64_t *retVal); 42 int32_t GetUint32Para(TlvListNode *head, int32_t msgType, uint32_t *retVal); 43 int32_t GetInt32Para(TlvListNode *head, int32_t msgType, int32_t *retVal); 44 Buffer *GetBuffPara(TlvListNode *head, int32_t msgType); 45 46 int32_t TlvAppendObject(TlvListNode *head, int32_t type, const uint8_t *buffer, uint32_t length); 47 int32_t SerializeTlvWrapper(TlvListNode *head, uint8_t *buffer, uint32_t maxSize, uint32_t *contentSize); 48 49 #ifdef __cplusplus 50 } 51 #endif 52 53 #endif // TLV_WRAPPER_H