-
Notifications
You must be signed in to change notification settings - Fork 626
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
Added uint32 flags for QUERY and BATCH operations for native protocol v5 #1783
Conversation
frame.go
Outdated
flagValuesV5 uint32 = 0x01 | ||
flagSkipMetaDataV5 = 0x02 | ||
flagPageSizeV5 = 0x04 | ||
flagWithPagingStateV5 = 0x08 | ||
flagWithSerialConsistencyV5 = 0x10 | ||
flagDefaultTimestampV5 = 0x20 | ||
flagWithNameValuesV5 = 0x40 | ||
flagWithKeyspaceV5 = 0x80 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about changing only the type of existing flags?
It allows us to avoid such code duplications. We may implement the new way of constructing the flag field as uint32. Also, if the proto version is less than 5, we can just cast it to byte inside the corresponding methods like framer.writeQueryParams
.
894ab54
to
6bcffe1
Compare
frame.go
Outdated
switch { | ||
case f.proto < protoVersion5: | ||
if len(opts.values) > 0 { | ||
flagsByte |= byte(flagValues) | ||
} | ||
if opts.skipMeta { | ||
flagsByte |= byte(flagSkipMetaData) | ||
} | ||
if opts.pageSize > 0 { | ||
flagsByte |= byte(flagPageSize) | ||
} | ||
if len(opts.pagingState) > 0 { | ||
flagsByte |= byte(flagPageSize) | ||
} | ||
if opts.serialConsistency > 0 { | ||
flagsByte |= byte(flagWithSerialConsistency) | ||
} | ||
if f.proto > protoVersion2 { | ||
if opts.defaultTimestamp { | ||
flagsByte |= byte(flagDefaultTimestamp) | ||
} | ||
if len(opts.values) > 0 && opts.values[0].name != "" { | ||
flagsByte |= byte(flagWithNameValues) | ||
names = true | ||
} | ||
} | ||
f.writeByte(flagsByte) | ||
|
||
case f.proto >= protoVersion5: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we also may avoid these code duplications by implementing only the new way of constructing the flag. As I see, we may construct the flag as uint32, and in the end, we may check the proto version. If the version is less than 5 we may cast it to byte and write it as it is.
What do you think about this approach? Also, if we follow this approach, the flagsByte
var may be omitted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense, fixed
6bcffe1
to
3b1c6db
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
The pull request #1783 for the Cassandra gocql driver introduces uint32 flags for QUERY and BATCH operations to support native protocol v5. It refactors the code to handle protocol-specific flag settings more efficiently by retaining byte-based flags for protocol versions less than 5 and introducing integer-based flags for protocol version 5 and higher. This refactoring improves code readability and maintainability, preparing the driver for future protocol changes.