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

In industrial scenarios, it is necessary to increase the processing of special data structures such as union and bit fields. #4

Open
wancy-x opened this issue Jan 31, 2023 · 3 comments

Comments

@wancy-x
Copy link
Contributor

wancy-x commented Jan 31, 2023

At present, there is a very common data structure as follows:

typedef struct
{
	union
	{
		unsigned short word;
		struct
		{
			unsigned code1		:3;
			unsigned code2		:5;
			unsigned code3		:2;
			unsigned code4		:6;
		}block;
	}order;
	...
}

In order to be compatible with a large number of early module codes, this is a necessary data structure, and this data structure will be transmitted with high-level programming languages.

After careful study, the conclusion is that under the current use scenario, the union cannot be serialized in general, but can only be parsed in a targeted way. In consideration of the universality of Jstruct, it is recommended to negotiate the special data types that may be encountered at present and in the future.

@wancy-x
Copy link
Contributor Author

wancy-x commented Jan 31, 2023

When processing this type of data, it is also necessary to consider the problem of big-endian and little-endian, which may cause dislocation in the transmission process of different 'arch'.

@hanhui03
Copy link
Owner

I don't recommend doing this, jstruct just provides serialization and deserialization for json, I want to keep it simpl, not to understand the meaning inside the protocol, this work should be do by protocol parsing.

@wancy-x
Copy link
Contributor Author

wancy-x commented Mar 14, 2023

In fact, the union should be an extension of the base data type, but the data defined by the union cannot be parsed according to the original logic, so the protocol is proposed. Do you think the extension of union should not be parsed or the description of protocol is inappropriate? If it is the latter, I will put the protocol in other files and extend the jstruct in the form of modules.

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

No branches or pull requests

2 participants