use of org.infinispan.protostream.WrappedMessage in project infinispan by infinispan.
the class DefaultQuerySerializer method createQueryResponse.
@Override
public QueryResponse createQueryResponse(RemoteQueryResult remoteQueryResult) {
List<?> list = remoteQueryResult.getResults();
int numResults = list.size();
String[] projection = remoteQueryResult.getProjections();
int projSize = projection != null ? projection.length : 0;
List<WrappedMessage> results = new ArrayList<>(projSize == 0 ? numResults : numResults * projSize);
for (Object o : list) {
if (projSize == 0) {
results.add(new WrappedMessage(o));
} else {
Object[] row = (Object[]) o;
for (int i = 0; i < projSize; i++) {
results.add(new WrappedMessage(row[i]));
}
}
}
QueryResponse response = new QueryResponse();
response.setTotalResults(remoteQueryResult.getTotalResults());
response.setNumResults(numResults);
response.setProjectionSize(projSize);
response.setResults(results);
return response;
}
use of org.infinispan.protostream.WrappedMessage in project infinispan by infinispan.
the class FilterResultMarshaller method readFrom.
@Override
public FilterResult readFrom(ProtoStreamReader reader) throws IOException {
byte[] instance = reader.readBytes("instance");
List<WrappedMessage> projection = reader.readCollection("projection", new ArrayList<>(), WrappedMessage.class);
List<WrappedMessage> sortProjection = reader.readCollection("sortProjection", new ArrayList<>(), WrappedMessage.class);
Object i = null;
if (instance != null) {
i = ProtobufUtil.fromWrappedByteArray(reader.getSerializationContext(), instance);
}
Object[] p = null;
if (!projection.isEmpty()) {
p = new Object[projection.size()];
int j = 0;
for (WrappedMessage m : projection) {
p[j++] = m.getValue();
}
}
Comparable[] sp = null;
if (!sortProjection.isEmpty()) {
sp = new Comparable[sortProjection.size()];
int j = 0;
for (WrappedMessage m : sortProjection) {
sp[j++] = (Comparable) m.getValue();
}
}
return new FilterResult(i, p, sp);
}
use of org.infinispan.protostream.WrappedMessage in project infinispan by infinispan.
the class FilterResultMarshaller method writeTo.
@Override
public void writeTo(ProtoStreamWriter writer, FilterResult filterResult) throws IOException {
if (filterResult.getProjection() == null) {
// skip marshalling the instance if there is a projection
writer.writeBytes("instance", (byte[]) filterResult.getInstance());
} else {
WrappedMessage[] p = new WrappedMessage[filterResult.getProjection().length];
for (int i = 0; i < p.length; i++) {
p[i] = new WrappedMessage(filterResult.getProjection()[i]);
}
writer.writeArray("projection", p, WrappedMessage.class);
}
if (filterResult.getSortProjection() != null) {
WrappedMessage[] p = new WrappedMessage[filterResult.getSortProjection().length];
for (int i = 0; i < p.length; i++) {
p[i] = new WrappedMessage(filterResult.getSortProjection()[i]);
}
writer.writeArray("sortProjection", p, WrappedMessage.class);
}
}
use of org.infinispan.protostream.WrappedMessage in project infinispan by infinispan.
the class QueryResponse method extractResults.
@Override
public List<?> extractResults(SerializationContext serializationContext) throws IOException {
List<Object> unwrappedResults;
if (projectionSize > 0) {
unwrappedResults = new ArrayList<>(results.size() / projectionSize);
Iterator<WrappedMessage> it = results.iterator();
while (it.hasNext()) {
Object[] row = new Object[projectionSize];
for (int i = 0; i < row.length; i++) {
row[i] = it.next().getValue();
}
unwrappedResults.add(row);
}
} else {
unwrappedResults = new ArrayList<>(results.size());
for (WrappedMessage r : results) {
Object o = r.getValue();
if (serializationContext != null && o instanceof byte[]) {
o = ProtobufUtil.fromWrappedByteArray(serializationContext, (byte[]) o);
}
unwrappedResults.add(o);
}
}
return unwrappedResults;
}
use of org.infinispan.protostream.WrappedMessage in project protostream by infinispan.
the class CompileTimeProtoSchemaGenerator method importProtoTypeMetadata.
@Override
protected ProtoTypeMetadata importProtoTypeMetadata(XClass javaType) {
if (javaType == typeFactory.fromClass(WrappedMessage.class)) {
GenericDescriptor descriptor = serializationContext.getDescriptorByName(WrappedMessage.PROTOBUF_TYPE_NAME);
BaseMarshaller<WrappedMessage> marshaller = serializationContext.getMarshaller(WrappedMessage.PROTOBUF_TYPE_NAME);
return new ImportedProtoTypeMetadata(descriptor, marshaller, javaType);
}
String fileName = dependencies.get(javaType);
if (fileName != null) {
String packageName = serializationContext.getFileDescriptors().get(fileName).getPackage();
return new CompileTimeImportedProtoTypeMetadata(makeTypeMetadata(javaType), packageName, fileName);
}
return null;
}
Aggregations