-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add a TLV encoder/decoder. #35
Conversation
} | ||
|
||
type TLVUtilsTests struct { | ||
StringField string `tlv:"0"` |
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.
This is pretty cool :-D
var result []byte | ||
for i := 0; i < val.NumField(); i++ { | ||
field := val.Field(i) | ||
tag := typ.Field(i).Tag.Get("tlv") |
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.
This is cool! Is this how the json serializing works in Go too?
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.
Yeah I think json utilize this reflect as well
field := val.Field(i) | ||
tag := typ.Field(i).Tag.Get("tlv") | ||
if tag == "" { | ||
continue |
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.
Will this just silently drop those fields? Do you think it should it be an error?
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.
The consideration is to make it flexible, so not all fields needs to be serialized to TLV.
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.
One example is that if we ever want to use 2 bytes as type, we can specify it in the struct without TLV field.
No description provided.