use of com.hazelcast.client.impl.protocol.codec.custom.HazelcastJsonValueCodec in project hazelcast by hazelcast.
the class SqlPageCodec method encode.
@SuppressWarnings({ "unchecked", "checkstyle:CyclomaticComplexity", "checkstyle:MethodLength" })
public static void encode(ClientMessage clientMessage, SqlPage sqlPage) {
clientMessage.add(BEGIN_FRAME.copy());
// Write the "last" flag.
byte[] content = new byte[] { (byte) (sqlPage.isLast() ? 1 : 0) };
clientMessage.add(new ClientMessage.Frame(content));
// Write column types.
List<SqlColumnType> columnTypes = sqlPage.getColumnTypes();
List<Integer> columnTypeIds = new ArrayList<>(columnTypes.size());
for (SqlColumnType columnType : columnTypes) {
columnTypeIds.add(columnType.getId());
}
ListIntegerCodec.encode(clientMessage, columnTypeIds);
// Write columns.
for (int i = 0; i < sqlPage.getColumnCount(); i++) {
SqlColumnType columnType = columnTypes.get(i);
Iterable<?> column = sqlPage.getColumnValuesForServer(i);
switch(columnType) {
case VARCHAR:
ListMultiFrameCodec.encodeContainsNullable(clientMessage, (Iterable<String>) column, StringCodec::encode);
break;
case BOOLEAN:
ListCNBooleanCodec.encode(clientMessage, (Iterable<Boolean>) column);
break;
case TINYINT:
ListCNByteCodec.encode(clientMessage, (Iterable<Byte>) column);
break;
case SMALLINT:
ListCNShortCodec.encode(clientMessage, (Iterable<Short>) column);
break;
case INTEGER:
ListCNIntegerCodec.encode(clientMessage, (Iterable<Integer>) column);
break;
case BIGINT:
ListCNLongCodec.encode(clientMessage, (Iterable<Long>) column);
break;
case REAL:
ListCNFloatCodec.encode(clientMessage, (Iterable<Float>) column);
break;
case DOUBLE:
ListCNDoubleCodec.encode(clientMessage, (Iterable<Double>) column);
break;
case DATE:
ListCNLocalDateCodec.encode(clientMessage, (Iterable<LocalDate>) column);
break;
case TIME:
ListCNLocalTimeCodec.encode(clientMessage, (Iterable<LocalTime>) column);
break;
case TIMESTAMP:
ListCNLocalDateTimeCodec.encode(clientMessage, (Iterable<LocalDateTime>) column);
break;
case TIMESTAMP_WITH_TIME_ZONE:
ListCNOffsetDateTimeCodec.encode(clientMessage, (Iterable<OffsetDateTime>) column);
break;
case DECIMAL:
ListMultiFrameCodec.encode(clientMessage, (Iterable<BigDecimal>) column, BigDecimalCodec::encodeNullable);
break;
case NULL:
int size = 0;
for (Object ignore : column) {
size++;
}
byte[] sizeBuffer = new byte[FixedSizeTypesCodec.INT_SIZE_IN_BYTES];
FixedSizeTypesCodec.encodeInt(sizeBuffer, 0, size);
clientMessage.add(new ClientMessage.Frame(sizeBuffer));
break;
case OBJECT:
assert SqlPage.convertToData(columnType);
ListMultiFrameCodec.encode(clientMessage, (Iterable<Data>) column, DataCodec::encodeNullable);
break;
case JSON:
ListMultiFrameCodec.encodeContainsNullable(clientMessage, (Iterable<HazelcastJsonValue>) column, HazelcastJsonValueCodec::encode);
break;
default:
throw new IllegalStateException("Unknown type " + columnType);
}
}
clientMessage.add(END_FRAME.copy());
}
Aggregations