joao-r-reis commented on code in PR #1952:
URL:
https://github.com/apache/cassandra-java-driver/pull/1952#discussion_r1923698707
##########
core/src/main/java/com/datastax/oss/driver/internal/core/type/codec/VectorCodec.java:
##########
@@ -113,40 +139,63 @@ public CqlVector<SubtypeT> decode(
if (bytes == null || bytes.remaining() == 0) {
return null;
}
+ boolean isVarSized = !subtypeCodec.serializedSize().isPresent();
+ if (isVarSized) {
+ ByteBuffer input = bytes.duplicate();
+ List<SubtypeT> rv = new ArrayList<SubtypeT>(cqlType.getDimensions());
+ for (int i = 0; i < cqlType.getDimensions(); ++i) {
+ int size = VIntCoding.getUnsignedVInt32(input, input.position());
+ input.position(input.position() +
VIntCoding.computeUnsignedVIntSize(size));
Review Comment:
Can't we put the `if (isVarSized)` here instead? Otherwise there's still a
bit of duplication in my mind.
Pseudocode:
```
for (int i = 0; i < cqlType.getDimensions(); ++i) {
if (isVarSized) {
// decode elementSize and move input position forward
}
if (elementSize > 0) { // this will always be true if is not varSized
so it works for both cases
// decode element and add it to collection
} else {
// add null to collection (maybe call codec with null? Idk what's
correct in java driver, looks like in the current version of this PR the codec
is being called with "null"
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]