ContractDefinitionPayloadConverter implements PayloadConverter<ContractDefinition> { @Override public BytesValue convertToPayload(final ContractDefinition contractDefinition) { try { logger.debug("Convert to payload from {}", contractDefinition); final byte[] rawContract = contractDefinition.getDecodedContract().getValue(); final ByteArrayOutputStream rawStream = new ByteArrayOutputStream(); final LittleEndianDataOutputStream dataOut = new LittleEndianDataOutputStream(rawStream); try { dataOut.writeInt(rawContract.length + 4); dataOut.write(rawContract); if (!contractDefinition.getConstructorArgs().isEmpty()) { final BytesValue constructorArgs = mapper.marshal(contractDefinition.getConstructorArgs()); dataOut.write(constructorArgs.getValue()); } } finally { dataOut.close(); } return BytesValue.of(rawStream.toByteArray()); } catch (HerajException e) { throw e; } catch (Exception e) { throw new HerajException(e); } }  @Override BytesValue convertToPayload(final ContractDefinition contractDefinition); @Override ContractDefinition parseToModel(final BytesValue payload);  }
@Test public void testConvertToPayload() { final PayloadConverter<ContractDefinition> converter = new ContractDefinitionPayloadConverter(); final ContractDefinition definition = ContractDefinition.newBuilder() .encodedContract(encodedContract) .constructorArgs("1", "2") .build(); final BytesValue payload = converter.convertToPayload(definition); assertNotNull(payload); }