@ Override public NSMessage < T > decode ( final byte [ ] buf ) { if ( isStreamingCodec ) { final StreamingCodec < T > streamingCodec = ( StreamingCodec < T > ) codec ; try ( ByteArrayInputStream bais = new ByteArrayInputStream ( buf ) ) { try ( DataInputStream dais = new DataInputStream ( bais ) ) { final Identifier srcId = factory . getNewInstance ( dais . readUTF ( ) ) ; final Identifier destId = factory . getNewInstance ( dais . readUTF ( ) ) ; final int size = dais . readInt ( ) ; final List < T > list = new ArrayList <> ( size ) ; for ( int i = 0 ; i < size ; i ++ ) { list . add ( streamingCodec . decodeFromStream ( dais ) ) ; } return new NSMessage <> ( srcId , destId , list ) ; } } catch ( final IOException e ) { throw new RuntimeException ( "IOException" , e ) ; } } else { final NSMessagePBuf pbuf ; try { pbuf = NSMessagePBuf . parseFrom ( buf ) ; } catch ( final InvalidProtocolBufferException e ) { e . printStackTrace ( ) ; throw new NetworkRuntimeException ( e ) ; } final List < T > list = new ArrayList <> ( ) ; for ( final NSRecordPBuf rbuf : pbuf . getMsgsList ( ) ) { list . add ( codec . decode ( rbuf . getData ( ) . toByteArray ( ) ) ) ; } return new NSMessage <> ( factory . getNewInstance ( pbuf . getSrcid ( ) ) , factory . getNewInstance ( pbuf . getDestid ( ) ) , list ) ; } }
Decodes a network service message from bytes .