Support setter/getter methods for byte array type
[platform/core/base/bundle.git] / include / bundle.h
1 /*
2  * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __BUNDLE_H__
18 #define __BUNDLE_H__
19
20 /**
21  * @file bundle.h
22  * @brief This file declares API of the bundle library.
23  */
24
25 /**
26  * @addtogroup CORE_LIB_BUNDLE_MODULE
27  * @{
28  */
29
30 #include <errno.h>
31 #include <stddef.h>
32 #include <tizen_error.h>
33
34 #ifdef __cplusplus
35 extern "C" {
36 # endif
37
38 #define API __attribute__((visibility("default")))
39 #define likely(x) __builtin_expect(x, 1)
40 #define unlikely(x) __builtin_expect(x, 0)
41
42 /**
43  * @brief Enumeration for error codes of Bundle.
44  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
45  */
46 typedef enum {
47         BUNDLE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
48         BUNDLE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
49         BUNDLE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
50         BUNDLE_ERROR_KEY_NOT_AVAILABLE = TIZEN_ERROR_KEY_NOT_AVAILABLE, /**< Required key not available */
51         BUNDLE_ERROR_KEY_EXISTS = TIZEN_ERROR_BUNDLE | 0x01, /**< Key exists */
52         BUNDLE_ERROR_ARRAY_INDEX_OUT_OF_BOUNDS = TIZEN_ERROR_BUNDLE | 0x02 /**< The index is out of bounds of the array */
53 } bundle_error_e;
54
55
56 /**
57  * @brief The bundle handle.
58  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
59  */
60 typedef struct _bundle_t bundle;
61
62
63 /**
64  * @brief The encoded data type.
65  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
66  * @see bundle_encode()
67  * @see bundle_decode()
68  */
69 typedef unsigned char bundle_raw;
70
71
72 /**
73  * @brief Enumeration for key-value pair types.
74  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
75  */
76 enum bundle_type_property {
77         BUNDLE_TYPE_ARRAY = 0x0100, /**< Array type */
78         BUNDLE_TYPE_PRIMITIVE = 0x0200, /**< Primitive type */
79         BUNDLE_TYPE_MEASURABLE = 0x0400 /**< Measurable type */
80 };
81
82
83 /**
84  * @brief Enumeration for bundle types.
85  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
86  */
87 enum bundle_type {
88         BUNDLE_TYPE_NONE = -1, /**< None */
89         BUNDLE_TYPE_ANY = 0, /**< Any type */
90         BUNDLE_TYPE_STR = 1 | BUNDLE_TYPE_MEASURABLE, /**< String type (Default) */
91         BUNDLE_TYPE_STR_ARRAY = BUNDLE_TYPE_STR | BUNDLE_TYPE_ARRAY | BUNDLE_TYPE_MEASURABLE, /**< String array type */
92         BUNDLE_TYPE_BYTE = 2, /**< Byte type */
93         BUNDLE_TYPE_BYTE_ARRAY = BUNDLE_TYPE_BYTE | BUNDLE_TYPE_ARRAY /**< Byte array type */
94 };
95
96
97 /**
98  * @brief The key-value pair handle.
99  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
100  * @see bundle_iterator_t
101  */
102 typedef struct keyval_t bundle_keyval_t;
103
104
105 /**
106  * @brief Called for every key-value pair.
107  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
108  * @param[in] key The key of key-value pair
109  * @param[in] type The type of bundle
110  * @param[in] kv The handle of key-value pair
111  * @param[in] user_data The user data
112  * @see bundle_foreach()
113  */
114 typedef void (*bundle_iterator_t) (const char *key, const int type, const bundle_keyval_t *kv, void *user_data);
115
116
117 /**
118  * @brief Creates a bundle object.
119  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
120  * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
121  * @return The bundle object
122  * @retval @c NULL - Failure
123  * @exception BUNDLE_ERROR_NONE Success
124  * @exception BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
125  * @see bundle_free()
126  *
127  * @code
128  #include <bundle.h>
129  bundle *b = bundle_create(); // Create a new bundle object
130  bundle_free(b); // Free the bundle
131  * @endcode
132  */
133 API bundle *bundle_create(void);
134
135
136 /**
137  * @brief Frees the given bundle object with key-value pairs in it.
138  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
139  * @param[in] b The bundle object to be freed
140  * @return The operation result
141  * @retval BUNDLE_ERROR_NONE Success
142  * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
143  * @pre @a b must be a valid bundle object.
144  * @see bundle_create()
145  *
146  * @code
147  #include <bundle.h>
148  bundle *b = bundle_create(); // Create a new bundle object
149  bundle_free(b); // Free the bundle
150  * @endcode
151  */
152 API int bundle_free(bundle *b);
153
154
155 /**
156  * @brief Adds a strings array type key-value pair into a given bundle.
157  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
158  * @param[in] b The bundle object
159  * @param[in] key The key
160  * @param[in] str_array The string type value; if @c NULL, an empty array is created; you can change an item with
161  * @param[in] len The length of the array
162  * @return The operation result
163  * @retval BUNDLE_ERROR_NONE Success
164  * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
165  * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
166  * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
167  * @pre @a b must be a valid bundle object.
168  * @see bundle_get_str_array()
169  *
170  * @code
171  #include <bundle.h>
172  char *sa = {"aaa", "bbb", "ccc"}; // String array of length 3
173  bundle *b = bundle_create();
174  bundle_add_str_array(b, "foo", sa, 3); // Add a key-value pair
175  bundle_free(b);
176  * @endcode
177  */
178 API int bundle_add_str_array(bundle *b, const char *key, const char **str_array, const int len);
179
180
181 /**
182  * @brief Deletes a key-value object with the given key.
183  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
184  * @param[in] b The bundle object
185  * @param[in] key The given key
186  * @return The operation result
187  * @retval BUNDLE_ERROR_NONE Success
188  * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
189  * @retval BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
190  * @pre @a b must be a valid bundle object.
191  *
192  * @code
193  #include <bundle.h>
194  bundle *b = bundle_create(); // Create a new bundle object
195  bundle_add_str(b, "foo_key", "bar_val"); // Add a key-value pair
196  bundle_del(b, "foo_key"); // Delete "foo_key" from b
197
198  bundle_free(b);
199  * @endcode
200  */
201 API int bundle_del(bundle *b, const char *key);
202
203
204 /**
205  * @brief Gets a string array from a given key.
206  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
207  * @remarks You MUST NOT free or modify the returned string. \n
208  *          The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
209  * @param[in] b The bundle object
210  * @param[in] key The key
211  * @param[out] len The array length
212  * @return The pointer to the array of strings
213  * @retval @c NULL - Key not found
214  * @exception BUNDLE_ERROR_NONE Success
215  * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
216  * @exception BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
217  * @pre @a b must be a valid bundle object.
218  * @see bundle_add_str_array()
219  *
220  * @code
221  #include <bundle.h>
222  bundle *b = bundle_create();
223  char *sa = {"aaa", "bbb", "ccc"}; // String array of length 3
224  bundle_add_str_array(b, "foo", sa, 3); // Add a key-value pair
225
226  char **str_array = NULL;
227  int len_str_array = 0;
228
229  str_array=bundle_get_str_array(b, "foo", &len_str_array);
230  // str_array = {"aaa", "bbb", "ccc"}, and len_str_array = 3
231
232  bundle_free(b);
233  * @endcode
234  */
235 API const char **bundle_get_str_array(bundle *b, const char *key, int *len);
236
237
238 /**
239  * @brief Gets the number of bundle items.
240  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
241  * @param[in] b The bundle object
242  * @return The number of bundle items
243  * @pre @a b must be a valid bundle object.
244  *
245  * @code
246  #include <bundle.h>
247  bundle *b = bundle_create(); // Create a new bundle object
248  bundle_add_str(b, "key1", "val1"); // Add a key-value pair
249  int count = bundle_get_count(b); // count = 1
250  bundle_add_str(b, "key2", "val2"); // Add another key-value pair
251  count = bundle_get_count(b); // count = 2
252
253  bundle_free(b);
254  * @endcode
255  */
256 API int bundle_get_count(bundle *b);
257
258
259 /**
260  * @brief Gets the type of the value with a given key.
261  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
262  * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
263  * @param[in] b A bundle
264  * @param[in] key A key in the bundle
265  * @return The type of a key in @a b
266  * @exception BUNDLE_ERROR_NONE Success
267  * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
268  * @exception BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
269  * @pre @a b must be a valid bundle object.
270  * @see bundle_type_t
271  */
272 API int bundle_get_type(bundle *b, const char *key);
273
274
275 /**
276  * @brief Duplicates a given bundle object.
277  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
278  * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
279  * @param[in] b_from The bundle object to be duplicated
280  * @return The new bundle object
281  * @retval @c NULL - Failure
282  * @exception BUNDLE_ERROR_NONE Success
283  * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
284  * @pre @a b must be a valid bundle object.
285  *
286  * @code
287  #include <bundle.h>
288  bundle *b = bundle_create(); // Create a new bundle object
289  bundle_add_str(b, "foo_key", "bar_val"); // Add a key-value pair
290  bundle *b_dup = bundle_dup(b); // Duplicate b
291
292  bundle_free(b);
293  bundle_free(b_dup);
294  * @endcode
295  */
296 API bundle *bundle_dup(bundle *b_from);
297
298
299 /**
300  * @brief Iterates a callback function for each key-value pair in a given bundle.
301  * @details Supports all types of values.
302  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
303  * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section. \n
304  *          This function supports all types.
305  * @param[in] b The bundle object
306  * @param[in] iter The iteration callback function
307  * @param[in] user_data The data for the callback function
308  * @exception BUNDLE_ERROR_NONE Success
309  * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
310  * @pre @a b must be a valid bundle object.
311  * @see bundle_keyval_get_type()
312  * @see bundle_keyval_type_is_array()
313  * @see bundle_keyval_get_basic_val()
314  * @see bundle_keyval_get_array_val()
315  *
316  * @code
317  #include <stdio.h>
318  #include <bundle.h>
319  void
320  sample_cb(const char *key, const int type, const bundle_keyval_t *kv, void *user_data)
321  {
322      void *basic_val = NULL;
323      size_t basic_size = 0;
324      void **array_val = NULL;
325      int array_len = 0;
326      size_t *array_elem_size = NULL;
327
328      printf("Key:%s, Type:%d\n", key, type);
329      if (bundle_keyval_type_is_array(kv)) {
330          bundle_keyval_get_array_val(kv, &array_val, &array_len, &array_elem_size);
331          // Do something
332      }
333      else {
334          bundle_keyval_get_basic_val(kv, &basic_val, &basic_size);
335          // Do something
336      }
337  }
338
339  int main(void)
340  {
341      bundle *b = bundle_create(); // Create a new bundle object
342      bundle_add_str(b, "k1", "v1"); // Add a key-value pair
343      bundle_add_byte(b, "k2", "v2", 3); // Add a key-value pair
344      char *s_arr[] = {"abc", "bcd", "cde"};
345      bundle_add_str_array(b, "k3", s_arr, 3); // Add a key-value pair
346      bundle_foreach(b, sample_cb, NULL); // Iterate sample_cb() for each key/value
347
348      return 0;
349  }
350  * @endcode
351  */
352 API void bundle_foreach(bundle *b, bundle_iterator_t iter, void *user_data);
353
354
355 /**
356  * @brief Gets the type of a key-value pair.
357  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
358  * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
359  * @param[in] kv A bundle_keyval_t object
360  * @return The type of @a kv
361  * @retval @c -1 - Failure
362  * @exception BUNDLE_ERROR_NONE Success
363  * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
364  * @pre @a kv must be a valid bundle_keyval_t object.
365  * @see bundle_foreach()
366  */
367 API int bundle_keyval_get_type(bundle_keyval_t *kv);
368
369
370 /**
371  * @brief Determines whether the type of a key-value pair is an array.
372  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
373  * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
374  * @param[in] kv A bundle_keyval_t object
375  * @return The operation result
376  * @retval @c 1 - @a kv is an array
377  * @retval @c 0 - @a kv is not an array
378  * @exception BUNDLE_ERROR_NONE Success
379  * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
380  * @pre @a kv must be a valid bundle_keyval_t object.
381  * @see bundle_foreach()
382  */
383 API int bundle_keyval_type_is_array(bundle_keyval_t *kv);
384
385
386 /**
387  * @brief Gets the value and size of the value from a key-value pair of basic type.
388  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
389  * @remarks You must not free @a val.
390  * @param[in] kv A bundle_keyval_t object
391  * @param[out] val The value
392  * @param[out] size The size of @a val
393  * @return The operation result
394  * @retval BUNDLE_ERROR_NONE Success
395  * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
396  * @pre @a kv must be a valid bundle_keyval_t object.
397  * @post @a val and @a size are set.
398  * @see bundle_foreach()
399  */
400 API int bundle_keyval_get_basic_val(bundle_keyval_t *kv, void **val, size_t *size);
401
402
403 /**
404  * @brief Gets the value array, length of the array, and size of each array item.
405  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
406  * @param[in] kv A bundle_keyval_t object
407  * @param[out] array_val The array pointer of values
408  * @param[out] array_len The length of @a array_val
409  * @param[out] array_element_size The array of size of each array element
410  * @return The operation result
411  * @retval BUNDLE_ERROR_NONE Success
412  * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
413  * @pre @a kv must be a valid bundle_keyval_t object.
414  * @post @a array_val, @a array_len, @a array_item_size are set.
415  * @see bundle_foreach()
416  */
417 API int bundle_keyval_get_array_val(bundle_keyval_t *kv, void ***array_val, unsigned int *array_len, size_t **array_element_size);
418
419
420 /**
421  * @brief Encodes a bundle to the bundle_raw format (uses base64 format).
422  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
423  * @param[in] b The bundle object
424  * @param[out] r The returned bundle_raw data(byte data)
425  *               @a r MUST BE FREED by free(r)
426  * @param[out] len The size of @a r (in bytes)
427  * @return The size of the raw data
428  * @retval BUNDLE_ERROR_NONE Success
429  * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
430  * @pre @a b must be a valid bundle object.
431  *
432  * @code
433  #include <bundle.h>
434  bundle *b = bundle_create(); // Create a new bundle object
435  bundle_add_str(b, "foo_key", "bar_val"); // Add a key-value pair
436  bundle_raw *r;
437  int len;
438  bundle_encode(b, &r, &len); // Encode b
439
440  bundle_free(b);
441  * @endcode
442  */
443 API int bundle_encode(bundle *b, bundle_raw **r, int *len);
444
445
446 /**
447  * @brief Deserializes bundle_raw and gets the bundle object.
448  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
449  * @remarks The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
450  * @param[in] r The bundle_raw data to be converted to bundle object
451  * @param[in] len The size of @a r
452  * @return The bundle object
453  * @retval @c NULL - Failure
454  * @exception BUNDLE_ERROR_NONE Success
455  * @exception BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
456  * @pre @a b must be a valid bundle object.
457  *
458  * @code
459  #include <bundle.h>
460  bundle *b = bundle_create(); // Create a new bundle object
461  bundle_add_str(b, "foo_key", "bar_val"); // Add a key-value pair
462
463  bundle_raw *encoded_b;
464  int len;
465  bundle_encode(b, &encoded_b, &len); // Encode b
466
467  bundle *b_dup;
468  b_dup = bundle_decode(encoded_b, len); // Decoded bundle object
469
470  bundle_free(b);
471  free(encoded_b);
472  bundle_free(b_dup);
473  * @endcode
474  */
475 API bundle *bundle_decode(const bundle_raw *r, const int len);
476
477
478 /**
479  * @brief Adds a string type key-value pair into a bundle.
480  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
481  * @param[in] b The bundle object
482  * @param[in] key The key
483  * @param[in] str The string type value
484  * @return The operation result
485  * @retval BUNDLE_ERROR_NONE Success
486  * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
487  * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
488  * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
489  * @pre @a b must be a valid bundle object.
490  * @see bundle_get_str()
491  * @code
492  #include <bundle.h>
493  bundle *b = bundle_create(); // Create a new bundle object
494  bundle_add_str(b, "foo", "bar"); // Add a key-value pair
495
496  bundle_free(b);
497  * @endcode
498  */
499 API int bundle_add_str(bundle *b, const char *key, const char *str);
500
501
502 /**
503  * @brief Adds a byte sequence type key-value pair into a bundle.
504  * @details The bundle will contain a copy of the added byte sequence.
505  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
506  * @param[in] b The bundle object
507  * @param[in] key The key
508  * @param[in] bytes The byte sequence
509  * @param[in] size The byte sequence size in bytes
510  * @return The operation result
511  * @retval BUNDLE_ERROR_NONE Success
512  * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
513  * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
514  * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
515  * @pre @a b must be a valid bundle object.
516  * @see bundle_get_byte()
517  *
518  * @code
519  #include <bundle.h>
520  bundle *b = bundle_create(); // Create a new bundle object
521  bundle_add_byte(b, "foo", "bar\0", 4); // Add a key-value pair
522
523  int number = 12345;
524  bundle_add_byte(b, "number", &number, sizeof(int));
525
526  bundle_free(b);
527  * @endcode
528  */
529 API int bundle_add_byte(bundle *b, const char *key, const void *bytes, const size_t size);
530
531
532 /**
533  * @brief Gets the string value with the given key.
534  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
535  * @remarks You must not free str.
536  * @param[in] b The bundle object
537  * @param[in] key The key
538  * @param[out] str The returned value
539  * @return The operation result
540  * @retval BUNDLE_ERROR_NONE Success
541  * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
542  * @retval BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
543  * @pre @a b must be a valid bundle object.
544  * @see bundle_add_str()
545  *
546  * @code
547  #include <bundle.h>
548  bundle *b = bundle_create(); // Create a new bundle object
549  bundle_add_str(b, "foo_key", "bar_val"); // Add a key-value pair
550
551  char *v = NULL;
552  bundle_get_str(b, "foo_key", &v); // v = "bar_val"
553
554  bundle_free(b); // After freeing b, v becomes a dangling pointer
555  v = NULL;
556  * @endcode
557  */
558 API int bundle_get_str(bundle *b, const char *key, char **str);
559
560
561 /**
562  * @brief Gets the byte sequence with the given key.
563  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
564  * @remarks You must not free @a byte.
565  * @param[in] b The bundle object
566  * @param[in] key The key
567  * @param[out] bytes The byte sequence
568  * @param[out] size The byte sequence size in bytes
569  * @return The operation result
570  * @retval BUNDLE_ERROR_NONE Success
571  * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
572  * @retval BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
573  * @pre @a b must be a valid bundle object.
574  * @see bundle_add_byte()
575  *
576  * @code
577  #include <bundle.h>
578  bundle *b = bundle_create(); // Create a new bundle object
579  bundle_add_byte(b, "foo", "bar\0", 4); // Add a string to the bundle
580  int number = 12345;
581  bundle_add_byte(b, "number", (const void**)&number, sizeof(int)); // Add an integer to the bundle
582
583  unsigned char *v = NULL;
584  size_t v_size;
585  bundle_get_byte(b, "foo", (void**)&v, &v_size); // v = "bar\0"
586  int *n = NULL;
587  size_t n_size;
588  bundle_get_byte(b, "number", (void**)&n, &n_size); // number = 12345
589
590  bundle_free(b); // After freeing b, v and n become a dangling pointer
591  * @endcode
592  */
593 API int bundle_get_byte(bundle *b, const char *key, void **bytes, size_t *size);
594
595 /**
596  * @brief Adds an 'array of byte sequences' type key-value pair into a bundle.
597  * @since_tizen 5.5
598  * @remarks To set the value of the byte array element, you should use bundle_set_byte_array_element().
599  *          This function is only for creating a buffer of the byte array.
600  *
601  * @param[in]   b                       The bundle object
602  * @param[in]   key                     The key
603  * @param[in]   len                     The length of the array to be created
604  * @return      @c 0 on success,
605  *              otherwise a negative error value
606  * @retval #BUNDLE_ERROR_NONE Successful
607  * @retval #BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
608  * @retval #BUNDLE_ERROR_KEY_EXISTS Key already exists
609  * @retval #BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
610  *
611  * @see bundle_get_byte_array()
612  * @see bundle_set_byte_array_element()
613  */
614 API int bundle_add_byte_array(bundle *b, const char *key, const unsigned int len);
615
616 /**
617  * @brief Sets an element of an array of byte sequences.
618  * @since_tizen 5.5
619  * @details The array will contain its own copy of the added value.
620  *
621  * @param[in]   b                       The bundle object
622  * @param[in]   key                     The key
623  * @param[in]   idx                     The index of the array element to be changed
624  * @param[in]   bytes                   The byte sequence
625  * @param[in]   size                    The byte sequence size in bytes
626  * @return      @c 0 on success,
627  *              otherwise a negative error value
628  * @retval #BUNDLE_ERROR_NONE Successful
629  * @retval #BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
630  * @retval #BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
631  * @retval #BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
632  * @retval #BUNDLE_ERROR_ARRAY_INDEX_OUT_OF_BOUNDS The index is out of bounds of the array
633  *
634  * @see bundle_add_byte_array()
635  * @see bundle_get_byte_array()
636  */
637 API int bundle_set_byte_array_element(bundle *b, const char *key, const unsigned int idx, const void *bytes, const size_t size);
638
639 /**
640  * @brief Gets the array of byte sequences with the given key.
641  * @since_tizen 5.5
642  * @remarks You should not release @a byte_array, @a len and @a array_element_size.
643  *          @a byte_array, @a len and @a array_element_size will be released when the bundle containing them is released with bundle_free().
644  *
645  * @param[in]   b                       The bundle object
646  * @param[in]   key                     The key
647  * @param[out]  byte_array              The array pointer of the byte value
648  * @param[out]  len                     The array length
649  * @param[out]  array_element_size      An array of sizes of each @a byte_array element
650  * @return      @c 0 on success,
651  *              otherwise a negative error value
652  * @retval #BUNDLE_ERROR_NONE Successful
653  * @retval #BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
654  * @retval #BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
655  *
656  * @see bundle_add_byte_array()
657  * @see bundle_set_byte_array_element()
658 */
659 API int bundle_get_byte_array(bundle *b, const char *key, void ***byte_array, unsigned int *len, unsigned int **array_element_size);
660
661 #ifdef __cplusplus
662 }
663 #endif
664
665 /**
666  * @}
667  */
668
669 #endif /* __BUNDLE_H__ */