Skip to content

Instantly share code, notes, and snippets.

@TheServer201
Last active January 16, 2017 13:25
Show Gist options
  • Save TheServer201/da649e2b20b1469e766bfa2b633ac2f6 to your computer and use it in GitHub Desktop.
Save TheServer201/da649e2b20b1469e766bfa2b633ac2f6 to your computer and use it in GitHub Desktop.
Serialize with list
typedef struct node {
uint8_t *Elem;
uint16_t Size;
struct node *Next;
} node_t;
void Node_Push(node_t **Head, uint8_t *Elem, uint16_t Size){
node_t *Node = malloc(sizeof(node_t));
Node->Elem = Elem;
Node->Size = Size;
Node->Next = *Head;
*Head = Node;
}
uint32_t Node_Size(node_t *Head){
uint32_t Size = 0;
node_t *Node = Head;
while(Node != NULL){
Size += Node->Size;
Node = Node->Next;
}
return Size;
}
void Node_Serial(node_t **Head, node_t *Resu){
node_t *Node = *Head, *Temp;
while(Node != NULL){
memcpy(Resu->Elem + Resu->Size, Node->Elem, Node->Size);
Resu->Size += Node->Size;
Temp = Node;
Node = Node->Next;
free(Temp);
}
*Head = NULL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment