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

Fix: add empty struct marshaling #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gallexis
Copy link

I needed to encode a map[string]struct{} but ran into this error :

testing/cbor_gen.go:172:25: t.EmptyStruct.MarshalCBOR undefined (type struct {} has no field or method MarshalCBOR) which is logical since we can't attach a function to an empty struct :

EmptyStruct struct{}
...
if err := EmptyStruct.UnmarshalCBOR(br); err != nil {.      // it fails here
     return xerrors.Errorf("unmarshaling t.EmptyStruct: %w", err)
}

So I made this fix to handle this case and added some tests

@Stebalien
Copy link
Collaborator

Stebalien commented Aug 15, 2021

In general, I'd expect an empty struct to marshel to an empty object (in our case, that would be an empty list). So I'd rather not handle struct{} generically at the moment.

But in this case, map[string]struct{} really just represents a set. That should probably marshal to an array of keys.

SGTY @whyrusleeping?

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

Successfully merging this pull request may close these issues.

2 participants