Search in sources :

Example 11 with Utf8Array

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\"}"));
}
Also used : SimpletypesConfig(com.yahoo.foo.SimpletypesConfig) InnerCNode(com.yahoo.config.codegen.InnerCNode) DefParser(com.yahoo.config.codegen.DefParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) StringReader(java.io.StringReader) LZ4PayloadCompressor(com.yahoo.vespa.config.LZ4PayloadCompressor) Utf8Array(com.yahoo.text.Utf8Array) Test(org.junit.Test)

Example 12 with Utf8Array

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;
}
Also used : Version(com.yahoo.component.Version) Inspector(com.yahoo.slime.Inspector) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Error(com.yahoo.messagebus.Error) Slime(com.yahoo.slime.Slime) CompressionType(com.yahoo.compress.CompressionType) Utf8Array(com.yahoo.text.Utf8Array) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 13 with Utf8Array

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;
}
Also used : Version(com.yahoo.component.Version) Inspector(com.yahoo.slime.Inspector) Slime(com.yahoo.slime.Slime) CompressionType(com.yahoo.compress.CompressionType) Utf8Array(com.yahoo.text.Utf8Array)

Example 14 with Utf8Array

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;
}
Also used : Utf8String(com.yahoo.text.Utf8String) DocumentType(com.yahoo.document.DocumentType) DataTypeName(com.yahoo.document.DataTypeName) Utf8Array(com.yahoo.text.Utf8Array)

Example 15 with Utf8Array

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;
}
Also used : Utf8Array(com.yahoo.text.Utf8Array)

Aggregations

Utf8Array (com.yahoo.text.Utf8Array)15 Version (com.yahoo.component.Version)3 Slime (com.yahoo.slime.Slime)3 CompressionType (com.yahoo.compress.CompressionType)2 EmptyReply (com.yahoo.messagebus.EmptyReply)2 Error (com.yahoo.messagebus.Error)2 Reply (com.yahoo.messagebus.Reply)2 Inspector (com.yahoo.slime.Inspector)2 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)2 LZ4PayloadCompressor (com.yahoo.vespa.config.LZ4PayloadCompressor)2 CompressionInfo (com.yahoo.vespa.config.protocol.CompressionInfo)2 SlimeConfigResponse (com.yahoo.vespa.config.protocol.SlimeConfigResponse)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Test (org.junit.Test)2 EqualsTester (com.google.common.testing.EqualsTester)1 DefParser (com.yahoo.config.codegen.DefParser)1 InnerCNode (com.yahoo.config.codegen.InnerCNode)1 DataTypeName (com.yahoo.document.DataTypeName)1 DocumentType (com.yahoo.document.DocumentType)1 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)1