use of com.yahoo.slime.Cursor in project vespa by vespa-engine.
the class DeployHandlerLoggerTest method testLogging.
private void testLogging(boolean verbose, String expectedPattern) throws IOException {
Slime slime = new Slime();
Cursor array = slime.setArray();
DeployLogger logger = new DeployHandlerLogger(array, verbose, new ApplicationId.Builder().tenant("testtenant").applicationName("testapp").build());
logMessages(logger);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new JsonFormat(true).encode(baos, slime);
assertTrue(Pattern.matches(expectedPattern, baos.toString()));
}
use of com.yahoo.slime.Cursor in project vespa by vespa-engine.
the class JSONStringTestCase method getSlime5.
private Inspector getSlime5() {
Slime slime = new Slime();
Cursor arr = slime.setArray();
arr.addLong(1);
arr.addLong(2);
arr.addLong(3);
return new SlimeAdapter(slime.get());
}
use of com.yahoo.slime.Cursor in project vespa by vespa-engine.
the class RPCSendV2 method encodeRequest.
@Override
protected Request encodeRequest(Version version, Route route, RPCServiceAddress address, Message msg, long timeRemaining, byte[] payload, int traceLevel) {
Request req = new Request(METHOD_NAME);
Values v = req.parameters();
v.add(new Int8Value(CompressionType.NONE.getCode()));
v.add(new Int32Value(0));
v.add(new DataValue(new byte[0]));
Slime slime = new Slime();
Cursor root = slime.setObject();
root.setString(VERSION_F, version.toString());
root.setString(ROUTE_F, route.toString());
root.setString(SESSION_F, address.getSessionName());
root.setString(PROTOCOL_F, msg.getProtocol().toString());
root.setBool(USERETRY_F, msg.getRetryEnabled());
root.setLong(RETRY_F, msg.getRetry());
root.setLong(TIMEREMAINING_F, msg.getTimeRemaining());
root.setLong(TRACELEVEL_F, traceLevel);
root.setData(BLOB_F, payload);
byte[] serializedSlime = BinaryFormat.encode(slime);
Compressor.Compression compressionResult = compressor.compress(serializedSlime);
v.add(new Int8Value(compressionResult.type().getCode()));
v.add(new Int32Value(compressionResult.uncompressedSize()));
v.add(new DataValue(compressionResult.data()));
return req;
}
use of com.yahoo.slime.Cursor in project vespa by vespa-engine.
the class RPCSendV2 method createResponse.
@Override
protected void createResponse(Values ret, Reply reply, Version version, byte[] payload) {
ret.add(new Int8Value(CompressionType.NONE.getCode()));
ret.add(new Int32Value(0));
ret.add(new DataValue(new byte[0]));
Slime slime = new Slime();
Cursor root = slime.setObject();
root.setString(VERSION_F, version.toString());
root.setDouble(RETRYDELAY_F, reply.getRetryDelay());
root.setString(PROTOCOL_F, reply.getProtocol().toString());
root.setData(BLOB_F, payload);
if (reply.getTrace().getLevel() > 0) {
root.setString(TRACE_F, reply.getTrace().getRoot().encode());
}
if (reply.getNumErrors() > 0) {
Cursor array = root.setArray(ERRORS_F);
for (int i = 0; i < reply.getNumErrors(); i++) {
Cursor e = array.addObject();
Error mbusE = reply.getError(i);
e.setLong(CODE_F, mbusE.getCode());
e.setString(MSG_F, mbusE.getMessage());
if (mbusE.getService() != null) {
e.setString(SERVICE_F, mbusE.getService());
}
}
}
byte[] serializedSlime = BinaryFormat.encode(slime);
Compressor.Compression compressionResult = compressor.compress(serializedSlime);
ret.add(new Int8Value(compressionResult.type().getCode()));
ret.add(new Int32Value(compressionResult.uncompressedSize()));
ret.add(new DataValue(compressionResult.data()));
}
use of com.yahoo.slime.Cursor in project vespa by vespa-engine.
the class JsonFormat method encode.
/**
* Serialize the given tensor into JSON format
*/
public static byte[] encode(Tensor tensor) {
Slime slime = new Slime();
Cursor root = slime.setObject();
Cursor cellsArray = root.setArray("cells");
for (Iterator<Tensor.Cell> i = tensor.cellIterator(); i.hasNext(); ) {
Tensor.Cell cell = i.next();
Cursor cellObject = cellsArray.addObject();
encodeAddress(tensor.type(), cell.getKey(), cellObject.setObject("address"));
cellObject.setDouble("value", cell.getValue());
}
return com.yahoo.slime.JsonFormat.toJsonBytes(slime);
}
Aggregations