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 args to conversion to be returnable as json #1512

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

JL-Brothers
Copy link
Collaborator

Closes Issue #698

Copy link

sonarcloud bot commented Sep 4, 2024

Copy link

codecov bot commented Sep 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.42%. Comparing base (6c85e08) to head (0399b5d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1512      +/-   ##
==========================================
+ Coverage   76.40%   76.42%   +0.02%     
==========================================
  Files         618      618              
  Lines       46858    46822      -36     
  Branches      845      845              
==========================================
- Hits        35803    35786      -17     
+ Misses      10959    10940      -19     
  Partials       96       96              
Flag Coverage Δ
frontend 56.13% <ø> (ø)
python 83.95% <ø> (+0.09%) ⬆️
ruby-api 47.59% <ø> (ø)
ruby-backend 82.53% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@ryanmelt ryanmelt left a comment

Choose a reason for hiding this comment

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

Need look through all the existing conversion classes and if they take arguments make sure the @params variable gets filled with those arguments.

If possible remove subclass as_json methods where they would do the same thing as the base class if @params is filled out.

@@ -67,6 +70,7 @@ def as_json(*_a)
result['converted_type'] = @converted_type if @converted_type
result['converted_bit_size'] = @converted_bit_size if @converted_bit_size
result['converted_array_size'] = @converted_array_size if @converted_array_size
result['args'] = JSON.generate(@args) if @args
Copy link
Member

Choose a reason for hiding this comment

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

as_json shouldn't call JSON.generate. The goal is return objects that are ready to be converted to JSON, but not return an actual JSON string yet. Change to "= @params.as_json(*a)" and remove underscore from the existing _a

@@ -61,4 +63,6 @@ def as_json(self):
result["converted_bit_size"] = self.converted_bit_size
if self.converted_array_size is not None:
result["converted_array_size"] = self.converted_array_size
if self.args is not None:
result["args"] = json.dumps(self.args)
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as in Ruby.

@@ -17,6 +17,7 @@ def __init__(self):
# a string, integer, float, or array of values.
# @param packet [Packet] The packet object where the conversion is defined
# @param buffer [String] The raw packet buffer
# @param args [Array] The arguments to return
Copy link
Member

Choose a reason for hiding this comment

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

args is not an parameter to call. remove.

@@ -30,12 +30,15 @@ class Conversion
attr_reader :converted_bit_size
# @return [Integer] The size in bits of the converted array value
attr_reader :converted_array_size
# @return [] The Array of arguments passed in
attr_reader :args
Copy link
Member

Choose a reason for hiding this comment

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

Probably rename to params. If you look at the as_json method in a lot of our existing conversion classes they already are reporting their arguments as 'params'

@@ -12,6 +12,8 @@ def initialize
# Size of the converted type in bits
# Use 0 for :STRING or :BLOCK where the size can be variable
@converted_bit_size = 0
# return the arguments used
@args = []
Copy link
Member

Choose a reason for hiding this comment

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

This should default to nil, like in the base class.

@jmthomas jmthomas marked this pull request as ready for review October 17, 2024 23:45
Copy link

sonarcloud bot commented Oct 17, 2024

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