use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.
the class CreateTopicsResponse method toStruct.
@Override
protected Struct toStruct(short version) {
Struct struct = new Struct(ApiKeys.CREATE_TOPICS.responseSchema(version));
List<Struct> topicErrorsStructs = new ArrayList<>(errors.size());
for (Map.Entry<String, Error> topicError : errors.entrySet()) {
Struct topicErrorsStruct = struct.instance(TOPIC_ERRORS_KEY_NAME);
topicErrorsStruct.set(TOPIC_KEY_NAME, topicError.getKey());
Error error = topicError.getValue();
topicErrorsStruct.set(ERROR_CODE_KEY_NAME, error.error.code());
if (version >= 1)
topicErrorsStruct.set(ERROR_MESSAGE_KEY_NAME, error.message());
topicErrorsStructs.add(topicErrorsStruct);
}
struct.set(TOPIC_ERRORS_KEY_NAME, topicErrorsStructs.toArray());
return struct;
}
use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.
the class DeleteTopicsResponse method toStruct.
@Override
protected Struct toStruct(short version) {
Struct struct = new Struct(ApiKeys.DELETE_TOPICS.responseSchema(version));
List<Struct> topicErrorCodeStructs = new ArrayList<>(errors.size());
for (Map.Entry<String, Errors> topicError : errors.entrySet()) {
Struct topicErrorCodeStruct = struct.instance(TOPIC_ERROR_CODES_KEY_NAME);
topicErrorCodeStruct.set(TOPIC_KEY_NAME, topicError.getKey());
topicErrorCodeStruct.set(ERROR_CODE_KEY_NAME, topicError.getValue().code());
topicErrorCodeStructs.add(topicErrorCodeStruct);
}
struct.set(TOPIC_ERROR_CODES_KEY_NAME, topicErrorCodeStructs.toArray());
return struct;
}
use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.
the class DescribeGroupsRequest method toStruct.
@Override
protected Struct toStruct() {
Struct struct = new Struct(ApiKeys.DESCRIBE_GROUPS.requestSchema(version()));
struct.set(GROUP_IDS_KEY_NAME, groupIds.toArray());
return struct;
}
use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.
the class FetchResponse method addTopicData.
private static void addTopicData(String dest, List<Send> sends, Struct topicData) {
String topic = topicData.getString(TOPIC_KEY_NAME);
Object[] allPartitionData = topicData.getArray(PARTITIONS_KEY_NAME);
// include the topic header and the count for the number of partitions
ByteBuffer buffer = ByteBuffer.allocate(Type.STRING.sizeOf(topic) + 4);
Type.STRING.write(buffer, topic);
buffer.putInt(allPartitionData.length);
buffer.rewind();
sends.add(new ByteBufferSend(dest, buffer));
for (Object partitionData : allPartitionData) addPartitionData(dest, sends, (Struct) partitionData);
}
use of org.apache.kafka.common.protocol.types.Struct in project kafka by apache.
the class FetchResponse method toStruct.
private static Struct toStruct(short version, LinkedHashMap<TopicPartition, PartitionData> responseData, int throttleTime) {
Struct struct = new Struct(ApiKeys.FETCH.responseSchema(version));
List<FetchRequest.TopicAndPartitionData<PartitionData>> topicsData = FetchRequest.TopicAndPartitionData.batchByTopic(responseData);
List<Struct> topicArray = new ArrayList<>();
for (FetchRequest.TopicAndPartitionData<PartitionData> topicEntry : topicsData) {
Struct topicData = struct.instance(RESPONSES_KEY_NAME);
topicData.set(TOPIC_KEY_NAME, topicEntry.topic);
List<Struct> partitionArray = new ArrayList<>();
for (Map.Entry<Integer, PartitionData> partitionEntry : topicEntry.partitions.entrySet()) {
PartitionData fetchPartitionData = partitionEntry.getValue();
Struct partitionData = topicData.instance(PARTITIONS_KEY_NAME);
Struct partitionDataHeader = partitionData.instance(PARTITION_HEADER_KEY_NAME);
partitionDataHeader.set(PARTITION_KEY_NAME, partitionEntry.getKey());
partitionDataHeader.set(ERROR_CODE_KEY_NAME, fetchPartitionData.error.code());
partitionDataHeader.set(HIGH_WATERMARK_KEY_NAME, fetchPartitionData.highWatermark);
partitionData.set(PARTITION_HEADER_KEY_NAME, partitionDataHeader);
partitionData.set(RECORD_SET_KEY_NAME, fetchPartitionData.records);
partitionArray.add(partitionData);
}
topicData.set(PARTITIONS_KEY_NAME, partitionArray.toArray());
topicArray.add(topicData);
}
struct.set(RESPONSES_KEY_NAME, topicArray.toArray());
if (version >= 1)
struct.set(THROTTLE_TIME_KEY_NAME, throttleTime);
return struct;
}
Aggregations