}
private void assemble(Frame frame, ByteBuffer segment)
{
BBDecoder dec = _decoder.get();
dec.init(segment);
int channel = frame.getChannel();
Method command;
switch (frame.getType())
{
case CONTROL:
int controlType = dec.readUint16();
Method control = Method.create(controlType);
control.read(dec);
emit(channel, control);
break;
case COMMAND:
int commandType = dec.readUint16();
// read in the session header, right now we don't use it
int hdr = dec.readUint16();
command = Method.create(commandType);
command.setSync((0x0001 & hdr) != 0);
command.read(dec);
if (command.hasPayload())
{
setIncompleteCommand(channel, command);
}
else
{
emit(channel, command);
}
break;
case HEADER:
command = getIncompleteCommand(channel);
List<Struct> structs = new ArrayList<Struct>(2);
while (dec.hasRemaining())
{
structs.add(dec.readStruct32());
}
command.setHeader(new Header(structs));
if (frame.isLastSegment())
{
setIncompleteCommand(channel, null);
emit(channel, command);
}
break;
case BODY:
command = getIncompleteCommand(channel);
command.setBody(segment);
setIncompleteCommand(channel, null);
emit(channel, command);
break;
default:
throw new IllegalStateException("unknown frame type: " + frame.getType());
}
dec.releaseBuffer();
}