blob: e52bd4007e2193e4ca52cf79e884defc32e8a12d (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jrt;
import java.nio.ByteBuffer;
abstract class Packet
{
public static final int PCODE_REQUEST = 100;
public static final int PCODE_REPLY = 101;
public static final int PCODE_ERROR = 102;
public static final int FLAG_REVERSE = 0x1; // bit 0
public static final int FLAG_NOREPLY = 0x2; // bit 1
public static final int headerLength = 12;
public static boolean checkFlag(int flag, int flags) {
return (flags & flag) != 0;
}
private int flags;
private int requestId;
public Packet(int flags, int reqId) {
this.flags = flags;
this.requestId = reqId;
}
public int requestId() {
return requestId;
}
public boolean reverseByteOrder() {
return checkFlag(FLAG_REVERSE, flags);
}
public boolean noReply() {
return checkFlag(FLAG_NOREPLY, flags);
}
public abstract int bytes();
public abstract int packetCode();
public abstract void encode(ByteBuffer dst);
public PacketInfo getPacketInfo() {
return new PacketInfo(bytes(), flags, packetCode(), requestId);
}
}
|