Commit 344ac8d1 authored by Sven Liefgen's avatar Sven Liefgen
Browse files

Update prrt/proto/types/packet.c, prrt/proto/types/packet.h files

parent f5b9b47a
Pipeline #4557 failed with stages
in 12 seconds
...@@ -128,27 +128,31 @@ create_header(uint8_t priority, prrtSequenceNumber_t seqno, prrtPacketLength_t s ...@@ -128,27 +128,31 @@ create_header(uint8_t priority, prrtSequenceNumber_t seqno, prrtPacketLength_t s
return NULL; return NULL;
} }
bool PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) { bool PrrtPacket_encode_payload(void *buf_ptr, PrrtPacket *packet_ptr) {
void *payload = packet_ptr->payload;
check(packet_ptr->payloadLength + PRRT_PACKET_ENCODED_GENERAL_HEADER_LENGTH <= buf_size, "Buffer too small.");
buf_ptr = encode_general_header(buf_ptr, packet_ptr);
prrtPacketType_t type = PrrtPacket_type(packet_ptr); prrtPacketType_t type = PrrtPacket_type(packet_ptr);
if (type == PACKET_TYPE_DATA) { if (type == PACKET_TYPE_DATA) {
buf_ptr = encode_data_header(buf_ptr, payload); buf_ptr = encode_data_header(buf_ptr, packet_ptr->payload);
PrrtPacket_copy_payload_to_buffer(buf_ptr, packet_ptr, PRRT_PACKET_DATA_HEADER_SIZE); PrrtPacket_copy_payload_to_buffer(buf_ptr, packet_ptr, PRRT_PACKET_DATA_HEADER_SIZE);
} else if (type == PACKET_TYPE_REDUNDANCY) { } else if (type == PACKET_TYPE_REDUNDANCY) {
buf_ptr = encode_redundancy_header(buf_ptr, payload); buf_ptr = encode_redundancy_header(buf_ptr, packet_ptr->payload);
PrrtPacket_copy_payload_to_buffer(buf_ptr, packet_ptr, PRRT_PACKET_REDUNDANCY_HEADER_SIZE); PrrtPacket_copy_payload_to_buffer(buf_ptr, packet_ptr, PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
} else if (type == PACKET_TYPE_FEEDBACK) { } else if (type == PACKET_TYPE_FEEDBACK) {
encode_feedback_header(buf_ptr, payload); encode_feedback_header(buf_ptr, packet_ptr->payload);
} else { } else {
perror("NOT IMPLEMENTED"); perror("NOT IMPLEMENTED");
return false; return false;
} }
return true; return true;
}
bool PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr) {
void *payload = packet_ptr->payload;
check(packet_ptr->payloadLength + PRRT_PACKET_ENCODED_GENERAL_HEADER_LENGTH <= buf_size, "Buffer too small.");
buf_ptr = encode_general_header(buf_ptr, packet_ptr);
return PrrtPacket_encode_payload(buf_ptr, packet_ptr);
error: error:
return false; return false;
...@@ -216,6 +220,22 @@ void *encode_general_header(void *buf_ptr, const PrrtPacket *packet) { ...@@ -216,6 +220,22 @@ void *encode_general_header(void *buf_ptr, const PrrtPacket *packet) {
return buf_ptr; return buf_ptr;
} }
bool PrrtPacket_decode_payload(void *srcBuffer, prrtPacketType_t packetType, void *payload, uint32_t payload_len) {
if (packetType == PACKET_TYPE_DATA) {
srcBuffer = decode_data_header(srcBuffer, payload);
memcpy(payload + PRRT_PACKET_DATA_HEADER_SIZE, srcBuffer, payload_len - PRRT_PACKET_DATA_HEADER_SIZE);
} else if (packetType == PACKET_TYPE_REDUNDANCY) {
srcBuffer = decode_redundancy_header(srcBuffer, targetPacket->payload);
memcpy(payload + PRRT_PACKET_REDUNDANCY_HEADER_SIZE, srcBuffer, payload_len - PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
} else if (packetType == PACKET_TYPE_FEEDBACK) {
decode_feedback_header(srcBuffer, payload);
} else {
perror("NOT IMPLEMENTED\n");
return false;
}
return true;
}
bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket) { bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket) {
// targetPacket is uninitialized, so we need to set the reference count // targetPacket is uninitialized, so we need to set the reference count
...@@ -238,18 +258,7 @@ bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targ ...@@ -238,18 +258,7 @@ bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targ
targetPacket->payloadLength = payload_len; targetPacket->payloadLength = payload_len;
prrtPacketType_t packetType = PrrtPacket_type(targetPacket); prrtPacketType_t packetType = PrrtPacket_type(targetPacket);
if (packetType == PACKET_TYPE_DATA) { return PrrtPacket_decode_payload(srcBuffer, packetType, payload_buffer, payload_len);
srcBuffer = decode_data_header(srcBuffer, payload_buffer);
PrrtPacket_copy_buffer_to_payload(targetPacket, srcBuffer, PRRT_PACKET_DATA_HEADER_SIZE);
} else if (packetType == PACKET_TYPE_REDUNDANCY) {
srcBuffer = decode_redundancy_header(srcBuffer, payload_buffer);
PrrtPacket_copy_buffer_to_payload(targetPacket, srcBuffer, PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
} else if (packetType == PACKET_TYPE_FEEDBACK) {
decode_feedback_header(srcBuffer, payload_buffer);
} else {
printf("NOT IMPLEMENTED\n");
}
return true;
error: error:
return false; return false;
......
...@@ -162,8 +162,10 @@ PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *payloadP ...@@ -162,8 +162,10 @@ PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *payloadP
PrrtCodingConfiguration *codingParams); PrrtCodingConfiguration *codingParams);
bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket); bool PrrtPacket_decode(void *srcBuffer, uint16_t srcBufferSize, PrrtPacket *targetPacket);
bool PrrtPacket_decode_payload(void *srcBuffer, PrrtPacket *targetPacket);
bool PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr); bool PrrtPacket_encode(void *buf_ptr, uint16_t buf_size, PrrtPacket *packet_ptr);
bool PrrtPacket_encode_payload(void *buf_ptr, PrrtPacket *packet_ptr);
int PrrtPacket_destroy(PrrtPacket *packet); int PrrtPacket_destroy(PrrtPacket *packet);
......
Supports Markdown
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