1 /******************************************************************
3 * Copyright 2015 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 * LICENSE-2.0" target="_blank">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.
20 ******************************************************************/
23 #ifndef _BYTE_ARRAY_H_
24 #define _BYTE_ARRAY_H_
37 * General purpose byte array structure.
39 * Contains pointer to array of bytes and it's length.
44 uint8_t *data; /**< Pointer to the byte array */
45 size_t len; /**< Data size */
49 /**@def BYTE_ARRAY_INITIALIZER
51 * Initializes of existing byte array pointer to \a NULL.
53 #undef BYTE_ARRAY_INITIALIZER
54 #define BYTE_ARRAY_INITIALIZER {NULL, 0}
56 /**@def INIT_BYTE_ARRAY(array)
58 * Initializes of existing byte array \a array.
60 * @param array ByteArray
62 #undef INIT_BYTE_ARRAY
63 #define INIT_BYTE_ARRAY(array) do{ \
64 (array).data = NULL; \
68 /**@def PRINT_BYTE_ARRAY(msg, array)
70 * Prints out byte array \a array in hex representation with message \a msg.
72 * @param msg string of characters
73 * @param array byte array
75 #undef PRINT_BYTE_ARRAY
76 #define PRINT_BYTE_ARRAY(msg, array) do{ \
78 printf("%10s", msg); \
79 for( i=0; i< (array).len; i++) { \
80 if( (i!=0) && ((i%16)==0) ) putchar('\n'); \
81 printf("%02X ", (array).data[i]); \
86 /**@def INC_BYTE_ARRAY_PTR(array, size)
88 * Increments byte array pointer \a array by \a size.
90 * @param array byte array pointer
91 * @param size number of positions
93 #undef INC_BYTE_ARRAY_PTR
94 #define INC_BYTE_ARRAY_PTR(array, size) do{ \
95 (array)->data += size; \
96 (array)->len -= size; \
99 /**@def INC_BYTE_ARRAY(array, size)
101 * Increments byte array \a array by \a size.
103 * @param array byte array
104 * @param size number of positions
106 #undef INC_BYTE_ARRAY
107 #define INC_BYTE_ARRAY(array, size) do{ \
108 (array).data += size; \
109 (array).len -= size; \
116 #endif // _BYTE_ARRAY_H_