// 1. Convert message to a stream that can be decoded.
ChannelBuffer buffer = (ChannelBuffer) msg;
ChannelBufferInputStream inputStream = new ChannelBufferInputStream(buffer);
// 2. Get first byte: message type:
int enumValue = inputStream.readByte();
RequestType type = RequestType.values()[enumValue];
if (LOG.isDebugEnabled()) {
LOG.debug("decode: Got a response of type " + type + " from server:" +
channel.getRemoteAddress());
}
// 3. Create object of the type determined in step 2.
Class<? extends WritableRequest> writableRequestClass =
type.getRequestClass();
WritableRequest serverResponse =
ReflectionUtils.newInstance(writableRequestClass, conf);
// 4. Deserialize the inputStream's contents into the newly-constructed
// serverResponse object.
try {