use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.
the class RPCSendV1 method createReply.
@Override
protected Reply createReply(Values ret, String serviceName, Trace trace) {
Version version = new Version(ret.get(0).asUtf8Array());
double retryDelay = ret.get(1).asDouble();
int[] errorCodes = ret.get(2).asInt32Array();
String[] errorMessages = ret.get(3).asStringArray();
String[] errorServices = ret.get(4).asStringArray();
Utf8Array protocolName = ret.get(5).asUtf8Array();
byte[] payload = ret.get(6).asData();
String replyTrace = ret.get(7).asString();
// Make sure that the owner understands the protocol.
Reply reply = null;
Error error = null;
if (payload.length > 0) {
Object retval = decode(protocolName, version, payload);
if (retval instanceof Reply) {
reply = (Reply) retval;
} else {
error = (Error) retval;
}
}
if (reply == null) {
reply = new EmptyReply();
}
if (error != null) {
reply.addError(error);
}
reply.setRetryDelay(retryDelay);
for (int i = 0; i < errorCodes.length && i < errorMessages.length; i++) {
reply.addError(new Error(errorCodes[i], errorMessages[i], errorServices[i].length() > 0 ? errorServices[i] : serviceName));
}
if (trace.getLevel() > 0) {
trace.getRoot().addChild(TraceNode.decode(replyTrace));
}
return reply;
}
use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.
the class ByteWriterTestCase method testWriteUtf8Array.
public void testWriteUtf8Array() throws IOException {
stream.reset();
ByteWriter b = new ByteWriter(stream, encoder);
final byte[] bytes = Utf8.toBytes("nalle");
b.write(new Utf8Array(bytes));
b.close();
assertArrayEquals(bytes, stream.toByteArray());
}
use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.
the class SerializationHelperTestCase method testGetNullTerminatedString.
public void testGetNullTerminatedString() throws Exception {
// This is a test.0ab
byte[] test = { 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x0, 0x61, 0x62 };
BufferSerializer data = BufferSerializer.wrap(test);
assertTrue(data.position() == 0);
Utf8Array thisIsATest = VespaDocumentDeserializer42.parseNullTerminatedString(data.getBuf().getByteBuffer());
assertTrue(thisIsATest.equals(new Utf8Array(Utf8.toBytes("This is a test."))));
assertTrue(data.position() == 16);
// a
assertTrue(test[16] == 0x61);
data.position(0);
assertTrue(data.position() == 0);
Utf8Array thisIsATestAgain = VespaDocumentDeserializer42.parseNullTerminatedString(data.getBuf().getByteBuffer(), 15);
assertTrue(thisIsATestAgain.equals(new Utf8Array(Utf8.toBytes("This is a test."))));
assertTrue(data.position() == 16);
// a
assertTrue(test[16] == 0x61);
}
use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.
the class StoragePolicyTestEnvironment method setUp.
@Override
public void setUp() throws Exception {
DocumentTypeManager manager = new DocumentTypeManager();
DocumentTypeManagerConfigurer.configure(manager, "file:./test/cfg/testdoc.cfg");
frame = new PolicyTestFrame(manager);
nodes = new TreeSet<>();
DocumentProtocol protocol = (DocumentProtocol) frame.getMessageBus().getProtocol((Utf8Array) DocumentProtocol.NAME);
policyFactory = new StoragePolicyTestFactory(nodes);
protocol.putRoutingPolicyFactory("storage", policyFactory);
frame.setMessage(createMessage("userdoc:ns:1:foo"));
frame.setHop(new HopSpec("test", "[storage:cluster=foo]"));
}
use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.
the class ConfigPayload method toUtf8Array.
public Utf8Array toUtf8Array(boolean compact) {
ByteArrayOutputStream os = new ByteArrayOutputStream(10000);
try {
new JsonFormat(compact).encode(os, slime);
os.close();
} catch (IOException e) {
e.printStackTrace();
}
return new Utf8Array(os.toByteArray());
}
Aggregations