protected byte[] assertEncodeDecode(final IGangliaMetadataMessage decl,final IGangliaMessage expected){
  if (expected == null)   throw new IllegalArgumentException();
  final XDROutputBuffer xdr=new XDROutputBuffer(IGangliaDefaults.BUFFER_SIZE);
  final GangliaMessageEncoder31 messageEncoder=new GangliaMessageEncoder31();
  final GangliaMessageDecoder31 messageDecoder=new GangliaMessageDecoder31();
  if (expected.isMetricRequest()) {
    messageEncoder.writeRequest(xdr,(IGangliaRequestMessage)expected);
  }
 else   if (expected.isMetricMetadata()) {
    messageEncoder.writeMetadata(xdr,(IGangliaMetadataMessage)expected);
  }
 else   if (expected.isMetricValue()) {
    if (decl == null)     throw new IllegalArgumentException("Declaration required for metric value record");
    messageEncoder.writeMetric(xdr,decl,(IGangliaMetricMessage)expected);
  }
 else {
    throw new AssertionError();
  }
  final IGangliaMessage actual=messageDecoder.decode(xdr.getBuffer(),0,xdr.getLength());
  assertEquals("messages not equal()",expected,actual);
  final byte[] actualData=new byte[xdr.getLength()];
  System.arraycopy(xdr.getBuffer(),0,actualData,0,actualData.length);
  return actualData;
}

protected byte [ ] assertEncodeDecode ( final IGangliaMetadataMessage decl , final IGangliaMessage expected ) { if ( expected == null ) throw new IllegalArgumentException ( ) ; final XDROutputBuffer xdr = new XDROutputBuffer ( IGangliaDefaults . BUFFER_SIZE ) ; final GangliaMessageEncoder31 messageEncoder = new GangliaMessageEncoder31 ( ) ; final GangliaMessageDecoder31 messageDecoder = new GangliaMessageDecoder31 ( ) ; if ( expected . isMetricRequest ( ) ) { messageEncoder . writeRequest ( xdr , ( IGangliaRequestMessage ) expected ) ; } else if ( expected . isMetricMetadata ( ) ) { messageEncoder . writeMetadata ( xdr , ( IGangliaMetadataMessage ) expected ) ; } else if ( expected . isMetricValue ( ) ) { if ( decl == null ) throw new IllegalArgumentException ( "Declaration required for metric value record" ) ; messageEncoder . writeMetric ( xdr , decl , ( IGangliaMetricMessage ) expected ) ; } else { throw new AssertionError ( ) ; } final IGangliaMessage actual = messageDecoder . decode ( xdr . getBuffer ( ) , 0 , xdr . getLength ( ) ) ; assertEquals ( "messages not equal()" , expected , actual ) ; final byte [ ] actualData = new byte [ xdr . getLength ( ) ] ; System . arraycopy ( xdr . getBuffer ( ) , 0 , actualData , 0 , actualData . length ) ; return actualData ; }
verify that we can encode and decode a record .
