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

Remove blank arrays and false boolean variables from serialised output #177

Open
pavel-odintsov opened this issue May 18, 2017 · 4 comments

Comments

@pavel-odintsov
Copy link

Hello!

First of all, I would like to say thank you for your brilliant library!

Right now I'm working on space optimisation of our data.

We have a pretty big number of false variables and blank arrays in output. I'm looking for ways to suppress them from generated message pack.

For example, we have the following structure:

type MyData struct {
  Name string
  Options []string
  SomeBoolValue bool
  AnotherBoolVariable bool
} 

And then we have the following structure:

obj.Name = "xyz"
obj.Options = []string{}
obj.SomeBoolVariable = false
obj.AnotherBoolVariable = true

And I would like to have in generated message pack only:

Name: "xyz"
obj.AnotherBoolVariable = true

And skip blank arrays / false variables.

How could I achieve this goal?

Thank you!

@philhofer
Copy link
Member

This issue is trickier than it looks at first (see #164 - a 12,000 line change).

Another option might be to add a feature to the msgp library that lets you strip zeroed fields from a serialized message. I'll try to sketch that out if I can find some free time.

@pavel-odintsov
Copy link
Author

pavel-odintsov commented Jun 13, 2017

@philhofer Oh, yes, I see. It's pretty sophisticated;( Good luck with these changes! Hope to see them merged to master.

I think an option to use additional tool to strip blank fields works for us. We do not care so much about serialise performance but de-serialisation performance (and space) is very important for us. So, we are happy to have additional method which cleans messages from redundant data.

@pavel-odintsov
Copy link
Author

Do you have any progress in this direction?

@bradleypeabody
Copy link
Contributor

bradleypeabody commented Oct 27, 2023

Since this issue was originally created, omitempty and omitzero struct tags were introduced, which I believe fully addresses this concern.

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

3 participants