List of usage examples for io.netty.buffer ByteBuf readUnsignedInt
public abstract long readUnsignedInt();
From source file:com.tesora.dve.mysqlapi.repl.messages.MyComBinLogDumpRequest.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { binlogPosition = cb.readUnsignedInt(); cb.skipBytes(2);//from ww w. j a v a 2 s . c o m slaveServerID = cb.readInt(); if (cb.readableBytes() > 0) { binlogFileName = cb.readSlice(cb.readableBytes()).toString(CharsetUtil.UTF_8); } }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyFormatDescriptionLogEvent.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { binaryLogVersion = cb.readShort();// ww w .j a v a 2 s . c o m serverVersion = MysqlAPIUtils.readBytesAsString(cb, ST_SERVER_VER_LEN, CharsetUtil.UTF_8); createTime = cb.readUnsignedInt(); eventTypeLength = cb.readUnsignedByte(); int numberOfEntries = cb.readableBytes() - 1;//string is null terminated. switch (MyBinLogVerType.fromByte((byte) binaryLogVersion)) { case MySQL_5_0: for (int i = 1; i <= numberOfEntries; i++) { eventTypeValues.put(MyLogEventType.fromByte((byte) i), cb.readByte()); } cb.skipBytes(1);//throw out EOF break; default: // TODO throw???? logger.error("Cannot process binary log messages that are not for MySQL 5.0"); } }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyQueryLogEvent.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) throws PEException { // read event header slaveProxyId = cb.readUnsignedInt(); execTime = cb.readUnsignedInt();/*from www . j a v a 2 s . co m*/ dbNameLen = cb.readByte(); errorCode = cb.readUnsignedShort(); statusVarsLen = cb.readUnsignedShort(); statusVars.parseStatusVariables(cb, statusVarsLen); dbName = MysqlAPIUtils.readBytesAsString(cb, dbNameLen, CharsetUtil.UTF_8); cb.skipBytes(1); //for trailing 0 query = Unpooled.buffer(cb.readableBytes()); query.writeBytes(cb); origQuery = query.toString(CharsetUtil.UTF_8); }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyReplEvent.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) throws PEException { //assumes the provided buffer is already scoped to payload boundary. rawPayload = cb.slice().copy();//from www.java 2 s. c o m // 19 bytes for the common header commonHdr = new MyReplEventCommonHeader(); commonHdr.setTimestamp(cb.readUnsignedInt()); commonHdr.setType(cb.readByte()); commonHdr.setServerId(cb.readUnsignedInt()); commonHdr.setTotalSize(cb.readUnsignedInt()); commonHdr.setMasterLogPosition(cb.readUnsignedInt()); commonHdr.setFlags(cb.readShort()); // unmarshall message based on common header type if (logger.isDebugEnabled()) logger.debug("Unmarshalling event of type: " + MyLogEventType.fromByte(commonHdr.getType()).name()); levp = MyLogEventPacket.MySqlLogEventFactory.newInstance(MyLogEventType.fromByte(commonHdr.getType()), commonHdr); levp.unmarshallMessage(cb); }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyUserVarLogEvent.java
License:Open Source License
long readValue(ByteBuf decimalPortionBuf, int valueLen) throws PEException { if (valueLen < 1 || valueLen > 4) throw new PEException("Cannot decode decimal buffer. Invalid read length of " + valueLen); long value = 0; if (valueLen == 4) { value = decimalPortionBuf.readUnsignedInt(); } else if (valueLen == 3) { value = decimalPortionBuf.readUnsignedMedium(); } else if (valueLen == 2) { value = decimalPortionBuf.readUnsignedShort(); } else if (valueLen == 1) { value = decimalPortionBuf.readUnsignedByte(); }/* ww w . j av a2 s. c o m*/ return value; }
From source file:com.uber.tchannel.codecs.TFrameCodec.java
License:Open Source License
public static TFrame decode(ByteBuf buffer) { // size:2/* w w w.ja va2s . c om*/ int size = buffer.readUnsignedShort() - TFrame.FRAME_HEADER_LENGTH; // type:1 byte type = buffer.readByte(); // reserved:1 buffer.skipBytes(1); // id:4 long id = buffer.readUnsignedInt(); // reserved:8 buffer.skipBytes(8); // payload:16+ ByteBuf payload = buffer.readSlice(size); // payload.retain(); return new TFrame(size, type, id, payload); }
From source file:com.vethrfolnir.encdec.ReadDataFiles.java
License:Open Source License
public static long[] readFile(URL url) { ByteBuf buff = Unpooled.buffer().order(ByteOrder.LITTLE_ENDIAN); try (DataInputStream is = new DataInputStream(url.openStream())) { buff.writeBytes(is, is.available()); } catch (Exception e) { throw new RuntimeException(e); }/*from www. j av a2 s . c o m*/ int bits2 = buff.readUnsignedShort(); System.out.println("First two bits: " + bits2 + " hex: 0x" + PrintData.fillHex(bits2, 2)); long[] out_dat = new long[12]; buff.readerIndex(6); int pointer = 0; for (int i = 0; i < 3; i++) { long[] buf = new long[4]; for (int j = 0; j < 4; j++) { buf[j] = buff.readUnsignedInt(); } out_dat[pointer++] = buf[0] ^ (xor_tab_datfile[0]); out_dat[pointer++] = buf[1] ^ (xor_tab_datfile[1] & 0xFFFFFFFFL); out_dat[pointer++] = buf[2] ^ (xor_tab_datfile[2] & 0xFFFFFFFFL); out_dat[pointer++] = buf[3] ^ (xor_tab_datfile[3]); } for (int i = 0; i < out_dat.length; i++) { System.out.print(" " + (out_dat[i])); } System.out.println(); return null; }
From source file:com.vethrfolnir.game.network.mu.crypt.MuKeyFactory.java
License:Open Source License
private static void readFile(String path, long[] out_dat) { AssetManager assetManager = Corax.fetch(AssetManager.class); ByteBuf buff = Unpooled.buffer().order(ByteOrder.LITTLE_ENDIAN); try (InputStream is = assetManager.loadAsset(FileKey.class, path)) { buff.writeBytes(is, is.available()); } catch (IOException e) { e.printStackTrace();/*from w w w .j a va 2 s .co m*/ } buff.readerIndex(6); int pointer = 0; for (int i = 0; i < 3; i++) { long[] buf = new long[4]; for (int j = 0; j < 4; j++) { buf[j] = buff.readUnsignedInt(); } out_dat[pointer++] = buf[0] ^ (xor_tab_datfile[0]); out_dat[pointer++] = buf[1] ^ (xor_tab_datfile[1] & 0xFFFFFFFFL); out_dat[pointer++] = buf[2] ^ (xor_tab_datfile[2] & 0xFFFFFFFFL); out_dat[pointer++] = buf[3] ^ (xor_tab_datfile[3]); } }
From source file:com.yahoo.pulsar.client.impl.ProducerImpl.java
License:Apache License
/** * Computes checksum again and verifies it against existing checksum. If checksum doesn't match it means that * message is corrupt.// w w w . ja v a 2 s . c om * * @param op * @return returns true only if message is not modified and computed-checksum is same as previous checksum else * return false that means that message is corrupted. Returns true if checksum is not present. */ protected boolean verifyLocalBufferIsNotCorrupted(OpSendMsg op) { DoubleByteBuf msg = getDoubleByteBuf(op.cmd); if (msg != null) { ByteBuf headerFrame = msg.getFirst(); msg.markReaderIndex(); headerFrame.markReaderIndex(); try { // skip bytes up to checksum index headerFrame.skipBytes(4); // skip [total-size] int cmdSize = (int) headerFrame.readUnsignedInt(); headerFrame.skipBytes(cmdSize); // verify if checksum present if (hasChecksum(headerFrame)) { int checksum = readChecksum(headerFrame).intValue(); // msg.readerIndex is already at header-payload index, Recompute checksum for headers-payload int metadataChecksum = computeChecksum(headerFrame); long computedChecksum = resumeChecksum(metadataChecksum, msg.getSecond()); return checksum == computedChecksum; } else { log.warn("[{}] [{}] checksum is not present into message with id {}", topic, producerName, op.sequenceId); } } finally { headerFrame.resetReaderIndex(); msg.resetReaderIndex(); } return true; } else { log.warn("[{}] Failed while casting {} into DoubleByteBuf", producerName, op.cmd.getClass().getName()); return false; } }
From source file:com.yahoo.pulsar.client.impl.ProducerImpl.java
License:Apache License
/** * Strips checksum from {@link OpSendMsg} command if present else ignore it. * /*ww w .j a v a 2 s. c om*/ * @param op */ private void stripChecksum(OpSendMsg op) { op.cmd.markReaderIndex(); int totalMsgBufSize = op.cmd.readableBytes(); DoubleByteBuf msg = getDoubleByteBuf(op.cmd); if (msg != null) { ByteBuf headerFrame = msg.getFirst(); msg.markReaderIndex(); headerFrame.markReaderIndex(); try { headerFrame.skipBytes(4); // skip [total-size] int cmdSize = (int) headerFrame.readUnsignedInt(); // verify if checksum present headerFrame.skipBytes(cmdSize); if (!hasChecksum(headerFrame)) { headerFrame.resetReaderIndex(); return; } int headerSize = 4 + 4 + cmdSize; // [total-size] [cmd-length] [cmd-size] int checksumSize = 4 + 2; // [magic-number] [checksum-size] int checksumMark = (headerSize + checksumSize); // [header-size] [checksum-size] int metaPayloadSize = (totalMsgBufSize - checksumMark); // metadataPayload = totalSize - checksumMark int newTotalFrameSizeLength = 4 + cmdSize + metaPayloadSize; // new total-size without checksum headerFrame.resetReaderIndex(); int headerFrameSize = headerFrame.readableBytes(); headerFrame.setInt(0, newTotalFrameSizeLength); // rewrite new [total-size] ByteBuf metadata = headerFrame.slice(checksumMark, headerFrameSize - checksumMark); // sliced only // metadata headerFrame.writerIndex(headerSize); // set headerFrame write-index to overwrite metadata over checksum metadata.readBytes(headerFrame, metadata.readableBytes()); headerFrame.capacity(headerFrameSize - checksumSize); // reduce capacity by removed checksum bytes headerFrame.resetReaderIndex(); } finally { op.cmd.resetReaderIndex(); } } else { log.warn("[{}] Failed while casting {} into DoubleByteBuf", producerName, op.cmd.getClass().getName()); } }