Commit f336cbc6 authored by Melissa Elkadi's avatar Melissa Elkadi

Fixing pull/push array 32 and cleaning nFAPI code

Several of these changes were made previously and
lost in the merge.
parent a1dee602
...@@ -44,13 +44,21 @@ uint8_t pulls32(uint8_t **in, int32_t *out, uint8_t *end); ...@@ -44,13 +44,21 @@ uint8_t pulls32(uint8_t **in, int32_t *out, uint8_t *end);
uint32_t pullarray8(uint8_t **in, uint8_t out[], uint32_t max_len, uint32_t len, uint8_t *end); uint32_t pullarray8(uint8_t **in, uint8_t out[], uint32_t max_len, uint32_t len, uint8_t *end);
uint32_t pullarray16(uint8_t **in, uint16_t out[], uint32_t max_len, uint32_t len, uint8_t *end); uint32_t pullarray16(uint8_t **in, uint16_t out[], uint32_t max_len, uint32_t len, uint8_t *end);
uint32_t pullarrays16(uint8_t **in, int16_t out[], uint32_t max_len, uint32_t len, uint8_t *end); uint32_t pullarrays16(uint8_t **in, int16_t out[], uint32_t max_len, uint32_t len, uint8_t *end);
uint32_t pullarray32(uint8_t **in, uint32_t out[], uint32_t max_len, uint32_t len, uint8_t *end); uint32_t pullarray32(uint8_t **values_to_pull,
uint32_t out[],
uint32_t max_num_values_to_pull,
uint32_t num_values_to_pull,
uint8_t *out_end);
uint32_t pullarrays32(uint8_t **in, int32_t out[], uint32_t max_len, uint32_t len, uint8_t *end); uint32_t pullarrays32(uint8_t **in, int32_t out[], uint32_t max_len, uint32_t len, uint8_t *end);
uint32_t pusharray8(uint8_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end); uint32_t pusharray8(uint8_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end);
uint32_t pusharray16(uint16_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end); uint32_t pusharray16(uint16_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end);
uint32_t pusharrays16(int16_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end); uint32_t pusharrays16(int16_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end);
uint32_t pusharray32(uint32_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end); uint32_t pusharray32(const uint32_t *values_to_push,
uint32_t max_num_values_to_push,
uint32_t num_values_to_push,
uint8_t **out,
uint8_t *out_end);
uint32_t pusharrays32(int32_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end); uint32_t pusharrays32(int32_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end);
typedef uint8_t (*pack_array_elem_fn)(void* elem, uint8_t **ppWritePackedMsg, uint8_t *end); typedef uint8_t (*pack_array_elem_fn)(void* elem, uint8_t **ppWritePackedMsg, uint8_t *end);
......
...@@ -307,7 +307,8 @@ uint32_t pusharrays16(int16_t in[], uint32_t max_len, uint32_t len, uint8_t **ou ...@@ -307,7 +307,8 @@ uint32_t pusharrays16(int16_t in[], uint32_t max_len, uint32_t len, uint8_t **ou
uint32_t idx; uint32_t idx;
for(idx = 0; idx < len; ++idx) { for(idx = 0; idx < len; ++idx) {
pushs16(in[idx], out, end); if (!pushs16(in[idx], out, end))
return 0;
} }
return sizeof(uint16_t) * len; return sizeof(uint16_t) * len;
...@@ -316,24 +317,28 @@ uint32_t pusharrays16(int16_t in[], uint32_t max_len, uint32_t len, uint8_t **ou ...@@ -316,24 +317,28 @@ uint32_t pusharrays16(int16_t in[], uint32_t max_len, uint32_t len, uint8_t **ou
return 0; return 0;
} }
} }
uint32_t pullarray32(uint8_t **in, uint32_t out[], uint32_t max_len, uint32_t len, uint8_t *end) { uint32_t pullarray32(uint8_t **values_to_pull,
if(len == 0) uint32_t out[],
uint32_t max_num_values_to_pull,
uint32_t num_values_to_pull,
uint8_t *out_end) {
if(num_values_to_pull == 0)
return 1; return 1;
if(len > max_len) { if(num_values_to_pull > max_num_values_to_pull) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len); NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, num_values_to_pull, max_num_values_to_pull);
return 0; return 0;
} }
if((end - (*in)) >= sizeof(uint32_t) * len) { if((out_end - (*values_to_pull)) >= sizeof(uint32_t) * num_values_to_pull) {
uint32_t idx; uint32_t idx;
for(idx = 0; idx < len; ++idx) { for(idx = 0; idx < num_values_to_pull; ++idx) {
if(!pull32(in, &out[idx], end)) if(!pull32(values_to_pull, &out[idx], out_end))
return 0; return 0;
} }
return sizeof(uint32_t) * len; return sizeof(uint32_t) * num_values_to_pull;
} else { } else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__); NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
return 0; return 0;
...@@ -363,24 +368,28 @@ uint32_t pullarrays32(uint8_t **in, int32_t out[], uint32_t max_len, uint32_t le ...@@ -363,24 +368,28 @@ uint32_t pullarrays32(uint8_t **in, int32_t out[], uint32_t max_len, uint32_t le
return 0; return 0;
} }
} }
uint32_t pusharray32(uint32_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end) { uint32_t pusharray32(const uint32_t *values_to_push,
if(len == 0) uint32_t max_num_values_to_push,
uint32_t num_values_to_push,
uint8_t **out,
uint8_t *out_end) {
if(num_values_to_push == 0)
return 1; return 1;
if(len > max_len) { if(num_values_to_push > max_num_values_to_push) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, len, max_len); NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s exceed array size (%d > %d)\n", __FUNCTION__, num_values_to_push, max_num_values_to_push);
return 0; return 0;
} }
if((end - (*out)) >= sizeof(uint32_t) * len) { if((out_end - (*out)) >= sizeof(uint32_t) * num_values_to_push) {
uint32_t idx; uint32_t idx;
for(idx = 0; idx < len; ++idx) { for(idx = 0; idx < num_values_to_push; ++idx) {
if(!push32(in[idx], out, end)) if(!push32(values_to_push[idx], out, out_end))
return 0; return 0;
} }
return sizeof(uint32_t) * len; return sizeof(uint32_t) * num_values_to_push;
} else { } else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__); NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s no space in buffer\n", __FUNCTION__);
return 0; return 0;
...@@ -399,7 +408,8 @@ uint32_t pusharrays32(int32_t in[], uint32_t max_len, uint32_t len, uint8_t **ou ...@@ -399,7 +408,8 @@ uint32_t pusharrays32(int32_t in[], uint32_t max_len, uint32_t len, uint8_t **ou
uint32_t idx; uint32_t idx;
for(idx = 0; idx < len; ++idx) { for(idx = 0; idx < len; ++idx) {
pushs32(in[idx], out, end); if (!pushs32(in[idx], out, end))
return 0;
} }
return sizeof(uint32_t) * len; return sizeof(uint32_t) * len;
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment