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

gen: custom marshaler #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

isomorphiccat
Copy link

Custom marshaler support on codegen using reflect's interface implementation check. Ref: bluesky-social/indigo#153

The codegen now checks custom marshaler/unmarshaler implementation for the fields of struct maps and struct tuples. When present, the codegen uses the existing methods instead of generating a new one.

@@ -1305,6 +1376,10 @@ func emptyValForField(f Field) (string, error) {
}
}

type Marshaler interface {
MarshalCBOR() ([]byte, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to introduce a new interface instead of using the current MarshalCBOR(w io.Writer) error one?

@@ -1442,6 +1524,10 @@ func emitCborMarshalStructMap(w io.Writer, gti *GenTypeInfo) error {
return nil
}

type Unmarshaler interface {
UnmarshalCBOR([]byte) error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto above?

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