maedhroz commented on code in PR #1962:
URL: https://github.com/apache/cassandra/pull/1962#discussion_r1040156650
##########
src/java/org/apache/cassandra/utils/ByteBufferUtil.java:
##########
@@ -533,6 +551,35 @@ else if (obj instanceof byte[])
return ByteBuffer.wrap((byte[]) obj);
else if (obj instanceof ByteBuffer)
return (ByteBuffer) obj;
+ else if (obj instanceof List)
+ {
+ List<?> list = (List<?>) obj;
+ // convert subtypes to BB
+ List<ByteBuffer> bbs =
list.stream().map(ByteBufferUtil::objectToBytes).collect(Collectors.toList());
+ // decompose/serializer doesn't use the isMultiCell, so safe to do
this
+ return ListType.getInstance(BytesType.instance,
false).decompose(bbs);
+ }
+ else if (obj instanceof Map)
+ {
+ Map<?, ?> map = (Map<?, ?>) obj;
+ // convert subtypes to BB
+ Map<ByteBuffer, ByteBuffer> bbs = new LinkedHashMap<>();
+ for (Map.Entry<?, ?> e : map.entrySet())
+ bbs.put(objectToBytes(e.getKey()),
objectToBytes(e.getValue()));
Review Comment:
In any case, something like this is what you have in mind?
```
for (Map.Entry<?, ?> e : map.entrySet())
{
Object key = e.getKey();
ByteBuffer previousValue = bbs.put(objectToBytes(key),
objectToBytes(e.getValue()));
if (previousValue != null)
throw new IllegalStateException("Key " + key + " already maps to
value " + previousValue);
}
```
--
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]