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

Add a TLV encoder/decoder. #35

Merged
merged 2 commits into from
Jul 10, 2024
Merged

Add a TLV encoder/decoder. #35

merged 2 commits into from
Jul 10, 2024

Conversation

zhenlu
Copy link
Contributor

@zhenlu zhenlu commented Jul 10, 2024

No description provided.

@zhenlu zhenlu requested a review from jklein24 July 10, 2024 19:08
@zhenlu zhenlu requested a review from shreyav July 10, 2024 19:11
}

type TLVUtilsTests struct {
StringField string `tlv:"0"`
Copy link
Collaborator

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")
Copy link
Collaborator

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?

Copy link
Contributor Author

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
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@zhenlu zhenlu merged commit 31af802 into main Jul 10, 2024
2 checks passed
@zhenlu zhenlu deleted the tlv-util branch July 10, 2024 23:31
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