List of usage examples for io.netty.buffer ByteBuf writeLong
public abstract ByteBuf writeLong(long value);
From source file:gedi.remote.codec.NumberEncoder.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, Number msg, ByteBuf out) throws Exception { if (msg instanceof Byte) { out.writeInt(Integer.BYTES + 1 + Byte.BYTES); out.writeInt(1);/*ww w . j av a 2 s. c om*/ out.writeByte('B'); out.writeByte(msg.byteValue()); } else if (msg instanceof Short) { out.writeInt(Integer.BYTES + 1 + Short.BYTES); out.writeInt(1); out.writeByte('S'); out.writeShort(msg.shortValue()); } else if (msg instanceof Integer) { out.writeInt(Integer.BYTES + 1 + Integer.BYTES); out.writeInt(1); out.writeByte('I'); out.writeInt(msg.intValue()); } else if (msg instanceof Long) { out.writeInt(Integer.BYTES + 1 + Long.BYTES); out.writeInt(1); out.writeByte('L'); out.writeLong(msg.longValue()); } else if (msg instanceof Float) { out.writeInt(Integer.BYTES + 1 + Float.BYTES); out.writeInt(1); out.writeByte('F'); out.writeFloat(msg.floatValue()); } else if (msg instanceof Double) { out.writeInt(Integer.BYTES + 1 + Double.BYTES); out.writeInt(1); out.writeByte('D'); out.writeDouble(msg.doubleValue()); } else throw new RuntimeException("Could not encode number " + msg.getClass().getName()); }
From source file:hellfirepvp.astralsorcery.common.network.packet.client.PktRequestSeed.java
License:Open Source License
@Override public void toBytes(ByteBuf buf) { buf.writeInt(dimId); buf.writeInt(session); buf.writeLong(seed); }
From source file:hellfirepvp.astralsorcery.common.network.packet.server.PktCraftingTableFix.java
License:Open Source License
@Override public void toBytes(ByteBuf buf) { buf.writeLong(at.toLong()); }
From source file:herddb.proto.PduCodec.java
License:Apache License
private static void writeObject(ByteBuf byteBuf, Object v) { if (v == null) { byteBuf.writeByte(TYPE_NULL);/*from w w w . j ava2s . c o m*/ } else if (v instanceof RawString) { byteBuf.writeByte(TYPE_STRING); ByteBufUtils.writeRawString(byteBuf, (RawString) v); } else if (v instanceof String) { byteBuf.writeByte(TYPE_STRING); ByteBufUtils.writeString(byteBuf, (String) v); } else if (v instanceof Long) { byteBuf.writeByte(TYPE_LONG); byteBuf.writeLong((Long) v); } else if (v instanceof Integer) { byteBuf.writeByte(TYPE_INTEGER); byteBuf.writeInt((Integer) v); } else if (v instanceof Boolean) { byteBuf.writeByte(TYPE_BOOLEAN); byteBuf.writeBoolean((Boolean) v); } else if (v instanceof java.util.Date) { byteBuf.writeByte(TYPE_TIMESTAMP); byteBuf.writeLong(((java.util.Date) v).getTime()); } else if (v instanceof Double) { byteBuf.writeByte(TYPE_DOUBLE); byteBuf.writeDouble((Double) v); } else if (v instanceof Float) { byteBuf.writeByte(TYPE_DOUBLE); byteBuf.writeDouble((Float) v); } else if (v instanceof Short) { byteBuf.writeByte(TYPE_SHORT); byteBuf.writeLong((Short) v); } else if (v instanceof byte[]) { byteBuf.writeByte(TYPE_BYTEARRAY); ByteBufUtils.writeArray(byteBuf, (byte[]) v); } else if (v instanceof Byte) { byteBuf.writeByte(TYPE_BYTE); byteBuf.writeByte((Byte) v); } else { throw new IllegalArgumentException("bad data type " + v.getClass()); } }
From source file:herddb.utils.ByteBufUtils.java
License:Apache License
public static final void writeDouble(ByteBuf buffer, double i) { buffer.writeLong(Double.doubleToLongBits(i)); }
From source file:hivemall.mix.MixMessageEncoder.java
License:Open Source License
private static void encodeObject(final Object obj, final ByteBuf buf) throws IOException { assert (obj != null); if (obj instanceof Integer) { Integer i = (Integer) obj; buf.writeByte(INTEGER_TYPE);//www . ja v a 2s . c om buf.writeInt(i.intValue()); } else if (obj instanceof Text) { Text t = (Text) obj; byte[] b = t.getBytes(); int length = t.getLength(); buf.writeByte(TEXT_TYPE); buf.writeInt(length); buf.writeBytes(b, 0, length); } else if (obj instanceof String) { String s = (String) obj; buf.writeByte(STRING_TYPE); writeString(s, buf); } else if (obj instanceof IntWritable) { IntWritable i = (IntWritable) obj; buf.writeByte(INT_WRITABLE_TYPE); buf.writeInt(i.get()); } else if (obj instanceof LongWritable) { LongWritable l = (LongWritable) obj; buf.writeByte(LONG_WRITABLE_TYPE); buf.writeLong(l.get()); } else { throw new IllegalStateException("Unexpected type: " + obj.getClass().getName()); } }
From source file:impl.underdark.transport.bluetooth.discovery.ble.transport.peripheral.BlePeripheral.java
License:Open Source License
void onCharacteristicReadRequest(final BluetoothDevice device, final int requestId, final int offset, final BluetoothGattCharacteristic characteristic) { //Logger.debug("ble peripheral onCharacteristicReadRequest"); if (BleConfig.charactNodeIdUuid.equals(characteristic.getUuid())) { ByteBuf buffer = Unpooled.buffer(); buffer.order(ByteOrder.BIG_ENDIAN); buffer.writeLong(this.nodeId); if (offset >= buffer.readableBytes()) { Logger.warn("ble peripheral read nodeId failed - invalid offset {}", offset); gattServer.sendResponse(device, requestId, BluetoothGatt.GATT_INVALID_OFFSET, offset, null); return; }//from w w w . j a v a2 s . co m byte[] value = Arrays.copyOfRange(buffer.array(), offset, Math.min(buffer.readableBytes() - offset, BleConfig.charactValueSizeMax)); gattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, value); return; } // nodeId if (BleConfig.charactAddressUuid.equals(characteristic.getUuid())) { byte[] address = BtUtils.getBytesFromAddress(this.adapter.getAddress()); if (address == null) { gattServer.sendResponse(device, requestId, BluetoothGatt.GATT_FAILURE, offset, null); return; } onAddressReadRequest(address, device, requestId, offset); return; } // address gattServer.sendResponse(device, requestId, BluetoothGatt.GATT_REQUEST_NOT_SUPPORTED, offset, null); }
From source file:io.atomix.cluster.messaging.impl.MessageEncoder.java
License:Apache License
private void encodeMessage(InternalMessage message, ByteBuf out) { // If the address hasn't been written to the channel, write it. if (!addressWritten) { out.writeShort(VERSION);//from w w w. j a v a 2 s . co m final InetAddress senderIp = address.address(); final byte[] senderIpBytes = senderIp.getAddress(); out.writeByte(senderIpBytes.length); out.writeBytes(senderIpBytes); // write sender port out.writeInt(address.port()); addressWritten = true; } out.writeByte(message.type().id()); out.writeInt(this.preamble); // write message id out.writeLong(message.id()); final byte[] payload = message.payload(); // write payload length out.writeInt(payload.length); // write payload. out.writeBytes(payload); }
From source file:io.crate.protocols.postgres.types.BigIntType.java
License:Apache License
@Override public int writeAsBinary(ByteBuf buffer, @Nonnull Object value) { buffer.writeInt(TYPE_LEN);//from ww w . j av a2s . co m buffer.writeLong(((long) value)); return INT32_BYTE_SIZE + TYPE_LEN; }
From source file:io.github.vastframework.codecs.primitives.EncodingPrimitiveSupport.java
License:Apache License
default void encodeLong(ByteBuf buffer, long value) { buffer.writeLong(value); }