private static int streamIdSizeFor(ProtocolVersion version) { switch (version) { case V1: case V2: return 1; case V3: case V4: case V5: return 2; default: throw version.unsupported(); } }
private static int sizeOfCollectionSize(ProtocolVersion version) { switch (version) { case V1: case V2: return 2; case V3: case V4: case V5: return 4; default: throw version.unsupported(); } }
/** * Return the expected frame header length in bytes according to the protocol version in use. * * @param version the protocol version in use * @return the expected frame header length in bytes */ static int lengthFor(ProtocolVersion version) { switch (version) { case V1: case V2: return 8; case V3: case V4: case V5: return 9; default: throw version.unsupported(); } }
private void writeStreamId(int streamId, ByteBuf header, ProtocolVersion protocolVersion) { switch (protocolVersion) { case V1: case V2: header.writeByte(streamId); break; case V3: case V4: case V5: header.writeShort(streamId); break; default: throw protocolVersion.unsupported(); } } }
private static int readStreamid(ByteBuf fullFrame, ProtocolVersion version) { switch (version) { case V1: case V2: return fullFrame.readByte(); case V3: case V4: case V5: return fullFrame.readShort(); default: throw version.unsupported(); } }
private static int sizeOfValue(ByteBuffer value, ProtocolVersion version) { switch (version) { case V1: case V2: int elemSize = value.remaining(); if (elemSize > 65535) throw new IllegalArgumentException( String.format( "Native protocol version %d supports only elements with size up to 65535 bytes - but element size is %d bytes", version.toInt(), elemSize)); return 2 + elemSize; case V3: case V4: case V5: return value == null ? 4 : 4 + value.remaining(); default: throw version.unsupported(); } }
/** * Utility method that reads a size value. Mainly intended for collection codecs when * deserializing CQL collections. * * @param input The ByteBuffer to read from. * @param version The protocol version to use. * @return The size value. */ public static int readSize(ByteBuffer input, ProtocolVersion version) { switch (version) { case V1: case V2: return getUnsignedShort(input); case V3: case V4: case V5: return input.getInt(); default: throw version.unsupported(); } }
/** * Utility method that writes a value. Mainly intended for collection codecs when deserializing * CQL collections. * * @param output The ByteBuffer to write to. * @param value The value to write. * @param version The protocol version to use. */ public static void writeValue(ByteBuffer output, ByteBuffer value, ProtocolVersion version) { switch (version) { case V1: case V2: assert value != null; output.putShort((short) value.remaining()); output.put(value.duplicate()); break; case V3: case V4: case V5: if (value == null) { output.putInt(-1); } else { output.putInt(value.remaining()); output.put(value.duplicate()); } break; default: throw version.unsupported(); } }
/** * Utility method that writes a size value. Mainly intended for collection codecs when serializing * CQL collections. * * @param output The ByteBuffer to write to. * @param size The collection size. * @param version The protocol version to use. */ public static void writeSize(ByteBuffer output, int size, ProtocolVersion version) { switch (version) { case V1: case V2: if (size > 65535) throw new IllegalArgumentException( String.format( "Native protocol version %d supports up to 65535 elements in any collection - but collection contains %d elements", version.toInt(), size)); output.putShort((short) size); break; case V3: case V4: case V5: output.putInt(size); break; default: throw version.unsupported(); } }
void encode(ByteBuf dest, ProtocolVersion version) { switch (version) { case V2: CBUtil.writeConsistencyLevel(consistency, dest); break; case V3: case V4: case V5: CBUtil.writeConsistencyLevel(consistency, dest); QueryFlag.serialize(flags, dest, version); if (flags.contains(QueryFlag.SERIAL_CONSISTENCY)) CBUtil.writeConsistencyLevel(serialConsistency, dest); if (flags.contains(QueryFlag.DEFAULT_TIMESTAMP)) dest.writeLong(defaultTimestamp); break; default: throw version.unsupported(); } }
int encodedSize(ProtocolVersion version) { switch (version) { case V2: return CBUtil.sizeOfConsistencyLevel(consistency); case V3: case V4: case V5: int size = 0; size += CBUtil.sizeOfConsistencyLevel(consistency); size += QueryFlag.serializedSize(version); if (flags.contains(QueryFlag.SERIAL_CONSISTENCY)) size += CBUtil.sizeOfConsistencyLevel(serialConsistency); if (flags.contains(QueryFlag.DEFAULT_TIMESTAMP)) size += 8; return size; default: throw version.unsupported(); } }
break; default: throw version.unsupported();
return size; default: throw version.unsupported();
static SchemaChange deserializeEvent(ByteBuf bb, ProtocolVersion version) { Change change; SchemaElement targetType; String targetKeyspace, targetName; List<String> targetSignature; switch (version) { case V1: case V2: change = CBUtil.readEnumValue(Change.class, bb); targetKeyspace = CBUtil.readString(bb); targetName = CBUtil.readString(bb); targetType = targetName.isEmpty() ? KEYSPACE : TABLE; targetSignature = Collections.emptyList(); return new SchemaChange(change, targetType, targetKeyspace, targetName, targetSignature); case V3: case V4: case V5: change = CBUtil.readEnumValue(Change.class, bb); targetType = CBUtil.readEnumValue(SchemaElement.class, bb); targetKeyspace = CBUtil.readString(bb); targetName = (targetType == KEYSPACE) ? "" : CBUtil.readString(bb); targetSignature = (targetType == FUNCTION || targetType == AGGREGATE) ? CBUtil.readStringList(bb) : Collections.<String>emptyList(); return new SchemaChange(change, targetType, targetKeyspace, targetName, targetSignature); default: throw version.unsupported(); } }
private static int sizeOfCollectionSize(ProtocolVersion version) { switch (version) { case V1: case V2: return 2; case V3: case V4: return 4; default: throw version.unsupported(); } }
throw protocolVersion.unsupported();
private static int readStreamid(ByteBuf fullFrame, ProtocolVersion version) { switch (version) { case V1: case V2: return fullFrame.readByte(); case V3: case V4: return fullFrame.readShort(); default: throw version.unsupported(); } }
private static int readStreamid(ByteBuf fullFrame, ProtocolVersion version) { switch (version) { case V1: case V2: return fullFrame.readByte(); case V3: case V4: return fullFrame.readShort(); default: throw version.unsupported(); } }
throw protocolVersion.unsupported();
throw protocolVersion.unsupported();