-
Notifications
You must be signed in to change notification settings - Fork 44
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
Support time.Time #100
Support time.Time #100
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good. Only minor changes to follow the same standard for the generated code.
sszgen/generator/unmarshal.go
Outdated
@@ -104,6 +104,9 @@ func (v *Value) unmarshal(dst string) string { | |||
case TypeBool: | |||
return fmt.Sprintf("::.%s = ssz.UnmarshalBool(%s)", v.name, dst) | |||
|
|||
case TypeTime: | |||
return fmt.Sprintf("::.%s = time.Unix(int64(ssz.UnmarshallUint64(%s)), 0).UTC()", v.name, dst) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of doing a complex generated code, add an entry at the root of the project with a helper function:
function UnmarshalTime(buf []byte) time.Time {
time.Unix(int64(UnmarshallUint64(buf)), 0).UTC()
}
and use that instead on the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, you do not need to do this after this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be addressed, but please take a look to confirm.
(Note that this removes the requirement for the time import in the earlier comment).
This allows encoding and decoding of the
time.Time
type in structs, touint64
values.