add tlv8_encode_n

This commit is contained in:
hathach committed 2018-01-15 15:13:04 +07:00
1 parent a0dc1eced5
commit 83ad264e35
3 files changed
+14 -5

No files matched your search

@@ -198,11 +198,7 @@ HAPResponse_t* HAPCharacteristic::createHapResponse(uint8_t tid, uint8_t status,
hap_resp->body_len = body_len;
/*------------- Serialize Data -------------*/
uint8_t* pdata = hap_resp->body_data;
for(uint8_t i=0; i < count; i++)
{
if ( !tlv8_encode_next(&pdata, &body_len, tlv_para[i]) ) break;
}
tlv8_encode_n(hap_resp->body_data, body_len, tlv_para, count);
return hap_resp;
}
+12
View File
@@ -131,3 +131,15 @@ bool tlv8_encode_next(uint8_t** pp_buf, uint16_t* p_buflen, TLV8_t tlv)
return true;
}
uint16_t tlv8_encode_n(uint8_t* buf, uint16_t bufsize, TLV8_t tlv[], uint8_t count)
{
uint16_t len = bufsize;
for(uint8_t i=0; i < count; i++)
{
if( !tlv8_encode_next(&buf, &bufsize, tlv[i]) ) break;
}
return len - bufsize;
}
+1
View File
@@ -151,6 +151,7 @@ typedef struct ATTR_PACKED
TLV8_t tlv8_decode_next(uint8_t const** pp_data, uint16_t* p_len, void* buf = NULL, uint16_t bufsize = 0);
bool tlv8_encode_next(uint8_t** pp_buf, uint16_t* p_buflen, TLV8_t tlv);
uint16_t tlv8_encode_n(uint8_t* buf, uint16_t bufsize, TLV8_t tlv[], uint8_t count);
uint16_t tlv8_calculate_encode_len(TLV8_t tlv_para[], uint8_t count);
#endif /* HAPPROCEDURE_H_ */