List of usage examples for io.netty.buffer Unpooled buffer
public static ByteBuf buffer(int initialCapacity)
From source file:com.tesora.dve.db.mysql.DBTypeBasedUtilsTest.java
License:Open Source License
@Test public void sqlReadWriteTest() throws Exception { ByteBuf cb = Unpooled.buffer(100).order(ByteOrder.LITTLE_ENDIAN); for (Pair<Integer, Object> expValue : expValuesSQL) { cb.clear();/*from ww w. j a v a2s. c om*/ DataTypeValueFunc dtvf = DBTypeBasedUtils.getSQLTypeFunc(expValue.getFirst()); dtvf.writeObject(cb, expValue.getSecond()); assertEqualData(expValue.getSecond(), dtvf.readObject(cb)); } }
From source file:com.tesora.dve.db.mysql.libmy.MyBinaryResultRow.java
License:Open Source License
public MyBinaryResultRow projection(int[] desiredFields) { int expectedFieldCount = desiredFields.length; ArrayList<ByteBuf> newSlices = new ArrayList<>(expectedFieldCount); ArrayList<DecodedMeta> newConverters = new ArrayList<>(expectedFieldCount); for (int targetIndex = 0; targetIndex < expectedFieldCount; targetIndex++) { int sourceIndex = desiredFields[targetIndex]; newConverters.add(fieldConverters.get(sourceIndex));//use the source index, not the target index.. if (fieldSlices.get(sourceIndex) == null) { newSlices.add(null);// ww w.j ava 2 s. c o m } else { ByteBuf fieldSlice = fieldSlices.get(sourceIndex); ByteBuf copySlice = Unpooled.buffer(fieldSlice.readableBytes()).order(ByteOrder.LITTLE_ENDIAN); copySlice.writeBytes(fieldSlice.slice()); newSlices.add(copySlice); } } return new MyBinaryResultRow(newConverters, newSlices); }
From source file:com.tesora.dve.db.mysql.libmy.MyFieldPktResponse.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { ByteBuf newCache = Unpooled.buffer(cb.readableBytes()).order(ByteOrder.LITTLE_ENDIAN); newCache.writeBytes(cb);/*from w w w. j a v a2s . c o m*/ updateCache(newCache); //parsing variable length name info is expensive, only unpack fixed length type info by default. unpackTypeInfo(cachedBuffer.slice()); state = CacheState.PACKED; }
From source file:com.tesora.dve.db.mysql.libmy.MyRawMessage.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { heapBuffer = Unpooled.buffer(cb.readableBytes()); heapBuffer.writeBytes(cb); }
From source file:com.tesora.dve.db.mysql.libmy.MyTextResultRow.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { backingBuffer = Unpooled.buffer(cb.readableBytes()).writeBytes(cb).order(ByteOrder.LITTLE_ENDIAN); ArrayList<Integer> offsets = MysqlAPIUtils.locateLengthCodedStrings(backingBuffer); stringOffsets = new int[offsets.size() + 1]; for (int i = 0; i < offsets.size(); i++) stringOffsets[i] = offsets.get(i); stringOffsets[offsets.size()] = backingBuffer.readableBytes();//last entry is (endpoint+1) of the last string. }
From source file:com.tesora.dve.db.mysql.portal.protocol.BaseMSPMessage.java
License:Open Source License
protected ByteBuf readBuffer() { if (isBufferSet()) return this.buffer; if (isStateSet()) { ByteBuf container = Unpooled.buffer(INITIAL_CAPACITY).order(ByteOrder.LITTLE_ENDIAN); marshall(this.state, container); this.set(state, container); return this.buffer; }//from w w w . j a v a 2 s.c o m throw new IllegalStateException(String.format("Cannot access buffer of %s, no fields or buffer provided.", this.getClass().getSimpleName())); }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyAppendBlockLogEvent.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { fileId = cb.readInt(); dataBlock = Unpooled.buffer(cb.readableBytes()); dataBlock.writeBytes(cb); }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyCreateFileLogEvent.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { threadId = cb.readInt();//from www . ja v a 2 s . com // TODO: need to parse out the variable part of the data variableData = Unpooled.buffer(cb.readableBytes()); variableData.writeBytes(cb); }
From source file:com.tesora.dve.mysqlapi.repl.messages.MyExecuteLoadLogEvent.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) throws PEException { threadId = cb.readInt();//from ww w. ja v a 2 s . c om time = cb.readInt(); dbLen = cb.readByte(); errorCode = cb.readShort(); statusBlockLen = cb.readShort(); fileId = cb.readInt(); startPos = cb.readInt(); endPos = cb.readInt(); duplicateFlag = cb.readByte(); // really we should check if replication version >=4 or else this is wrong statusVars.parseStatusVariables(cb, statusBlockLen); dbName = MysqlAPIUtils.readBytesAsString(cb, dbLen, 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.MyLoadLogEvent.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { threadId = cb.readInt();//w w w. j a v a 2 s . c o m time = cb.readInt(); ignoreLines = cb.readInt(); tableLen = cb.readByte(); dbLen = cb.readByte(); columns = cb.readInt(); // TODO: need to parse out the variable part of the data variableData = Unpooled.buffer(cb.readableBytes()); variableData.writeBytes(cb); }