aboutsummaryrefslogtreecommitdiffstats
path: root/jrt/src/com/yahoo/jrt/ErrorPacket.java
blob: d66fba2b9270c1721e1454527dfa617cdabfc88c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jrt;


import java.nio.ByteBuffer;


class ErrorPacket extends Packet
{
    private int         errorCode;
    private StringValue errorMessage;

    public ErrorPacket(int flags, int reqId,
                       int errorCode,
                       String errorMessage)
    {
        super(flags, reqId);
        this.errorCode = errorCode;
        this.errorMessage = new StringValue(errorMessage);
    }

    public ErrorPacket(int flags, int reqId,
                       ByteBuffer src)
    {
        super(flags, reqId);
        errorCode = src.getInt();
        errorMessage = new StringValue(src);
    }

    public int bytes() {
        return (headerLength +
                4 +
                errorMessage.bytes());
    }

    public int packetCode() {
        return PCODE_ERROR;
    }

    public void encode(ByteBuffer dst) {
        dst.putInt(errorCode);
        errorMessage.encode(dst);
    }

    public int errorCode() {
        return errorCode;
    }

    public String errorMessage() {
        return errorMessage.asString();
    }
}