packer-ng-plugin
packer-ng-plugin copied to clipboard
关于wrapPayload的一个小问题
static ByteBuffer wrapPayload(byte[] payload) throws UnsupportedEncodingException { /* PLUGIN BLOCK LAYOUT OFFSET DATA TYPE DESCRIPTION @+0 magic string magic string 16 bytes @+16 payload length payload length int 4 bytes @+20 payload payload data bytes @-4 payload length same as @+16 4 bytes */ byte[] magic = BLOCK_MAGIC.getBytes(UTF8); int magicLen = magic.length; int payloadLen = payload.length; int length = (magicLen + 4) * 2 + payloadLen;//这里是不是多申请了16位的大小 ByteBuffer buffer = ByteBuffer.allocate(length); buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.put(magic); //16 buffer.putInt(payloadLen); //4 payload length buffer.put(payload); // payload buffer.putInt(payloadLen); // 4 buffer.flip(); return buffer; } int length = (magicLen + 4) * 2 + payloadLen; 这里应该是吧 int length = magicLen + 4 * 2 + payloadLen; 另外请教一下加上这样一个Magic是出于什么目的