Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[struct_pack] how to support QString and QTL of Qt #764

Closed
2 tasks
xiaocai123123 opened this issue Aug 23, 2024 · 10 comments · Fixed by #776
Closed
2 tasks

[struct_pack] how to support QString and QTL of Qt #764

xiaocai123123 opened this issue Aug 23, 2024 · 10 comments · Fixed by #776

Comments

@xiaocai123123
Copy link

Search before asking

  • I searched the issues and found no similar issues.

What happened + What you expected to happen

When i use struct_pack to serialized a struct like below
struct Test
{
QString str;
QVector iArray;
QMap<QString, QString> name2Sb;
};
An error occurred during compile when i use struct_pack::serializestd::string(Test):1.If the struct is empty,which is not allowed in struct_pack type system.

Reproduction way

Anything else

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!
@poor-circle
Copy link
Collaborator

struct Test
{
QString str;
QVector iArray;
QMap<QString, QString> name2Sb;
};
template <>
constexpr std::size_t struct_pack::members_count<Test> = 3;

Could you try this?

@xiaocai123123
Copy link
Author

It’s not working.
I think I'm using the Qt third-party library data type like QString、QVector、QMap, and I don't know how to integrate it with struct_pack.
Maybe i can only use std::string、std::vector、std::map

@poor-circle
Copy link
Collaborator

It’s not working. I think I'm using the Qt third-party library data type like QString、QVector、QMap, and I don't know how to integrate it with struct_pack. Maybe i can only use std::string、std::vector、std::map

Could you show me the error message

@poor-circle
Copy link
Collaborator

It’s not working. I think I'm using the Qt third-party library data type like QString、QVector、QMap, and I don't know how to integrate it with struct_pack. Maybe i can only use std::string、std::vector、std::map

Here is a example of support third-party type:

https://alibaba.github.io/yalantinglibs/en/struct_pack/struct_pack_intro.html#the-type-cannot-be-abstracted-to-a-type-already-in-the-type-system-1

@poor-circle
Copy link
Collaborator

You can add the helper function in QT namespace to support Qstring/QVector/QMap.

@xiaocai123123
Copy link
Author

The error message was
"1. If the struct is empty, which is not allowed in struct_pack type system.\n"
"2. If the strut is not empty, it means struct_pack can't calculate your struct members' count. You can use macro STRUCT_PACK_REFL(Typename, field1, field2...)."

Yes! I am learning how to integrate third party library types and it is a learning process. Thanks a lot!

@poor-circle
Copy link
Collaborator

The error message was "1. If the struct is empty, which is not allowed in struct_pack type system.\n" "2. If the strut is not empty, it means struct_pack can't calculate your struct members' count. You can use macro STRUCT_PACK_REFL(Typename, field1, field2...)."

Yes! I am learning how to integrate third party library types and it is a learning process. Thanks a lot!

Or you can try this:

struct Test
{
QString str;
QVector iArray;
QMap<QString, QString> name2Sb;
};
STRUCT_PACK_REFL(Test, str, iArray, name2Sb);

@xiaocai123123
Copy link
Author

The error message was "1. If the struct is empty, which is not allowed in struct_pack type system.\n" "2. If the strut is not empty, it means struct_pack can't calculate your struct members' count. You can use macro STRUCT_PACK_REFL(Typename, field1, field2...)."
Yes! I am learning how to integrate third party library types and it is a learning process. Thanks a lot!

Or you can try this:

struct Test
{
QString str;
QVector iArray;
QMap<QString, QString> name2Sb;
};
STRUCT_PACK_REFL(Test, str, iArray, name2Sb);

I registered QString、QVector、QMap with sp_get_needed_size、sp_serialize_to、sp_deserialize_to,and used STRUCT_PACK_REFL(Test, str, iArray, name2Sb);
It`s good work with struct_packderialize(),but an error occurred during compile when i use
std::ofstream writer("struct_pack_demo.data"), std::ofstream::out|std::ofstream::binary);
struct_pack::serialize_to(writer, test);

The complier error message: read_bytes_array Cannot find identifier(找不到标识符)
I think I still need to implement some else template functions

@poor-circle
Copy link
Collaborator

poor-circle commented Sep 19, 2024

The error message was "1. If the struct is empty, which is not allowed in struct_pack type system.\n" "2. If the strut is not empty, it means struct_pack can't calculate your struct members' count. You can use macro STRUCT_PACK_REFL(Typename, field1, field2...)."
Yes! I am learning how to integrate third party library types and it is a learning process. Thanks a lot!

Or you can try this:

struct Test
{
QString str;
QVector iArray;
QMap<QString, QString> name2Sb;
};
STRUCT_PACK_REFL(Test, str, iArray, name2Sb);

I registered QString、QVector、QMap with sp_get_needed_size、sp_serialize_to、sp_deserialize_to,and used STRUCT_PACK_REFL(Test, str, iArray, name2Sb); It`s good work with struct_packderialize(),but an error occurred during compile when i use std::ofstream writer("struct_pack_demo.data"), std::ofstream::out|std::ofstream::binary); struct_pack::serialize_to(writer, test);

The complier error message: read_bytes_array Cannot find identifier(找不到标识符) I think I still need to implement some else template functions

Sorry for my late, it's a code bug, fixed by #776

@xiaocai123123
Copy link
Author

The error message was "1. If the struct is empty, which is not allowed in struct_pack type system.\n" "2. If the strut is not empty, it means struct_pack can't calculate your struct members' count. You can use macro STRUCT_PACK_REFL(Typename, field1, field2...)."
Yes! I am learning how to integrate third party library types and it is a learning process. Thanks a lot!

Or you can try this:

struct Test
{
QString str;
QVector iArray;
QMap<QString, QString> name2Sb;
};
STRUCT_PACK_REFL(Test, str, iArray, name2Sb);

I registered QString、QVector、QMap with sp_get_needed_size、sp_serialize_to、sp_deserialize_to,and used STRUCT_PACK_REFL(Test, str, iArray, name2Sb); It`s good work with struct_packderialize(),but an error occurred during compile when i use std::ofstream writer("struct_pack_demo.data"), std::ofstream::out|std::ofstream::binary); struct_pack::serialize_to(writer, test);
The complier error message: read_bytes_array Cannot find identifier(找不到标识符) I think I still need to implement some else template functions

Sorry for my late, it's a code bug, fixed by #776

强!我更新到最新版本了,发现部分宏都改变了,源码文件也有些改动。试了一下,问题迎刃而解了。非常感谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants