1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 #include "camsgparser.h"
27 #include "caadapterutils.h"
30 * @var CA_MSG_PARSER_TAG
31 * @brief debugging tag for parser module
33 #define CA_MSG_PARSER_TAG "CA_MSG_PARSER"
35 CAResult_t CAGenerateHeader(char *header, uint32_t length)
37 OIC_LOG(DEBUG, CA_MSG_PARSER_TAG, "IN");
39 VERIFY_NON_NULL(header, CA_MSG_PARSER_TAG, "header is NULL");
40 memset(header, 0x0, sizeof(char) * CA_HEADER_LENGTH);
42 if(length > MAX_DATA_LENGTH_SUPPORTED)
44 OIC_LOG(DEBUG, CA_MSG_PARSER_TAG, "Given length is more than 4095.It will be truncated");
46 //if length is more than 4095 then it will be truncated.
47 header[1] = length & 0xFF;
49 header[0] = length & 0x0F;
50 header[0] = header[0] | 0x40; // Adding version 0100.(Not used. Future use)
52 OIC_LOG(DEBUG, CA_MSG_PARSER_TAG, "OUT");
56 uint32_t CAParseHeader(const char *header)
58 OIC_LOG(DEBUG, CA_MSG_PARSER_TAG, "IN");
60 VERIFY_NON_NULL(header, CA_MSG_PARSER_TAG, "header is NULL");
62 uint32_t dataLen = ((header[0] & 0x0F) << 8) | (header[1] & 0xFF);
64 OIC_LOG(DEBUG, CA_MSG_PARSER_TAG, "OUT");