this.payloadWriter = payloadWriter;
}
public void write(InterHubMessage message) throws Exception {
if (message instanceof ChannelMessage) {
ChannelMessage channelMessage = (ChannelMessage) message;
encoder.writeByte(CHANNEL_MESSAGE);
writeChannelId(channelMessage);
payloadWriter.write(channelMessage.getPayload());
} else if (message instanceof EndOfStream) {
encoder.writeByte(END_STREAM_MESSAGE);
} else {
throw new IllegalArgumentException();
}