Methods Summary |
---|
public abstract void | connected()Called when the DDM server connects. The handler is allowed to
send messages to the server.
|
public static Chunk | createFailChunk(int errorCode, java.lang.String msg)Create a FAIL chunk. The "handleChunk" methods can use this to
return an error message when they are not able to process a chunk.
if (msg == null)
msg = "";
ByteBuffer out = ByteBuffer.allocate(8 + msg.length() * 2);
out.order(ChunkHandler.CHUNK_ORDER);
out.putInt(errorCode);
out.putInt(msg.length());
putString(out, msg);
return new Chunk(CHUNK_FAIL, out);
|
public abstract void | disconnected()Called when the DDM server disconnects. Can be used to disable
periodic transmissions or clean up saved state.
|
public static java.lang.String | getString(java.nio.ByteBuffer buf, int len)Utility function to copy a String out of a ByteBuffer.
This is here because multiple chunk handlers can make use of it,
and there's nowhere better to put it.
char[] data = new char[len];
for (int i = 0; i < len; i++)
data[i] = buf.getChar();
return new String(data);
|
public abstract Chunk | handleChunk(Chunk request)Handle a single chunk of data. "request" includes the type and
the chunk payload.
Returns a response in a Chunk.
|
public static java.lang.String | name(int type)Convert an integer type to a 4-character string.
char[] ascii = new char[4];
ascii[0] = (char) ((type >> 24) & 0xff);
ascii[1] = (char) ((type >> 16) & 0xff);
ascii[2] = (char) ((type >> 8) & 0xff);
ascii[3] = (char) (type & 0xff);
return new String(ascii);
|
public static void | putString(java.nio.ByteBuffer buf, java.lang.String str)Utility function to copy a String into a ByteBuffer.
int len = str.length();
for (int i = 0; i < len; i++)
buf.putChar(str.charAt(i));
|
public static int | type(java.lang.String typeName)Convert a 4-character string to a 32-bit type.
int val = 0;
if (typeName.length() != 4)
throw new RuntimeException();
for (int i = 0; i < 4; i++) {
val <<= 8;
val |= (byte) typeName.charAt(i);
}
return val;
|
public static java.nio.ByteBuffer | wrapChunk(Chunk request)Utility function to wrap a ByteBuffer around a Chunk.
ByteBuffer in;
in = ByteBuffer.wrap(request.data, request.offset, request.length);
in.order(CHUNK_ORDER);
return in;
|