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

Use pointers for optional datatypes. Use arrays for fixed size sets #204

Merged
merged 2 commits into from
Aug 3, 2021

Conversation

dave-tucker
Copy link
Collaborator

This PR changes:

  1. Modelgen to generate pointers to an atomic type when it is a set with a min value of 0 and a max value of 1
  2. Modelgen to generate arrays for fixed size sets (e.g max != unlimited)
  3. Bindings to cope with these new types

Fixes: #191

@dave-tucker
Copy link
Collaborator Author

Split from #151

@coveralls
Copy link

coveralls commented Jul 19, 2021

Pull Request Test Coverage Report for Build 1090436413

  • 59 of 105 (56.19%) changed or added relevant lines in 3 files are covered.
  • 6 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.7%) to 75.654%

Changes Missing Coverage Covered Lines Changed/Added Lines %
ovsdb/set.go 12 13 92.31%
modelgen/table.go 7 17 41.18%
ovsdb/bindings.go 40 75 53.33%
Files with Coverage Reduction New Missed Lines %
ovsdb/bindings.go 1 74.93%
ovsdb/set.go 1 86.76%
modelgen/table.go 4 88.29%
Totals Coverage Status
Change from base Build 1076496319: -0.7%
Covered Lines: 3325
Relevant Lines: 4395

💛 - Coveralls

@alexanderConstantinescu
Copy link
Contributor

  1. Modelgen to generate pointers to an atomic type when it is a set with a min value of 0 and a max value of 1

How come a pointer to an atomic type and not the atomic type itself? That enforces "strange looking code" on the client, such as:

nyName := "acl"
acl := nbdb.ACL{
     Name: &myName
}

I would just like to understand why that should be the case here.

@dave-tucker
Copy link
Collaborator Author

@alexanderConstantinescu because the field needs to be nillable as its optional. Otherwise we end up with serialisation problems.

Copy link
Collaborator

@jcaamano jcaamano left a comment

Choose a reason for hiding this comment

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

I have not spotted anything weird code wise, just formatting nits.

mapper/mapper_test.go Outdated Show resolved Hide resolved
mapper/mapper_test.go Outdated Show resolved Hide resolved
ovsdb/bindings.go Show resolved Hide resolved
ovsdb/bindings.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@amorenoz amorenoz left a comment

Choose a reason for hiding this comment

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

For users not using modelgen I think we should add a brief comment on some of the documentation (maybe api/doc.go or main Readme.md)

ovsdb/bindings.go Outdated Show resolved Hide resolved
ovsdb/bindings.go Outdated Show resolved Hide resolved
Sets with min 1 and max 1 are a type
Sets with min 0 and max 1 are a pointer to a type
Sets with a max > 1 (non-default) are an array
Otherwise a set is represented by a slice

Signed-off-by: Dave Tucker <[email protected]>
This handles mapping from OvsToNative

- min 0, max > 1 && !unlimted to an array
- min 0, max 1 to a pointer
- min 0, max unlimited to a slice

And in NativeToOvs, we convert all cases back in to an
OvsSet

Signed-off-by: Dave Tucker <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Encode sets with max=1 as pointers
5 participants