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 argument names #165

Merged
merged 1 commit into from
Aug 2, 2020
Merged

Conversation

yanivagman
Copy link
Collaborator

No description provided.

@yanivagman yanivagman requested a review from itaysk July 27, 2020 08:25
@yanivagman yanivagman force-pushed the add_arg_names branch 3 times, most recently from 30abcca to 0183639 Compare July 28, 2020 11:26
Copy link
Collaborator

@itaysk itaysk left a comment

Choose a reason for hiding this comment

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

This is great! I've added some comments

@@ -63,10 +63,11 @@ type Event struct {
EventName string `json:"eventName"`
ArgsNum int `json:"argsNum"`
ReturnValue int `json:"returnValue"`
ArgsNames []string `json:"argsNames"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should not just add the argnames array to the Event type here, but instead combine it with the args array, probably as a map[string]interface{}. The reason we created this Event type is that we could decouple the internal data structures (context, []args) that are required to process events from the external data type (Event) that is used to communicate events externally (gob) and for printing (printer). This is a good opportunity to take use the Event struct to adapt the internal representation (2 arrays) which were convenient for processing but not for consuming, and adjust it to be convenient for consuming (one map).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm handling this in some different way in my next PR which is based on this one. We can change this internal representations after these will be merged

for _, value := range event.Args {
fmt.Fprintf(p.out, "%v ", value)
for i, value := range event.Args {
fmt.Fprintf(p.out, "%s: %v ", event.ArgsNames[i], value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

you have only handled the table printer and not the others, but I think the other will be naturally fixed if address my other comment fro above

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nothing to do in the others - the json printer will just marshal it as well, same for the gob which will encode as well

argsNames[i] = argName
} else {
t.handleError(err)
continue
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we want to fail here or to just skip the tag parsing? (I'm not sure myself)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is definetely an error. If an argtag doesn't have an argName, this means something went wrong in the event decoding, as this shouldn't happen

Comment on lines +485 to +489
argsTags[i] = argTag
args[i] = argVal
argName, ok := argNames[argTag]
if ok {
argsNames[i] = argName
Copy link
Collaborator

Choose a reason for hiding this comment

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

The event processing code doesn't care about the arg names, it just needs their tags. the names are for printing only, so I think this code doesn't belongs here rather in the newEvent code

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right. I'm handling exactly this in my next PR

@yanivagman yanivagman requested a review from itaysk August 2, 2020 07:03
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