use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.
the class ConfigResponseTest method require_that_slime_response_decompresses_on_serialize.
@Test
public void require_that_slime_response_decompresses_on_serialize() throws IOException {
ConfigPayload configPayload = ConfigPayload.fromInstance(new SimpletypesConfig(new SimpletypesConfig.Builder()));
DefParser dParser = new DefParser(SimpletypesConfig.getDefName(), new StringReader(StringUtilities.implode(SimpletypesConfig.CONFIG_DEF_SCHEMA, "\n")));
InnerCNode targetDef = dParser.getTree();
Utf8Array data = configPayload.toUtf8Array(true);
Utf8Array bytes = new Utf8Array(new LZ4PayloadCompressor().compress(data.getBytes()));
ConfigResponse response = new SlimeConfigResponse(bytes, targetDef, 3, "mymd5", CompressionInfo.create(CompressionType.LZ4, data.getByteLength()));
List<String> payload = response.getLegacyPayload();
assertNotNull(payload);
assertThat(payload.size(), is(6));
assertThat(payload.get(0), is("boolval false"));
assertThat(response.getGeneration(), is(3L));
assertThat(response.getConfigMd5(), is("mymd5"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
response.serialize(baos, CompressionType.UNCOMPRESSED);
assertThat(baos.toString(), is("{\"boolval\":false,\"doubleval\":0.0,\"enumval\":\"VAL1\",\"intval\":0,\"longval\":0,\"stringval\":\"s\"}"));
}
use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.
the class RPCSendV2 method createReply.
@Override
protected Reply createReply(Values ret, String serviceName, Trace trace) {
CompressionType compression = CompressionType.valueOf(ret.get(3).asInt8());
byte[] slimeBytes = compressor.decompress(ret.get(5).asData(), compression, ret.get(4).asInt32());
Slime slime = BinaryFormat.decode(slimeBytes);
Inspector root = slime.get();
Version version = new Version(root.field(VERSION_F).asString());
byte[] payload = root.field(BLOB_F).asData();
// Make sure that the owner understands the protocol.
Reply reply = null;
Error error = null;
if (payload.length > 0) {
Object retval = decode(new Utf8Array(root.field(PROTOCOL_F).asUtf8()), 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(root.field(RETRYDELAY_F).asDouble());
Inspector errors = root.field(ERRORS_F);
for (int i = 0; i < errors.entries(); i++) {
Inspector e = errors.entry(i);
String service = e.field(SERVICE_F).asString();
reply.addError(new Error((int) e.field(CODE_F).asLong(), e.field(MSG_F).asString(), (service != null && service.length() > 0) ? service : serviceName));
}
if (trace.getLevel() > 0) {
trace.getRoot().addChild(TraceNode.decode(root.field(TRACE_F).asString()));
}
return reply;
}
use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.
the class RPCSendV2 method toParams.
protected Params toParams(Values args) {
CompressionType compression = CompressionType.valueOf(args.get(3).asInt8());
byte[] slimeBytes = compressor.decompress(args.get(5).asData(), compression, args.get(4).asInt32());
Slime slime = BinaryFormat.decode(slimeBytes);
Inspector root = slime.get();
Params p = new Params();
p.version = new Version(root.field(VERSION_F).asString());
p.route = root.field(ROUTE_F).asString();
p.session = root.field(SESSION_F).asString();
p.retryEnabled = root.field(USERETRY_F).asBool();
p.retry = (int) root.field(RETRY_F).asLong();
p.timeRemaining = root.field(TIMEREMAINING_F).asLong();
p.protocolName = new Utf8Array(Utf8.toBytes(root.field(PROTOCOL_F).asString()));
p.payload = root.field(BLOB_F).asData();
p.traceLevel = (int) root.field(TRACELEVEL_F).asLong();
return p;
}
use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.
the class VespaDocumentDeserializer42 method readDocumentType.
public DocumentType readDocumentType() {
Utf8Array docTypeName = parseNullTerminatedString();
// used to hold the version
int ignored = getShort(null);
DocumentType docType = manager.getDocumentType(new DataTypeName(docTypeName));
if (docType == null) {
throw new DeserializationException("No known document type with name " + new Utf8String(docTypeName).toString());
}
return docType;
}
use of com.yahoo.text.Utf8Array in project vespa by vespa-engine.
the class VespaDocumentDeserializer42 method parseNullTerminatedString.
static Utf8Array parseNullTerminatedString(ByteBuffer buf, int lengthExcludingNull) throws DeserializationException {
Utf8Array utf8 = new Utf8Array(buf, lengthExcludingNull);
// move past 0-termination
buf.get();
return utf8;
}
Aggregations