/** * Internal use only. * * <p>Creates a new service request using the <code>data</code> byte array and information from * the KNXnet/IP header, but leaves out the cEMI part.<br> * This helper will not try to create the cEMI structure contained in the data part, i.e. the * returned service request is incomplete and {@link ServiceRequest#getCEMI()} returns <code>null * </code>. The service request must not be used for the creation of KNXnet/IP packets. * * @param h KNXnet/IP header associated with <code>data</code> * @param data byte array containing the data following the KNXnet/IP header in the message * structure * @param offset offset into <code>data</code> pointing at the begin of usable data * @return the new empty service request * @throws KNXFormatException if the data buffer is too short for the request or unsupported * connection header structure */ public static ServiceRequest getEmptyServiceRequest(KNXnetIPHeader h, byte[] data, int offset) throws KNXFormatException { return new ServiceRequest( h.getServiceType(), data, offset, h.getTotalLength() - h.getStructLength(), null); }
/** * Creates a packet with a KNXnet/IP message header v1.0, containing the specified service <code> * type</code>, and generates the corresponding byte representation of this structure. * * @param type service type to pack * @return the packet as byte array */ public static byte[] toPacket(ServiceType type) { final KNXnetIPHeader h = new KNXnetIPHeader(type.svcType, type.getStructLength()); final ByteArrayOutputStream os = new ByteArrayOutputStream(h.getTotalLength()); os.write(h.toByteArray(), 0, h.getStructLength()); return type.toByteArray(os); }