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

[feat][struct_pack][struct_json] support struct bit-field #595

Open
queshishuai opened this issue Feb 7, 2024 · 16 comments
Open

[feat][struct_pack][struct_json] support struct bit-field #595

queshishuai opened this issue Feb 7, 2024 · 16 comments
Labels
enhancement New feature or request

Comments

@queshishuai
Copy link

example:

struct person {
  std::string name;
  int age;
  int weight:16;/*bit-field*/
  int height:16;
};
@qicosmos
Copy link
Collaborator

qicosmos commented Feb 7, 2024

目前还没有支持,是可以支持的,等后面支持好了再更新这个issue。

@poor-circle
Copy link
Collaborator

需要修改反射机制,目前struct_json的反射机制需要通过宏注册结构体的成员指针,但是位域并没有成员指针……

@poor-circle
Copy link
Collaborator

需要修改反射机制,目前struct_json的反射机制需要通过宏注册结构体的成员指针,但是位域并没有成员指针……

同样,位域字段也不能返回引用。可能需要使用生成getter/setter函数的反射手段才能支持位域。

@poor-circle poor-circle added the enhancement New feature or request label Feb 7, 2024
@poor-circle poor-circle changed the title 【struct_json】能不能支持结构体***位域***字段的解析? [feat][struct_pack][struct_json] support struct bit-field Feb 7, 2024
@qicosmos
Copy link
Collaborator

qicosmos commented Feb 7, 2024

也许可以增加一个位域类型来实现这个功能,比如

struct person {
  std::string name;
  int age;
  bit_filed<int, 16> weight;
  bit_field<int, 16> height;
};

你觉得这样如何?@queshishuai

@poor-circle
Copy link
Collaborator

也许可以增加一个位域类型来实现这个功能,比如

struct person {
  std::string name;
  int age;
  bit_filed<int, 16> weight;
  bit_field<int, 16> height;
};

你觉得这样如何?@queshishuai

这个没法压缩空间吧

@qicosmos
Copy link
Collaborator

qicosmos commented Feb 7, 2024

json 化应该不在乎这个空间吧,在乎的是最终的文本内容吧。@queshishuai

@poor-circle
Copy link
Collaborator

poor-circle commented Feb 7, 2024

json 化应该不在乎这个空间吧,在乎的是最终的文本内容吧。@queshishuai

那为何要使用位域呢,直接用int不就好了

@qicosmos
Copy link
Collaborator

qicosmos commented Feb 7, 2024

也许是已有的结构呢?可以把这个场景再说说。@queshishuai

@poor-circle
Copy link
Collaborator

poor-circle commented Feb 7, 2024

那不都是要改结构体的定义,如果不支持位域的话。
反正目前是不支持位域的。

@qicosmos
Copy link
Collaborator

qicosmos commented Feb 7, 2024

还有个办法是增加一个宏来指定哪些字段是位域,办法总是有的。

@poor-circle
Copy link
Collaborator

核心问题是,位域没有成员指针也不能转换为引用。必须使用getter/setter

@qicosmos
Copy link
Collaborator

qicosmos commented Feb 7, 2024

针对位域的结构体要特殊处理,确实很麻烦。

@queshishuai
Copy link
Author

也许是已有的结构呢?可以把这个场景再说说。@queshishuai

对的,是已有的结构体,不希望改变包含位域的结构体,结构体很大,手动改不现实。需求的场景就是方便将现有结构体(不能改变结构体)序列化为 json。

@queshishuai
Copy link
Author

也许可以增加一个位域类型来实现这个功能,比如


struct person {

  std::string name;

  int age;

  bit_filed<int, 16> weight;

  bit_field<int, 16> height;

};

你觉得这样如何?@queshishuai

不希望手动改变结构体,这样工作量太大了

@movqword
Copy link

Hey there!

Support of bit fields is planned for now or not in queue?

Interesting becouse i have up once similar issue yet.

@poor-circle
Copy link
Collaborator

Hey there!

Support of bit fields is planned for now or not in queue?

Interesting becouse i have up once similar issue yet.

It's hard to support bit field, we dont have plan now. Maybe later I will consider support it by marco.

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

No branches or pull requests

4 participants