+#if !defined(ENABLE_ANNOTATIONS)
+# error annotation support has to be enabled when compling this file!
+#endif
+
+/* annotation_bytearray_new ***************************************************
+
+ Allocate a new bytearray.
+
+*******************************************************************************/
+
+annotation_bytearray_t *annotation_bytearray_new(uint32_t size)
+{
+ annotation_bytearray_t *ba =
+ mem_alloc(sizeof(uint32_t) + sizeof(uint8_t) * size);
+
+ if (ba != NULL) {
+ ba->size = size;
+ }
+
+ return ba;
+}
+
+
+/* annotation_bytearray_free **************************************************
+
+ Free a bytearray.
+
+*******************************************************************************/
+
+void annotation_bytearray_free(annotation_bytearray_t *ba)
+{
+ if (ba != NULL) {
+ mem_free(ba, sizeof(uint32_t) + sizeof(uint8_t) * ba->size);
+ }
+}
+
+
+/* annotation_bytearrays_new **************************************************
+
+ Allocate a new array of bytearrays.
+
+*******************************************************************************/
+
+annotation_bytearrays_t *annotation_bytearrays_new(uint32_t size)
+{
+ annotation_bytearrays_t *bas =
+ mem_alloc(sizeof(uint32_t) + sizeof(annotation_bytearray_t*) * size);
+
+ if (bas != NULL) {
+ bas->size = size;
+ }
+
+ return bas;
+}
+
+
+/* annotation_bytearrays_resize ***********************************************
+
+ Resize an array of bytearrays.
+
+*******************************************************************************/
+
+bool annotation_bytearrays_resize(annotation_bytearrays_t **bas,
+ uint32_t size)
+{
+ annotation_bytearrays_t *newbas = NULL;
+ uint32_t i;
+ uint32_t minsize;
+
+ assert(bas != NULL);
+
+ newbas = annotation_bytearrays_new(size);
+
+ if (newbas == NULL) {
+ return false;
+ }
+
+ if (*bas != NULL) {
+ minsize = size < (*bas)->size ? size : (*bas)->size;
+
+ for (i = size; i < (*bas)->size; ++ i) {
+ annotation_bytearray_free((*bas)->data[i]);
+ }
+
+ for (i = 0; i < minsize; ++i) {
+ newbas->data[i] = (*bas)->data[i];
+ }
+ }
+
+ *bas = newbas;
+
+ return true;
+}
+
+
+/* annotation_bytearrays_insert ***********************************************
+
+ Insert a bytearray into an array of bytearrays.