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

Marshal int like cql types into uint like go types #307

Open
illia-li opened this issue Oct 13, 2024 · 0 comments
Open

Marshal int like cql types into uint like go types #307

illia-li opened this issue Oct 13, 2024 · 0 comments

Comments

@illia-li
Copy link

All int like cql types have negative range and positive range, but uint like go types have only positive range.
For example, if cast -1 tinyint []byte("\xff") into uint like go types we got 255.

In the old marhsal/unmarshal functions (before the starts redesign), this problem was solved in different ways.
So, my suggest to leave only one way, because if have different ways its not clear. Moreover, this can lead to unexpected consequences, not at the time of testing, but at the moment when the value of uintfalls into the negative range ofcql type`.

Way 1 - deny any processing with negative range of int like cql types. This way means:

  1. On marshal:
    1.1. For uint like go types with less bitsize then the cql type - free encoding into positive range of the cql type
    1.2. For uint like go types with same or bigger bitsize then the cql type - encoding only if value of the uint go type in the positive range of the cql type.
  2. On unmarshal:
    2.1. For all uint like go types - encoding only if the data from DB in the positive range and in the range of the uint go type.

Way 2 - allow processing with negative range of int like cql types. This way means:

  1. On marshal:
    1.1. For uint like go types with less bitsize then the cql type - free encoding into positive range of the cql type
    1.1. For uint like go types with same bitsize then the cql type - free encoding into all range of the cql type
    1.2. For uint like go types with bigger bitsize then the cql type - encoding only if value of the uint go type in the range of the cql type.
  2. On unmarshal:
    2.1. For all uint like go types - encoding only if the data from DB in the range of the uint go type.

In relation to DB users can be sorted into 2 groups:

  1. Users who use DB only with GO.
  2. Users who use DB not only with GO.

For users from group #1 all two ways will be acceptable, but they will not be able to processing with full range of the int like cql types from the box.
At the same time, they will always have the opportunity to make their own marshal/unmarshall functions.

For users from group #2 only way 1 will be acceptable, because way 2 can lead to problems due to the different DB and GO representations of the same values.
And it may turn out that they will find out only after a while.

So, my suggest to leave only one way - deny the processing with a negative range of the int like cql types for all uint like go types.

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

No branches or pull requests

1 participant