Debian Codegraph @

src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/devdoc/constbuffer_array_batcher_requirements.md

raw
1 `constbuffer_array_batcher` requirements
2 ================
3
4 ## Overview
5
6 `constbuffer_array_batcher` is a module that batches/unbatches several `CONSTBUFFER_ARRAY`s.
7
8 `constbuffer_array_batcher` understands the layout of the batches as:
9
10 | Header | Payload 0 | | |
11 |----------------------|-------------------------------|-------------------------------|-----|------------------------------|--------------------|--------------------|-----|--------------------|-----|
12 | 4 byte payload count | 4 byte payload 0 buffer count | 4 byte payload 1 buffer count | ... |4 byte payload n buffer count | payload 0 buffer 0 | payload 0 buffer 1 | ... | payload 1 buffer 0 | ... |
13
14 ## Exposed API
15
16 ```c
17 MOCKABLE_FUNCTION(, CONSTBUFFER_ARRAY_HANDLE, constbuffer_array_batcher_batch, CONSTBUFFER_ARRAY_HANDLE*, payloads, uint32_t, count);
18 MOCKABLE_FUNCTION(, CONSTBUFFER_ARRAY_HANDLE*, constbuffer_array_batcher_unbatch, CONSTBUFFER_ARRAY_HANDLE, batch, uint32_t*, payload_count);
19 ```
20
21 ### constbuffer_array_batcher_batch
22
23 ```c
24 CONSTBUFFER_ARRAY_HANDLE constbuffer_array_batcher_batch(CONSTBUFFER_ARRAY_HANDLE* payloads, uint32_t count);
25 ```
26
27 `constbuffer_array_batcher_batch` batches several const buffer arrays.
28
29 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_001: [** If `payloads` is `NULL`, `constbuffer_array_batcher_batch` shall fail and return `NULL`. **]**
30
31 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_002: [** If `count` is 0, `constbuffer_array_batcher_batch` shall fail and return `NULL`. **]**
32
33 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_023: [** If any of the payload const buffer arrays is `NULL`, `constbuffer_array_batcher_batch` shall fail and return `NULL`. **]**
34
35 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_003: [** Otherwise `constbuffer_array_batcher_batch` shall obtain the number of buffers used by each CONSTBUFFER_ARRAY. **]**
36
37 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_004: [** `constbuffer_array_batcher_batch` shall allocate memory for the header buffer (enough to hold the entire batch header namingly (`count` + 1) `uint32_t` values). **]**
38
39 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_005: [** `count` shall be written as the first `uint32_t` in the header memory. **]**
40
41 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_006: [** The count of buffers for each array in `payloads` shall also be written in the header. **]**
42
43 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_007: [** `constbuffer_array_batcher_batch` shall allocate enough memory for all the buffer handles in all the arrays + one extra header buffer handle. **]**
44
45 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_008: [** `constbuffer_array_batcher_batch` shall populate the first handle in the newly allocated handles array with the header buffer handle. **]**
46
47 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_009: [** `constbuffer_array_batcher_batch` shall populate the rest of the handles in the newly allocated handles array with the const buffer handles obtained from the arrays in `payloads`. **]**
48
49 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_010: [** If any error occurrs, `constbuffer_array_batcher_batch` shall fail and return NULL. **]**
50
51 ### constbuffer_array_batcher_unbatch
52
53 ```c
54 CONSTBUFFER_ARRAY_HANDLE* constbuffer_array_batcher_unbatch(CONSTBUFFER_ARRAY_HANDLE batch, uint32_t* payload_count);
55 ```
56
57 `constbuffer_array_batcher_unbatch` unbatches a CONSTBUFFER_ARRAY and produces the originally batched payloads.
58
59 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_011: [** If `batch` is NULL, `constbuffer_array_batcher_unbatch` shall fail and return NULL. **]**
60
61 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_012: [** If `payload_count` is NULL, `constbuffer_array_batcher_unbatch` shall fail and return NULL. **]**
62
63 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_013: [** Otherwise, `constbuffer_array_batcher_unbatch` shall obtain the number of buffers in `batch`. **]**
64
65 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_014: [** `constbuffer_array_batcher_unbatch` shall obtain the content of first (header) buffer in `batch`. **]**
66
67 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_024: [** If the size of the first buffer is less than `uint32_t` or not a multiple of `uint32_t`, `constbuffer_array_batcher_unbatch` shall fail and return NULL. **]**
68
69 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_015: [** `constbuffer_array_batcher_unbatch` shall extract the number of buffer arrays batched by reading the first `uint32_t`. **]**
70
71 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_025: [** If the number of buffer arrays does not match the size of the first buffer, `constbuffer_array_batcher_unbatch` shall fail and return NULL. **]**
72
73 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_026: [** If the number of buffer arrays in the batch is 0, `constbuffer_array_batcher_unbatch` shall fail and return NULL. **]**
74
75 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_017: [** `constbuffer_array_batcher_unbatch` shall allocate enough memory to hold the handles for buffer arrays that will be unbatched. **]**
76
77 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_016: [** `constbuffer_array_batcher_unbatch` shall extract the number of buffers in each of the batched payloads reading the `uint32_t` values encoded in the rest of the first (header) buffer. **]**
78
79 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_018: [** `constbuffer_array_batcher_unbatch` shall create a const buffer array for each of the payloads in the batch. **]**
80
81 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_019: [** On success `constbuffer_array_batcher_unbatch` shall return the array of const buffer array handles that constitute the batch. **]**
82
83 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_020: [** On success `constbuffer_array_batcher_unbatch` shall write in `payload_count` the number of const buffer arrays that are in the batch. **]**
84
85 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_021: [** If there are not enough buffers in `batch` to properly create all the payloads, `constbuffer_array_batcher_unbatch` shall fail and return NULL. **]**
86
87 **SRS_CONSTBUFFER_ARRAY_BATCHER_01_022: [** If any error occurs, `constbuffer_array_batcher_unbatch` shall fail and return NULL. **]**