Last active
January 16, 2017 13:25
-
-
Save TheServer201/da649e2b20b1469e766bfa2b633ac2f6 to your computer and use it in GitHub Desktop.
Serialize with list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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