Source:
<code>protected void encode(final ChannelHandlerContext context, final SendableApnsPushNotification<T> sendablePushNotification, final ByteBuf out) throws Exception { out.writeByte(BINARY_PUSH_NOTIFICATION_COMMAND); <START> out.writeInt(this.getFrameLength(sendablePushNotification)); <END> out.writeByte(ApnsFrameItem.SEQUENCE_NUMBER.getCode()); out.writeShort(SEQUENCE_NUMBER_SIZE); out.writeInt(sendablePushNotification.getSequenceNumber()); out.writeByte(ApnsFrameItem.DEVICE_TOKEN.getCode()); out.writeShort(sendablePushNotification.getPushNotification().getToken().length); out.writeBytes(sendablePushNotification.getPushNotification().getToken()); final byte[] payloadBytes = sendablePushNotification.getPushNotification().getPayload().getBytes(utf8); out.writeByte(ApnsFrameItem.PAYLOAD.getCode()); out.writeShort(payloadBytes.length); out.writeBytes(payloadBytes); out.writeByte(ApnsFrameItem.EXPIRATION.getCode()); out.writeShort(EXPIRATION_SIZE); final int expiration; if (sendablePushNotification.getPushNotification().getDeliveryInvalidationTime() != null) { expiration = this.getTimestampInSeconds( sendablePushNotification.getPushNotification().getDeliveryInvalidationTime()); } else { expiration = EXPIRE_IMMEDIATELY; } out.writeInt(expiration); final DeliveryPriority priority = sendablePushNotification.getPushNotification().getPriority() != null ? sendablePushNotification.getPushNotification().getPriority() : DeliveryPriority.IMMEDIATE; out.writeByte(ApnsFrameItem.PRIORITY.getCode()); out.writeShort(PRIORITY_SIZE); out.writeByte(priority.getCode()); }</code><technical_language>encoded length first, actual encoding. sense encode a byte array, get length, write out</technical_language>

Target:
protected void encode(final ChannelHandlerContext context, final SendableApnsPushNotification<T> sendablePushNotification, final ByteBuf out) throws Exception { out.writeByte(BINARY_PUSH_NOTIFICATION_COMMAND); out.writeInt(this.getFrameLength(sendablePushNotification)); out.writeByte(ApnsFrameItem.SEQUENCE_NUMBER.getCode()); out.writeShort(SEQUENCE_NUMBER_SIZE); out.writeInt(sendablePushNotification.getSequenceNumber()); out.writeByte(ApnsFrameItem.DEVICE_TOKEN.getCode()); out.writeShort(sendablePushNotification.getPushNotification().getToken().length); out.writeBytes(sendablePushNotification.getPushNotification().getToken()); final byte[] payloadBytes = sendablePushNotification.getPushNotification().getPayload().getBytes(utf8); out.writeByte(ApnsFrameItem.PAYLOAD.getCode()); out.writeShort(payloadBytes.length); out.writeBytes(payloadBytes); out.writeByte(ApnsFrameItem.DELIVERY_INVALIDATION_TIME.getCode()); out.writeShort(DELIVERY_INVALIDATION_TIME_SIZE); final int deliveryInvalidationTime; if (sendablePushNotification.getPushNotification().getDeliveryInvalidationTime() != null) { deliveryInvalidationTime = this.getTimestampInSeconds( sendablePushNotification.getPushNotification().getDeliveryInvalidationTime()); } else { deliveryInvalidationTime = INVALIDATE_IMMEDIATELY; } out.writeInt(deliveryInvalidationTime); final DeliveryPriority priority = sendablePushNotification.getPushNotification().getPriority() != null ? sendablePushNotification.getPushNotification().getPriority() : DeliveryPriority.IMMEDIATE; out.writeByte(ApnsFrameItem.PRIORITY.getCode()); out.writeShort(PRIORITY_SIZE); out.writeByte(priority.getCode()); }