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

Zero padded strings #53

Closed
abourget opened this issue Mar 14, 2018 · 2 comments
Closed

Zero padded strings #53

abourget opened this issue Mar 14, 2018 · 2 comments

Comments

@abourget
Copy link

abourget commented Mar 14, 2018

Hi,

I was wondering if it'd be hard to build a zeroed flag or something, that would make this work:

	Precision byte   `struc:"uint8"`
	Name      string `struc:"[7]uint8"`
}

the Name is 7 bytes, but it's zero padded at the end, I'd like to have the string without the zeroes, and pad back with zeroes when writing.. I tried pad.. but it seems to simply ignore the field, right ?

So the data: 0443555200000000 would deserialize to Currency{4, "CUR"} instead of Currency{4, "CUR\x00\x00\x00\x00"}.

@lunixbochs
Copy link
Owner

lunixbochs commented Mar 14, 2018

#42 #31

Does it pack correctly? The easiest workaround for now is to trim nulls yourself using strings.TrimRight.

Another option is to write a custom type.

@abourget
Copy link
Author

ok, thanks

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