/** * Gets a ByteBuf from the Message that contains the encoded bytes to be sent on the wire. * <p> * When possible this method will present the bytes to the caller without copying them into * a new buffer copy. If copying is needed a new Netty buffer is created and returned. The * caller should ensure that the reference count on the returned buffer is always decremented * to avoid a leak in the case of a copied buffer being returned. * * @param deliveryCount * The new delivery count for this message. * * @return a Netty ByteBuf containing the encoded bytes of this Message instance. */ public ReadableBuffer getSendBuffer(int deliveryCount) { ensureDataIsValid(); if (deliveryCount > 1) { return createCopyWithNewDeliveryCount(deliveryCount); } else if (deliveryAnnotationsPosition != VALUE_NOT_PRESENT || (deliveryAnnotationsForSendBuffer != null && !deliveryAnnotationsForSendBuffer.getValue().isEmpty())) { return createCopyWithSkippedOrExplicitlySetDeliveryAnnotations(); } else { // Common case message has no delivery annotations, no delivery annotations for the send buffer were set // and this is the first delivery so no re-encoding or section skipping needed. return data.duplicate(); } }
/** * Gets a ByteBuf from the Message that contains the encoded bytes to be sent on the wire. * <p> * When possible this method will present the bytes to the caller without copying them into * another buffer copy. If copying is needed a new Netty buffer is created and returned. The * caller should ensure that the reference count on the returned buffer is always decremented * to avoid a leak in the case of a copied buffer being returned. * * @param deliveryCount * The new delivery count for this message. * * @return a Netty ByteBuf containing the encoded bytes of this Message instance. */ public ReadableBuffer getSendBuffer(int deliveryCount) { checkBuffer(); if (deliveryCount > 1) { return createCopyWithNewDeliveryCount(deliveryCount); } else if (headerEnds != messagePaylodStart) { return createCopyWithoutDeliveryAnnotations(); } else { // Common case message has no delivery annotations and this is the first delivery // so no re-encoding or section skipping needed. return data.duplicate(); } }