use of com.yahoo.slime.Cursor in project vespa by vespa-engine.
the class ConfigChangeActionsSlimeConverterTest method toJson.
private static String toJson(ConfigChangeActions actions) throws IOException {
Slime slime = new Slime();
Cursor root = slime.setObject();
new ConfigChangeActionsSlimeConverter(actions).toSlime(root);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
new JsonFormat(false).encode(outputStream, slime);
return outputStream.toString();
}
use of com.yahoo.slime.Cursor in project vespa by vespa-engine.
the class Dispatcher method toSlime.
private static Slime toSlime(String rankProfile, String summaryClass, String docType, SessionId sessionId, List<FastHit> hits) {
Slime slime = new Slime();
Cursor root = slime.setObject();
if (summaryClass != null) {
root.setString("class", summaryClass);
}
if (sessionId != null) {
root.setData("sessionid", sessionId.asUtf8String().getBytes());
}
if (docType != null) {
root.setString("doctype", docType);
}
if (rankProfile != null) {
root.setString("ranking", rankProfile);
}
Cursor gids = root.setArray("gids");
for (FastHit hit : hits) {
gids.addData(hit.getGlobalId().getRawId());
}
return slime;
}
use of com.yahoo.slime.Cursor in project vespa by vespa-engine.
the class ProjectBundleClassPaths method save.
static void save(OutputStream out, ProjectBundleClassPaths mappings) throws IOException {
Slime slime = new Slime();
Cursor rootCursor = slime.setObject();
Cursor mainBundleCursor = rootCursor.setObject("mainBundle");
BundleClasspathMapping.save(mainBundleCursor, mappings.mainBundle);
Cursor dependenciesCursor = rootCursor.setArray("providedDependencies");
mappings.providedDependencies.forEach(d -> BundleClasspathMapping.save(dependenciesCursor.addObject(), d));
new JsonFormat(false).encode(out, slime);
}
use of com.yahoo.slime.Cursor in project vespa by vespa-engine.
the class JSONStringTestCase method getSlime4.
private Inspector getSlime4() {
Slime slime = new Slime();
Cursor obj = slime.setObject();
obj.setLong("foo", 1);
return new SlimeAdapter(slime.get());
}
use of com.yahoo.slime.Cursor in project vespa by vespa-engine.
the class MockClient method getDocsums.
@Override
public void getDocsums(List<FastHit> hitsContext, NodeConnection node, CompressionType compression, int uncompressedSize, byte[] compressedSlime, Dispatcher.GetDocsumsResponseReceiver responseReceiver, double timeoutSeconds) {
if (malfunctioning) {
responseReceiver.receive(GetDocsumsResponseOrError.fromError("Malfunctioning"));
return;
}
Inspector request = BinaryFormat.decode(compressor.decompress(compressedSlime, compression, uncompressedSize)).get();
String docsumClass = request.field("class").asString();
List<Map<String, Object>> docsumsToReturn = new ArrayList<>();
request.field("gids").traverse((ArrayTraverser) (index, gid) -> {
GlobalId docId = new GlobalId(gid.asData());
docsumsToReturn.add(docsums.get(new DocsumKey(node.toString(), docId, docsumClass)));
});
Slime responseSlime = new Slime();
Cursor root = responseSlime.setObject();
Cursor docsums = root.setArray("docsums");
for (Map<String, Object> docsumFields : docsumsToReturn) {
Cursor docsumItem = docsums.addObject();
Cursor docsum = docsumItem.setObject("docsum");
for (Map.Entry<String, Object> field : docsumFields.entrySet()) {
if (field.getValue() instanceof Integer)
docsum.setLong(field.getKey(), (Integer) field.getValue());
else if (field.getValue() instanceof String)
docsum.setString(field.getKey(), (String) field.getValue());
else
throw new RuntimeException();
}
}
byte[] slimeBytes = BinaryFormat.encode(responseSlime);
Compressor.Compression compressionResult = compressor.compress(compression, slimeBytes);
GetDocsumsResponse response = new GetDocsumsResponse(compressionResult.type().getCode(), slimeBytes.length, compressionResult.data(), hitsContext);
responseReceiver.receive(GetDocsumsResponseOrError.fromResponse(response));
}
Aggregations