List of usage examples for io.netty.buffer ByteBuf readLong
public abstract long readLong();
From source file:com.spotify.netty4.handler.codec.zmtp.ZMTP10WireFormat.java
License:Apache License
/** * Read a ZMTP/1.0 frame length.//from w w w . j a va 2s . c om */ static long readLength(final ByteBuf in) { if (in.readableBytes() < 1) { return -1; } long size = in.readByte() & 0xFF; if (size == 0xFF) { if (in.readableBytes() < 8) { return -1; } size = in.readLong(); } return size; }
From source file:com.srotya.sidewinder.core.ingress.binary.SeriesDataPointDecoder.java
License:Apache License
public static DataPoint decodeBufToDPoint(ByteBuf buf) { int dbNameLength = buf.readInt(); if (dbNameLength < 0) { return null; }/* w w w .j a v a 2 s . co m*/ byte[] dbBytes = new byte[dbNameLength]; buf.readBytes(dbBytes); String dbName = new String(dbBytes); int measurementNameLength = buf.readInt(); if (measurementNameLength < 0) { return null; } byte[] measurementNameBytes = new byte[measurementNameLength]; buf.readBytes(measurementNameBytes); String measurementName = new String(measurementNameBytes); int valueNameLength = buf.readInt(); if (valueNameLength < 0) { return null; } byte[] valueNameBytes = new byte[valueNameLength]; buf.readBytes(valueNameBytes); String valueFieldName = new String(valueNameBytes); long timestamp = buf.readLong(); byte flag = buf.readByte(); DataPoint dp; if (flag == '0') { double value = buf.readDouble(); dp = new DataPoint(dbName, measurementName, valueFieldName, null, timestamp, value); dp.setFp(true); } else { long value = buf.readLong(); dp = new DataPoint(dbName, measurementName, valueFieldName, null, timestamp, value); } return dp; }
From source file:com.teambr.bookshelf.network.ClientOverridePacket.java
License:Creative Commons License
/******************************************************************************************************************* * IMessage * *******************************************************************************************************************/ @Override/* w ww.j a v a 2 s . c o m*/ public void fromBytes(ByteBuf buf) { blockPosition = BlockPos.fromLong(buf.readLong()); try { tag = new PacketBuffer(buf).readCompoundTag(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.teambr.bookshelf.network.SyncableFieldPacket.java
License:Creative Commons License
/******************************************************************************************************************* * IMessage * *******************************************************************************************************************/ @Override//w w w .ja v a 2 s .co m public void fromBytes(ByteBuf buf) { returnValue = buf.readBoolean(); id = buf.readInt(); value = buf.readDouble(); blockPosition = BlockPos.fromLong(buf.readLong()); }
From source file:com.teambrmodding.neotech.network.OpenContainerGuiPacket.java
License:Creative Commons License
/******************************************************************************************************************* * IMessage * *******************************************************************************************************************/ @Override// w w w. j a v a 2 s . co m public void fromBytes(ByteBuf buf) { blockPos = BlockPos.fromLong(buf.readLong()); id = buf.readInt(); }
From source file:com.tesora.dve.db.mysql.common.MysqlAPIUtils.java
License:Open Source License
public static long getLengthCodedLong(ByteBuf cb) { short byte1 = cb.readUnsignedByte(); if (byte1 == LEN_CODED_NULL) return 0; if (byte1 <= LEN_CODED_8_BITS) { return byte1; } else if (byte1 == LEN_CODED_16_BITS) { return cb.readUnsignedShort(); } else if (byte1 == LEN_CODED_24_BITS) return cb.readUnsignedMedium(); return cb.readLong(); }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyIntvarLogEvent.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { variableType = cb.readByte(); variableValue = UnsignedLong.valueOf(cb.readLong()); }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyRandLogEvent.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { seed1 = UnsignedLong.valueOf(cb.readLong()); seed2 = UnsignedLong.valueOf(cb.readLong()); }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyRotateLogEvent.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { position = cb.readLong(); newLogFileName = cb.toString(CharsetUtil.UTF_8); cb.skipBytes(cb.readableBytes());//consume the rest of the buffer. }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyStatusVariables.java
License:Open Source License
public void parseStatusVariables(ByteBuf cb, int svLen) throws PEException { if (svLen > 0) { ByteBuf statsVarsBuf = cb.readBytes(svLen); while (statsVarsBuf.isReadable()) { byte code = statsVarsBuf.readByte(); MyQueryEventCode mqec = MyQueryEventCode.fromByte(code); if (mqec == null) { throw new PEException("Replication could not decode query event code: '" + code + "' (0x" + Integer.toHexString(code) + ")"); }// w w w. j a v a2s .c om switch (mqec) { case Q_FLAGS2_CODE: int flags = statsVarsBuf.readInt(); suppliedEventCodes.add(new QueryFlags2Event(flags)); break; case Q_SQL_MODE_CODE: long sqlMode = statsVarsBuf.readLong(); suppliedEventCodes.add(new QuerySQLModeEvent(sqlMode)); break; case Q_CATALOG_CODE: { byte len = statsVarsBuf.readByte(); String catalog = MysqlAPIUtils.readBytesAsString(statsVarsBuf, len, CharsetUtil.UTF_8); statsVarsBuf.readByte(); // null terminated byte suppliedEventCodes.add(new QueryCatalogEvent(catalog)); break; } case Q_AUTO_INCREMENT: int autoIncrementIncrement = statsVarsBuf.readUnsignedShort(); int autoIncrementOffset = statsVarsBuf.readUnsignedShort(); suppliedEventCodes .add(new QueryAutoIncrementEvent(autoIncrementIncrement, autoIncrementOffset)); break; case Q_CHARSET_CODE: int charSetClient = statsVarsBuf.readUnsignedShort(); int collationConnection = statsVarsBuf.readUnsignedShort(); int collationServer = statsVarsBuf.readUnsignedShort(); suppliedEventCodes .add(new QueryCharSetCodeEvent(charSetClient, collationConnection, collationServer)); break; case Q_TIME_ZONE_CODE: { byte len = statsVarsBuf.readByte(); String timeZone = MysqlAPIUtils.readBytesAsString(statsVarsBuf, len, CharsetUtil.UTF_8); suppliedEventCodes.add(new QueryTimeZoneCodeEvent(timeZone)); break; } case Q_CATALOG_NZ_CODE: { byte catalogLen = statsVarsBuf.readByte(); String catalog = MysqlAPIUtils.readBytesAsString(statsVarsBuf, catalogLen, CharsetUtil.UTF_8); suppliedEventCodes.add(new QueryCatalogNZEvent(catalog)); break; } case Q_LC_TIME_NAMES_CODE: short monthDayNames = statsVarsBuf.readShort(); suppliedEventCodes.add(new QueryTimeNamesEvent(monthDayNames)); break; case Q_CHARSET_DATABASE_CODE: short collationDatabase = statsVarsBuf.readShort(); suppliedEventCodes.add(new QueryCollationDatabaseEvent(collationDatabase)); break; case Q_TABLE_MAP_FOR_UPDATE_CODE: long tableMapForUpdate = statsVarsBuf.readLong(); suppliedEventCodes.add(new QueryTableMapEvent(tableMapForUpdate)); break; case Q_MASTER_DATA_WRITTEN_CODE: int originalLength = statsVarsBuf.readInt(); suppliedEventCodes.add(new QueryMasterDataWrittenEvent(originalLength)); break; case Q_INVOKER: int userLen = statsVarsBuf.readByte(); String user = MysqlAPIUtils.readBytesAsString(statsVarsBuf, userLen, CharsetUtil.UTF_8); int hostLen = statsVarsBuf.readByte(); String host = MysqlAPIUtils.readBytesAsString(statsVarsBuf, hostLen, CharsetUtil.UTF_8); suppliedEventCodes.add(new QueryInvokerEvent(user, host)); break; case Q_UPDATED_DB_NAMES: List<String> dbNames = new ArrayList<String>(); int numDbs = statsVarsBuf.readByte(); if (numDbs > 0) { for (int i = 0; i < numDbs; i++) { dbNames.add(statsVarsBuf.readSlice(statsVarsBuf.bytesBefore((byte) 0)) .toString(CharsetUtil.UTF_8)); statsVarsBuf.readByte(); //read null byte } } suppliedEventCodes.add(new QueryUpdatedDBNamesEvent(dbNames)); break; case Q_MICROSECONDS: int microseconds = statsVarsBuf.readMedium(); suppliedEventCodes.add(new QueryMicrosecondsEvent(microseconds)); break; case Q_HRNOW: //TODO: this was apparently added for MariaDB, but I can't find a lot of info on it. skip for now. suppliedEventCodes.add(new QueryMicrosecondsEvent(statsVarsBuf.readUnsignedMedium())); break; default: throw new PEException("Replication encountered an unknown query event code: '" + code + "' (0x" + Integer.toHexString(code) + ")"); } } } }