@Override public ByteBuffer getPacket() { // int size = 100; ByteBuffer response = ByteBuffer.allocate(106); // response.put((byte)0x84); // response.put(Hex.intToBytes(player.getPacketCount(), 3),0,3); response.put((byte) 0x60); // Encapsulation ID response.put((byte) 0x03); response.put((byte) 0x00); // size of packet response.put(Hex.intToBytes(player.getDataCount(), 3), 0, 3); response.put((byte) 0x00); // MinecrafPE ID response.putInt(16); response.put((byte) 0x04); response.put((byte) 0x3f); response.put((byte) 0x57); response.put((byte) 0xfe); response.put((byte) 0xcd); response.putShort((short) player.clientPort); for (int i = 0; i < 10; i++) { response.put(Hex.intToBytes(4, 3)); response.putInt(0xffffffff); } response.putShort((short) 0); response.putLong(unknown1); response.putLong(1L); return response; }
/** * Remove all the local of a context (but keep global). * * @param context a counter context * @return a version of {@code context} where no shards are local. */ public ByteBuffer clearAllLocal(ByteBuffer context) { int count = Math.abs(context.getShort(context.position())); if (count == 0) return context; // no local or global shards present. List<Short> globalShardIndexes = new ArrayList<>(count); for (int i = 0; i < count; i++) { short elt = context.getShort(context.position() + HEADER_SIZE_LENGTH + i * HEADER_ELT_LENGTH); if (elt < 0) globalShardIndexes.add(elt); } if (count == globalShardIndexes.size()) return context; // no local shards detected. // allocate a smaller BB for the cleared context - with no local header elts. ByteBuffer cleared = ByteBuffer.allocate( context.remaining() - (count - globalShardIndexes.size()) * HEADER_ELT_LENGTH); cleared.putShort(cleared.position(), (short) globalShardIndexes.size()); for (int i = 0; i < globalShardIndexes.size(); i++) cleared.putShort( cleared.position() + HEADER_SIZE_LENGTH + i * HEADER_ELT_LENGTH, globalShardIndexes.get(i)); int origHeaderLength = headerLength(context); ByteBufferUtil.arrayCopy( context, context.position() + origHeaderLength, cleared, cleared.position() + headerLength(cleared), context.remaining() - origHeaderLength); return cleared; }
private void encodeCommand(@Nonnull AbstractCommand cmd) throws IOException { if (cmd.getId() != CommandList.CMD_KEEPALIVE) { log.debug("SND: {}", cmd); } buffer.clear(); buffer.put((byte) cmd.getId()); buffer.put((byte) (cmd.getId() ^ COMMAND_XOR_MASK)); // keep some space for the length and the CRC int headerLenCRC = buffer.position(); buffer.putShort((short) 0); buffer.putShort((short) 0); int startOfCmd = buffer.position(); // encode command into net protocol cmd.encode(this); int length = buffer.position() - startOfCmd; buffer.flip(); buffer.position(startOfCmd); int crc = NetComm.getCRC(buffer, length); buffer.position(headerLenCRC); buffer.putShort((short) length); buffer.putShort((short) crc); buffer.position(0); if (NetComm.isDumpingActive()) { NetComm.dump("snd => ", buffer); buffer.flip(); } outChannel.write(buffer); }
@Override public void getBox(WritableByteChannel writableByteChannel) throws IOException { writableByteChannel.write(getHeader()); ByteBuffer byteBuffer = ByteBuffer.allocate(52 + (fontName != null ? fontName.length() : 0)); byteBuffer.position(6); IsoTypeWriter.writeUInt16(byteBuffer, dataReferenceIndex); byteBuffer.putInt(displayFlags); byteBuffer.putInt(textJustification); IsoTypeWriter.writeUInt16(byteBuffer, backgroundR); IsoTypeWriter.writeUInt16(byteBuffer, backgroundG); IsoTypeWriter.writeUInt16(byteBuffer, backgroundB); IsoTypeWriter.writeUInt64(byteBuffer, defaultTextBox); IsoTypeWriter.writeUInt64(byteBuffer, reserved1); byteBuffer.putShort(fontNumber); byteBuffer.putShort(fontFace); byteBuffer.put(reserved2); byteBuffer.putShort(reserved3); IsoTypeWriter.writeUInt16(byteBuffer, foregroundR); IsoTypeWriter.writeUInt16(byteBuffer, foregroundG); IsoTypeWriter.writeUInt16(byteBuffer, foregroundB); if (fontName != null) { IsoTypeWriter.writeUInt8(byteBuffer, fontName.length()); byteBuffer.put(fontName.getBytes()); } writableByteChannel.write((ByteBuffer) byteBuffer.rewind()); // writeContainer(writableByteChannel); there are no child boxes!? }
@Override public boolean serialize(final ByteBuffer buffer) { if (this.contents.size() > 65535) { return false; } buffer.putShort((short) this.contents.size()); for (int i = 0; i < this.contents.size(); ++i) { final Content contents_element = this.contents.get(i); final boolean contents_element_ok = contents_element.serialize(buffer); if (!contents_element_ok) { return false; } } if (this.contentsSelection != null) { buffer.put((byte) 1); final boolean contentsSelection_ok = this.contentsSelection.serialize(buffer); if (!contentsSelection_ok) { return false; } } else { buffer.put((byte) 0); } if (this.buyableContents.size() > 65535) { return false; } buffer.putShort((short) this.buyableContents.size()); for (int i = 0; i < this.buyableContents.size(); ++i) { final BuyableContent buyableContents_element = this.buyableContents.get(i); final boolean buyableContents_element_ok = buyableContents_element.serialize(buffer); if (!buyableContents_element_ok) { return false; } } return true; }
public boolean serialize(ByteBuffer buffer) { try { buffer.put(unknown8); buffer.put(unknown9); buffer.put(unknown10); buffer.put(unknown11); buffer.put(unknown12); buffer.put(unknown13); buffer.put(unknown14); buffer.putShort(unknown15); buffer.put(unknown16); short prefix_unknown17; if (unknown17 == null) { prefix_unknown17 = 0; } else { prefix_unknown17 = (short) unknown17.length; } buffer.putShort(prefix_unknown17); for (int i = 0; i < prefix_unknown17; i++) { buffer.putChar(unknown17[i]); } } catch (BufferOverflowException e) { return false; } return true; }
// get the object as a byte array public synchronized byte[] getAsByteArray() { ByteBuffer buffer = ByteBuffer.allocate(packet_size); buffer.order(Constants.NETWORK_BYTEORDER); buffer.put(Constants.STRUCT_HEADER.getBytes(), 0, 4); buffer.putInt(Constants.STRUCT_VERSION); buffer.put(numPlayers); buffer.put(gameState); buffer.put(firstHalf); buffer.put(kickOffTeam); buffer.put(secGameState); buffer.put(dropInTeam); buffer.putShort(dropInTime); buffer.putInt(estimatedSecs); for (byte team = 0; team < Constants.NUM_TEAMS; team++) { buffer.put(getTeamNumber(team)); buffer.put(team); buffer.put(getGoalColour(team)); buffer.put(getScore(team)); for (byte i = 0; i < Constants.MAX_NUM_PLAYERS; i++) { RobotInfo robot = teams[team].getPlayer(i); buffer.putShort(robot.getPenalty()); buffer.putShort(robot.getSecsTillUnpenalised()); } } return buffer.array(); }
private void saveToFile(BlockLink[] links) { log.info("Saving matches to: " + fileName); try { File f = new File(fileName); if (f.exists()) { f.delete(); } FileChannel wChannel = new RandomAccessFile(f, "rw").getChannel(); ByteBuffer buffer = wChannel.map(FileChannel.MapMode.READ_WRITE, 0, links.length * 6 + 1); buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.put(version); for (BlockLink link : links) { buffer.putShort((short) link.blockIndex); buffer.put(link.linkMapX); buffer.put(link.linkMapY); buffer.putShort((short) link.linkBlockIndex); } wChannel.close(); } catch (Exception e) { e.printStackTrace(); } }
private void sendCloseMessage(CloseReason closeReason) { // 125 is maximum size for the payload of a control message ByteBuffer msg = ByteBuffer.allocate(125); CloseCode closeCode = closeReason.getCloseCode(); // CLOSED_ABNORMALLY should not be put on the wire if (closeCode == CloseCodes.CLOSED_ABNORMALLY) { // PROTOCOL_ERROR is probably better than GOING_AWAY here msg.putShort((short) CloseCodes.PROTOCOL_ERROR.getCode()); } else { msg.putShort((short) closeCode.getCode()); } String reason = closeReason.getReasonPhrase(); if (reason != null && reason.length() > 0) { appendCloseReasonWithTruncation(msg, reason); } msg.flip(); try { wsRemoteEndpoint.startMessageBlock(Constants.OPCODE_CLOSE, msg, true); } catch (IOException ioe) { // Failed to send close message. Close the socket and let the caller // deal with the Exception WebsocketsLogger.ROOT_LOGGER.closeMessageFail(ioe); wsRemoteEndpoint.close(); // Failure to send a close message is not unexpected in the case of // an abnormal closure (usually triggered by a failure to read/write // from/to the client. In this case do not trigger the endpoint's // error handling if (closeCode != CloseCodes.CLOSED_ABNORMALLY) { localEndpoint.onError(this, ioe); } } finally { webSocketContainer.unregisterSession(localEndpoint, this); } }
@Override public boolean serialize() { int size = getSize(); if (size == 0) { return false; } ByteBuffer buffer = ByteBuffer.allocate(size).order(ByteOrder.LITTLE_ENDIAN); try { buffer.putShort(getHeader()); buffer.putShort(localID); for (int i = 0; i < 16; i++) { buffer.put(guildHallData[i]); } buffer.put(type); buffer.putInt(joinDate); } catch (BufferOverflowException e) { return false; } setBuffer(buffer); return true; }
/** Preps the send buffer for next transmission */ public void prepSendBuffer() { // sendBuffer.rewind(); // Put the protocol ID and the localSequence sendBuffer.put(protocol); sendBuffer.putShort(localSequence); // Put analog values sendBuffer.putShort(controller.analogState.get(0)); sendBuffer.putShort(controller.analogState.get(1)); sendBuffer.putShort(controller.analogState.get(2)); sendBuffer.putShort(controller.analogState.get(3)); // Build first byte and put byte firstByte = 0; for (int n = 0; n < 7; n++, firstByte <<= 1) if (controller.buttonState.get(n)) firstByte |= 1; if (controller.buttonState.get(7)) firstByte |= 1; sendBuffer.put(firstByte); // Build second byte and put byte secondByte = 0; for (int n = 8; n < 15; n++, secondByte <<= 1) if (controller.buttonState.get(n)) secondByte |= 1; if (controller.buttonState.get(15)) secondByte |= 1; sendBuffer.put(secondByte); // Put the extra button (not implemented in touch yet) // sendBuffer.put((byte) (controller.buttons.get(16) ? 1 : 0)); sendBuffer.rewind(); }
@Override public ByteBuffer processBinaryStorageCommand( Object key, byte[] value, long cas, int flags, Cache cache, RequestReader request) { ByteBuffer response = request.getResponse(); Region<Object, ValueWrapper> r = getMemcachedRegion(cache); ValueWrapper val = ValueWrapper.getWrappedValue(value, flags); try { Object oldVal = r.putIfAbsent(key, val); // set status if (oldVal == null) { if (getLogger().fineEnabled()) { getLogger().fine("added key: " + key); } if (isQuiet()) { return null; } response.putShort(POSITION_RESPONSE_STATUS, ResponseStatus.NO_ERROR.asShort()); // set cas response.putLong(POSITION_CAS, val.getVersion()); } else { if (getLogger().fineEnabled()) { getLogger().fine("key: " + key + " not added as is already exists"); } response.putShort(POSITION_RESPONSE_STATUS, ResponseStatus.KEY_EXISTS.asShort()); } } catch (Exception e) { response = handleBinaryException(key, request, response, "add", e); } return response; }
public void serialize(final ByteBuffer buffer) { buffer.putShort(this.m_definition.getInstanceId()); buffer.putShort((short) this.m_results.size()); for (int i = 0; i < this.m_results.size(); ++i) { this.m_results.get(i).serialize(buffer); } }
@Override public boolean serialize() { int size = getSize(); if (size == 0) { return false; } ByteBuffer buffer = ByteBuffer.allocate(size).order(ByteOrder.LITTLE_ENDIAN); try { buffer.putShort(getHeader()); buffer.putInt(unknown1); buffer.putFloat(unknown2[0]); buffer.putFloat(unknown2[1]); buffer.putShort(unknown3); } catch (BufferOverflowException e) { return false; } setBuffer(buffer); return true; }
/** Encode message with raw data and other informations */ public byte[] encode() throws IOException { byte[] buffer = new byte[8 + 26]; ByteBuffer dos = ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN); dos.put((byte) 0xFE); dos.put((byte) (length & 0x00FF)); dos.put((byte) (sequence & 0x00FF)); dos.put((byte) (sysId & 0x00FF)); dos.put((byte) (componentId & 0x00FF)); dos.put((byte) (messageType & 0x00FF)); dos.putFloat(nav_roll); dos.putFloat(nav_pitch); dos.putFloat(alt_error); dos.putFloat(aspd_error); dos.putFloat(xtrack_error); dos.putShort((short) (nav_bearing & 0x00FFFF)); dos.putShort((short) (target_bearing & 0x00FFFF)); dos.putShort((short) (wp_dist & 0x00FFFF)); int crc = MAVLinkCRC.crc_calculate_encode(buffer, 26); crc = MAVLinkCRC.crc_accumulate((byte) IMAVLinkCRC.MAVLINK_MESSAGE_CRCS[messageType], crc); byte crcl = (byte) (crc & 0x00FF); byte crch = (byte) ((crc >> 8) & 0x00FF); buffer[32] = crcl; buffer[33] = crch; return buffer; }
@Override public boolean serialize() { int size = getSize(); if (size == 0) { return false; } ByteBuffer buffer = ByteBuffer.allocate(size).order(ByteOrder.LITTLE_ENDIAN); try { buffer.putShort(getHeader()); short prefix_unknown1; if (unknown1 == null) { prefix_unknown1 = 0; } else { prefix_unknown1 = (short) unknown1.length; } buffer.putShort(prefix_unknown1); for (int i = 0; i < prefix_unknown1; i++) { buffer.putChar(unknown1[i]); } } catch (BufferOverflowException e) { return false; } setBuffer(buffer); return true; }
/** get the data in this map as a ByteBuffer */ public ByteBuffer getData() { int size = getLength(); ByteBuffer buf = ByteBuffer.allocate(size); // write the header buf.putInt(getFormat()); buf.putInt(getItalicAngle()); buf.putShort(getUnderlinePosition()); buf.putShort(getUnderlineThickness()); buf.putShort(getIsFixedPitch()); buf.putShort((short) 0); buf.putInt(getMinMemType42()); buf.putInt(getMaxMemType42()); buf.putInt(getMinMemType1()); buf.putInt(getMaxMemType1()); // now write the table buf.put(nameMap.getData()); // reset the start pointer buf.flip(); return buf; }
/** * ackPacket * * <p>Constructs an ack packet for the given block number. * * @param block * @return ackPacket */ private DatagramPacket ackPacket(short block) { ByteBuffer buffer = ByteBuffer.allocate(BUFSIZE); buffer.putShort(OP_ACK); buffer.putShort(block); return new DatagramPacket(buffer.array(), 4); } // ackPacket
/** * Appends a zip64 extended info record to the extras contained in {@code ze}. If {@code ze} * contains no extras, a new extras array is created. */ public static void insertZip64ExtendedInfoToExtras(ZipEntry ze) throws ZipException { final byte[] output; // We always write the size, uncompressed size and local rel header offset in all our // Zip64 extended info headers (in both the local file header as well as the central // directory). We always omit the disk number because we don't support spanned // archives anyway. // // 2 bytes : Zip64 Extended Info Header ID // 2 bytes : Zip64 Extended Info Field Size. // 8 bytes : Uncompressed size // 8 bytes : Compressed size // 8 bytes : Local header rel offset. // ---------- // 28 bytes : total final int extendedInfoSize = 28; if (ze.extra == null) { output = new byte[extendedInfoSize]; } else { // If the existing extras are already too big, we have no choice but to throw // an error. if (ze.extra.length + extendedInfoSize > 65535) { throw new ZipException("No space in extras for zip64 extended entry info"); } // We copy existing extras over and put the zip64 extended info at the beginning. This // is to avoid breakages in the presence of "old style" extras which don't contain // headers and lengths. The spec is again silent about these inconsistencies. // // This means that people that for ZipOutputStream users, the value ZipEntry.getExtra // after an entry is written will be different from before. This shouldn't be an issue // in practice. output = new byte[ze.extra.length + extendedInfoSize]; System.arraycopy(ze.extra, 0, output, extendedInfoSize, ze.extra.length); } ByteBuffer bb = ByteBuffer.wrap(output).order(ByteOrder.LITTLE_ENDIAN); bb.putShort(ZIP64_EXTENDED_INFO_HEADER_ID); // We subtract four because extendedInfoSize includes the ID and field // size itself. bb.putShort((short) (extendedInfoSize - 4)); if (ze.getMethod() == ZipEntry.STORED) { bb.putLong(ze.size); bb.putLong(ze.compressedSize); } else { // Store these fields in the data descriptor instead. bb.putLong(0); // size. bb.putLong(0); // compressed size. } // The offset is only relevant in the central directory entry, but we write it out here // anyway, since we know what it is. bb.putLong(ze.localHeaderRelOffset); ze.extra = output; }
/** * dataPacket * * <p>Constructs an OP_DAT packet * * @param block current block number * @param data data to be sent * @param length lengh of data * @return DatagramPacket to be sent */ private DatagramPacket dataPacket(short block, byte[] data, int length) { ByteBuffer buffer = ByteBuffer.allocate(BUFSIZE); buffer.putShort(OP_DAT); buffer.putShort(block); buffer.put(data, 0, length); return new DatagramPacket(buffer.array(), 4 + length); } // dataPacket
@Override public void doWrite(ByteBuffer out) { out.put(asciiString(type)); out.putShort(primariesIndex); out.putShort(transferFunctionIndex); out.putShort(matrixIndex); if (colorRange != null) { out.put(colorRange); } }
@Override protected void getContent(ByteBuffer byteBuffer) { writeVersionAndFlags(byteBuffer); byteBuffer.putShort(graphicsMode); IsoTypeWriter.writeUInt16(byteBuffer, opColorR); IsoTypeWriter.writeUInt16(byteBuffer, opColorG); IsoTypeWriter.writeUInt16(byteBuffer, opColorB); byteBuffer.putShort(balance); byteBuffer.putShort(reserved); }
@Override public void putInPhysicalBuffer( ByteBuffer vertexBuffer, ByteBuffer indexBuffer, Vec3f pos, int faceMask) { float x = pos.x; float y = pos.y; float z = pos.z; for (int i = 0, bit = 1; i < 6; ++i, bit <<= 1) { if ((bit & faceMask) == bit) { Side side = Side.values()[i]; int s = vertexBuffer.position() / 12; float inset = getInset(side); if (side == Side.TOP) { put3f(vertexBuffer, x - 0.5f, y + 0.5f - inset, z + 0.5f); put3f(vertexBuffer, x + 0.5f, y + 0.5f - inset, z + 0.5f); put3f(vertexBuffer, x + 0.5f, y + 0.5f - inset, z - 0.5f); put3f(vertexBuffer, x - 0.5f, y + 0.5f - inset, z - 0.5f); } else if (side == Side.LEFT) { put3f(vertexBuffer, x - 0.5f + inset, y - 0.5f, z - 0.5f); put3f(vertexBuffer, x - 0.5f + inset, y - 0.5f, z + 0.5f); put3f(vertexBuffer, x - 0.5f + inset, y + 0.5f, z + 0.5f); put3f(vertexBuffer, x - 0.5f + inset, y + 0.5f, z - 0.5f); } else if (side == Side.FRONT) { put3f(vertexBuffer, x - 0.5f, y - 0.5f, z + 0.5f - inset); put3f(vertexBuffer, x + 0.5f, y - 0.5f, z + 0.5f - inset); put3f(vertexBuffer, x + 0.5f, y + 0.5f, z + 0.5f - inset); put3f(vertexBuffer, x - 0.5f, y + 0.5f, z + 0.5f - inset); } else if (side == Side.RIGHT) { put3f(vertexBuffer, x + 0.5f - inset, y + 0.5f, z - 0.5f); put3f(vertexBuffer, x + 0.5f - inset, y + 0.5f, z + 0.5f); put3f(vertexBuffer, x + 0.5f - inset, y - 0.5f, z + 0.5f); put3f(vertexBuffer, x + 0.5f - inset, y - 0.5f, z - 0.5f); } else if (side == Side.BACK) { put3f(vertexBuffer, x - 0.5f, y + 0.5f, z - 0.5f + inset); put3f(vertexBuffer, x + 0.5f, y + 0.5f, z - 0.5f + inset); put3f(vertexBuffer, x + 0.5f, y - 0.5f, z - 0.5f + inset); put3f(vertexBuffer, x - 0.5f, y - 0.5f, z - 0.5f + inset); } else if (side == Side.BOTTOM) { put3f(vertexBuffer, x - 0.5f, y - 0.5f + inset, z - 0.5f); put3f(vertexBuffer, x + 0.5f, y - 0.5f + inset, z - 0.5f); put3f(vertexBuffer, x + 0.5f, y - 0.5f + inset, z + 0.5f); put3f(vertexBuffer, x - 0.5f, y - 0.5f + inset, z + 0.5f); } indexBuffer.putShort((short) (s + 0)); indexBuffer.putShort((short) (s + 1)); indexBuffer.putShort((short) (s + 2)); indexBuffer.putShort((short) (s + 0)); indexBuffer.putShort((short) (s + 2)); indexBuffer.putShort((short) (s + 3)); } } }
/** * Encodes this sector into a {@link ByteBuffer}. * * @return The encoded buffer. */ public ByteBuffer encode() { ByteBuffer buf = ByteBuffer.allocate(SIZE); buf.putShort((short) id); buf.putShort((short) chunk); ByteBufferUtils.putTriByte(buf, nextSector); buf.put((byte) type); buf.put(data); return (ByteBuffer) buf.flip(); }
private static byte[] textToNumericFormatV6(String paramString) { String[] arrayOfString = paramString.split(":", 10); if ((arrayOfString.length < 3) || (arrayOfString.length > 9)) { return null; } int i = -1; for (int j = 1; j < arrayOfString.length - 1; j++) { if (arrayOfString[j].length() == 0) { if (i >= 0) { return null; } i = j; } } int k; if (i >= 0) { j = i; k = arrayOfString.length - i - 1; if (arrayOfString[0].length() == 0) { j--; if (j != 0) { return null; } } if (arrayOfString[(arrayOfString.length - 1)].length() == 0) { k--; if (k != 0) { return null; } } } else { j = arrayOfString.length; k = 0; } int m = 8 - (j + k); if (i >= 0 ? m < 1 : m != 0) { return null; } ByteBuffer localByteBuffer = ByteBuffer.allocate(16); try { for (int n = 0; n < j; n++) { localByteBuffer.putShort(parseHextet(arrayOfString[n])); } for (n = 0; n < m; n++) { localByteBuffer.putShort((short) 0); } for (n = k; n > 0; n--) { localByteBuffer.putShort(parseHextet(arrayOfString[(arrayOfString.length - n)])); } } catch (NumberFormatException localNumberFormatException) { return null; } return localByteBuffer.array(); }
/** * Packs a Pdu into the ByteBuffer. * * @throws java.nio.BufferOverflowException if buff is too small * @throws java.nio.ReadOnlyBufferException if buff is read only * @see java.nio.ByteBuffer * @param buff The ByteBuffer at the position to begin writing * @since ?? */ public void marshal(java.nio.ByteBuffer buff) { buff.put((byte) recordType); buff.put((byte) changeIndicator); buff.put((byte) associationStatus); buff.put((byte) associationType); entityID.marshal(buff); buff.putShort((short) ownStationLocation); buff.put((byte) physicalConnectionType); buff.put((byte) groupMemberType); buff.putShort((short) groupNumber); } // end of marshal method
/** * Prepare a send buffer. * * @param cmd the command identifier * @param key the key (for keyed ops) * @param val the data payload * @param extraHeaders any additional headers that need to be sent */ protected void prepareBuffer(String key, long cas, byte[] val, Object... extraHeaders) { int extraLen = 0; for (Object o : extraHeaders) { if (o instanceof Integer) { extraLen += 4; } else if (o instanceof byte[]) { extraLen += ((byte[]) o).length; } else if (o instanceof Long) { extraLen += 8; } else { assert false : "Unhandled extra header type: " + o.getClass(); } } final byte[] keyBytes = KeyUtil.getKeyBytes(key); int bufSize = MIN_RECV_PACKET + keyBytes.length + val.length; // # magic, opcode, keylen, extralen, datatype, [reserved], // bodylen, opaque, cas // REQ_PKT_FMT=">BBHBBxxIIQ" // set up the initial header stuff ByteBuffer bb = ByteBuffer.allocate(bufSize + extraLen); assert bb.order() == ByteOrder.BIG_ENDIAN; bb.put(REQ_MAGIC); bb.put((byte) cmd); bb.putShort((short) keyBytes.length); bb.put((byte) extraLen); bb.put((byte) 0); // data type bb.putShort((short) 0); // reserved bb.putInt(keyBytes.length + val.length + extraLen); bb.putInt(opaque); bb.putLong(cas); // Add the extra headers. for (Object o : extraHeaders) { if (o instanceof Integer) { bb.putInt((Integer) o); } else if (o instanceof byte[]) { bb.put((byte[]) o); } else if (o instanceof Long) { bb.putLong((Long) o); } else { assert false : "Unhandled extra header type: " + o.getClass(); } } // Add the normal stuff bb.put(keyBytes); bb.put(val); bb.flip(); setBuffer(bb); }
public boolean g(ByteBuffer paramByteBuffer) { if (this.gZr != null) { if (this.gZr.length > 65535) return false; paramByteBuffer.putShort((short) this.gZr.length); paramByteBuffer.put(this.gZr); } else { paramByteBuffer.putShort((short) 0); } paramByteBuffer.putInt(this.gZs); paramByteBuffer.putFloat(this.gZt); return true; }
public void writeTo(ByteBuffer data) { data.putInt(this.queueId); data.putInt(this.portNumber); data.putShort(this.length); data.putShort((short) 0); // pad data.putInt((int) 0); // pad if (this.properties != null) { for (OFQueueProperty queueProperty : this.properties) { queueProperty.writeTo(data); } } }
public byte[] toArray() { ByteBuffer bb = ByteBuffer.allocate(SIZE_WITHOUT_PAYLOAD + payload.length); bb.order(ByteOrder.LITTLE_ENDIAN); bb.put((byte) channel); bb.put((byte) BleTypes.RESERVED); bb.putShort((short) length); bb.put(target); bb.putShort((short) type); bb.put(payload); return bb.array(); }