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

feature: Encode nil map/slice with cbor empty map/list tag #351

Closed
dedefer opened this issue Jun 6, 2022 · 5 comments
Closed

feature: Encode nil map/slice with cbor empty map/list tag #351

dedefer opened this issue Jun 6, 2022 · 5 comments

Comments

@dedefer
Copy link
Contributor

dedefer commented Jun 6, 2022

Is your feature request related to a problem? Please describe.
I use cbor as a serialization format for rpc between services written in different languages.
So when i try to send some structure like

type Example struct {
  Data map[string]string `cbor:"data"`
}

I always need to initialize Data explicitly Example{Data: map[string]string{}} because Example{} is serialized to {"data":null}.

So I need to describe this dto in python like

class Example:
  data: Optional[dict[str, str]]

despite the fact that this field is required.

Describe the solution you'd like
I think it would be nice to have encoding option to enforce encoder use empty list/map cbor type for nil slice/map.

@dedefer dedefer changed the title feature: feature: Encode nil map/slice with cbor empty map/list tag Jun 6, 2022
@fxamacker
Copy link
Owner

@dedefer Thanks for opening issue and PR. It makes sense to me to add this option.

I'll take a look at the PR. It may be a while because I need to update fuzz test, etc. first.

@dedefer
Copy link
Contributor Author

dedefer commented Jul 19, 2022

@fxamacker Could you please give any updates on an issue?

@fxamacker
Copy link
Owner

Hello @dedefer,

I like your PR and want to include it in the next release. I've been swamped with work and hope to get to it after an upcoming deadline. I need to update the fuzzer for this PR and etc. so there's some extra work behind the scenes.

You can specify unmerged PR's commit inside go.mod as a workaround before the PR is merged.

Thanks again for the contribution and your patience!

@dedefer
Copy link
Contributor Author

dedefer commented Jul 20, 2022

It's ok! I know that feel, bro. Thanks for not forgetting about this issue! I really appreciate your work!

@fxamacker
Copy link
Owner

Closed by PR #352 and #377.

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