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

cel: Some ideas for ergonomics improvements #145

Merged
merged 2 commits into from
Dec 3, 2021
Merged

Conversation

josephlr
Copy link
Member

@josephlr josephlr commented Dec 3, 2021

Some ideas about how we might make CEL stuff easier to work with.

@alexmwu @jkl73 what do you think? Worth doing?

This makes the Record structure easier to use by just creating the TLV
fields in the EncodeCELR function.

Signed-off-by: Joe Richey <joerichey@google.com>
There is no longer a reason for these fields to be public (as they are
only used in DecodeToCELR.

Signed-off-by: Joe Richey <joerichey@google.com>
Copy link
Contributor

@alexmwu alexmwu left a comment

Choose a reason for hiding this comment

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

Makes a lot of sense to me. Thanks!

@@ -35,7 +35,7 @@ type TLV struct {
}

// MarshalBinary marshals a TLV to a byte slice.
func (tlv *TLV) MarshalBinary() (data []byte, err error) {
func (tlv TLV) MarshalBinary() (data []byte, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

So it seems like:

So I think it's fine to use a value receiver here. The type is small, marshaling doesn't change the value, and if I change it to a pointer receiver the code doesn't compile.

This is because you then can't do something like:

createRecNumField(r.RecNum).MarshalBinary()

as temporary values do not have an address.

Copy link
Contributor

@jkl73 jkl73 left a comment

Choose a reason for hiding this comment

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

LGTM, this way should be easier to use Record.

@josephlr josephlr merged commit 60b9344 into google:master Dec 3, 2021
@josephlr josephlr deleted the ergo branch December 3, 2021 21:46
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.

3 participants