final long predictedSize = producer.getSize(msgInEnv, null, null, null, null);
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
producer.writeTo(msgInEnv, msgInEnv.getClass(), null, null, null, null, bos);
} catch (IOException e) {
throw new OpenGammaRuntimeException("ioexception", e);
}
final byte[] data = bos.toByteArray();
if (predictedSize != -1) {
assertEquals(predictedSize, data.length);
}
assertTrue(consumer.isReadable(FudgeMsgEnvelope.class, null, null, null));
final ByteArrayInputStream bis = new ByteArrayInputStream(data);
final FudgeMsg msgOut;
try {
final FudgeMsgEnvelope env = (FudgeMsgEnvelope) consumer.readFrom(FudgeMsgEnvelope.class, null, null, null, null, bis);
assertNotNull(env);
msgOut = env.getMessage();
} catch (IOException e) {
throw new OpenGammaRuntimeException("ioexception", e);
}
assertNotNull(msgOut);
assertEquals("bar", msgOut.getFieldValue(String.class, msgOut.getByName("foo")));
assertEquals((Integer) 42, msgOut.getFieldValue(Integer.class, msgOut.getByName("number")));
}