Serialization of packages with C
===

Im new here and Ill love your help.
Im trying to serialize and deserialize a package (to use it in sockets) and the results are not the ones that I expect but I cant find the mistake. Here´s the code.

    typedef struct {
		int32_t size;
		char data[1024];
    } t_socket_buffer;

    typedef struct {
		int16_t payloadLength;
		int8_t type;
		char *path;
    } ReadRequestPackage;

The function that serializes

    t_socket_buffer *Open_serializer(ReadRequestPackage *ReadPackage){
	char data[1024];
	t_socket_buffer *stream = malloc(sizeof(t_socket_buffer));
	int8_t offset = 0, tmp_size = 0;


	memcpy(data, &ReadPackage->payloadLength, tmp_size = sizeof(int16_t));

	offset = tmp_size;
	memcpy(data + offset,&ReadPackage->type, tmp_size = sizeof(int8_t));


	offset+= tmp_size;
	memcpy(data + offset, ReadPackage->path,tmp_size = strlen(ReadPackage->path)+1);


	stream->size = offset + tmp_size;
	memcpy(stream->data, data,strlen(data)+1);

	return stream;

        }
The function that DEserializes

        ReadRequestPackage *Open_deserializer(t_socket_buffer *stream)
        {
	ReadRequestPackage *ReadPackage = malloc(sizeof(ReadRequestPackage));
	int32_t offset = 0, tmp_size = 0;

	memcpy(&ReadPackage->payloadLength,stream->data,tmp_size = sizeof(int16_t));

	offset = tmp_size;
	memcpy(&ReadPackage->type, stream->data + offset, tmp_size = sizeof(int8_t));

	offset += tmp_size;
	for(tmp_size = 1; (stream->data + offset)[tmp_size-1]!='\0';tmp_size++);
	ReadPackage->path = malloc(tmp_size);
	memcpy(ReadPackage->path, stream->data + offset, tmp_size);



	return ReadPackage;

         }

When I test it with this main()

    int main (void){
    ReadRequestPackage *pqt1 = malloc(sizeof(ReadRequestPackage));
    ReadRequestPackage *pqt2;

    t_socket_buffer *stream;
    pqt1->path=malloc(sizeof("directory"));
    strcpy(pqt1->path,"directory");
    pqt1->payloadLength = strlen("directory")+1+sizeof(int8_t);
    pqt1->type  = 1;
    
    stream = Open_serializer(pqt1);
    pqt2 = Open_deserializer(stream);
    printf("path 1: ");
    puts(pqt1->path);
    printf("path 2: ");
     puts(pqt2->path);
    printf("\ntype1:%d ",pck1->type);
    printf("\ntype2:%d ",pck2->type);
    printf("\nize:%d ",pck1->payloadLength);
    printf("\nsize:%d ",pck2->payloadLength);
  
    return 1;
    }

The results are not the same and they should!

Thank you very much!