List of usage examples for io.netty.buffer ByteBuf writeFloat
public abstract ByteBuf writeFloat(float value);
From source file:net.tridentsdk.server.packets.play.out.PacketPlayOutSoundEffect.java
License:Apache License
@Override public void encode(ByteBuf buf) { Codec.writeString(buf, this.sound.toString()); buf.writeInt((int) this.loc.x()); buf.writeInt((int) this.loc.y()); buf.writeInt((int) this.loc.z()); buf.writeFloat(this.volume); buf.writeByte(this.pitch); }
From source file:org.apache.drill.exec.store.hbase.CompareFunctionsProcessor.java
License:Apache License
@Override public Boolean visitConvertExpression(ConvertExpression e, LogicalExpression valueArg) throws RuntimeException { if (e.getConvertFunction() == ConvertExpression.CONVERT_FROM) { String encodingType = e.getEncodingType(); int prefixLength = 0; // Handle scan pruning in the following scenario: // The row-key is a composite key and the CONVERT_FROM() function has byte_substr() as input function which is // querying for the first few bytes of the row-key(start-offset 1) // Example WHERE clause: // CONVERT_FROM(BYTE_SUBSTR(row_key, 1, 8), 'DATE_EPOCH_BE') < DATE '2015-06-17' if (e.getInput() instanceof FunctionCall) { // We can prune scan range only for big-endian encoded data if (encodingType.endsWith("_BE") == false) { return false; }// ww w . j a v a 2 s . c o m FunctionCall call = (FunctionCall) e.getInput(); String functionName = call.getName(); if (!functionName.equalsIgnoreCase("byte_substr")) { return false; } LogicalExpression nameArg = call.args.get(0); LogicalExpression valueArg1 = call.args.size() >= 2 ? call.args.get(1) : null; LogicalExpression valueArg2 = call.args.size() >= 3 ? call.args.get(2) : null; if (((nameArg instanceof SchemaPath) == false) || (valueArg1 == null) || ((valueArg1 instanceof IntExpression) == false) || (valueArg2 == null) || ((valueArg2 instanceof IntExpression) == false)) { return false; } boolean isRowKey = ((SchemaPath) nameArg).getAsUnescapedPath().equals(DrillHBaseConstants.ROW_KEY); int offset = ((IntExpression) valueArg1).getInt(); if (!isRowKey || (offset != 1)) { return false; } this.path = (SchemaPath) nameArg; prefixLength = ((IntExpression) valueArg2).getInt(); this.isRowKeyPrefixComparison = true; return visitRowKeyPrefixConvertExpression(e, prefixLength, valueArg); } if (e.getInput() instanceof SchemaPath) { ByteBuf bb = null; switch (encodingType) { case "INT_BE": case "INT": case "UINT_BE": case "UINT": case "UINT4_BE": case "UINT4": if (valueArg instanceof IntExpression && (isEqualityFn || encodingType.startsWith("U"))) { bb = newByteBuf(4, encodingType.endsWith("_BE")); bb.writeInt(((IntExpression) valueArg).getInt()); } break; case "BIGINT_BE": case "BIGINT": case "UINT8_BE": case "UINT8": if (valueArg instanceof LongExpression && (isEqualityFn || encodingType.startsWith("U"))) { bb = newByteBuf(8, encodingType.endsWith("_BE")); bb.writeLong(((LongExpression) valueArg).getLong()); } break; case "FLOAT": if (valueArg instanceof FloatExpression && isEqualityFn) { bb = newByteBuf(4, true); bb.writeFloat(((FloatExpression) valueArg).getFloat()); } break; case "DOUBLE": if (valueArg instanceof DoubleExpression && isEqualityFn) { bb = newByteBuf(8, true); bb.writeDouble(((DoubleExpression) valueArg).getDouble()); } break; case "TIME_EPOCH": case "TIME_EPOCH_BE": if (valueArg instanceof TimeExpression) { bb = newByteBuf(8, encodingType.endsWith("_BE")); bb.writeLong(((TimeExpression) valueArg).getTime()); } break; case "DATE_EPOCH": case "DATE_EPOCH_BE": if (valueArg instanceof DateExpression) { bb = newByteBuf(8, encodingType.endsWith("_BE")); bb.writeLong(((DateExpression) valueArg).getDate()); } break; case "BOOLEAN_BYTE": if (valueArg instanceof BooleanExpression) { bb = newByteBuf(1, false /* does not matter */); bb.writeByte(((BooleanExpression) valueArg).getBoolean() ? 1 : 0); } break; case "DOUBLE_OB": case "DOUBLE_OBD": if (valueArg instanceof DoubleExpression) { bb = newByteBuf(9, true); PositionedByteRange br = new SimplePositionedMutableByteRange(bb.array(), 0, 9); if (encodingType.endsWith("_OBD")) { org.apache.hadoop.hbase.util.OrderedBytes.encodeFloat64(br, ((DoubleExpression) valueArg).getDouble(), Order.DESCENDING); this.sortOrderAscending = false; } else { org.apache.hadoop.hbase.util.OrderedBytes.encodeFloat64(br, ((DoubleExpression) valueArg).getDouble(), Order.ASCENDING); } } break; case "FLOAT_OB": case "FLOAT_OBD": if (valueArg instanceof FloatExpression) { bb = newByteBuf(5, true); PositionedByteRange br = new SimplePositionedMutableByteRange(bb.array(), 0, 5); if (encodingType.endsWith("_OBD")) { org.apache.hadoop.hbase.util.OrderedBytes.encodeFloat32(br, ((FloatExpression) valueArg).getFloat(), Order.DESCENDING); this.sortOrderAscending = false; } else { org.apache.hadoop.hbase.util.OrderedBytes.encodeFloat32(br, ((FloatExpression) valueArg).getFloat(), Order.ASCENDING); } } break; case "BIGINT_OB": case "BIGINT_OBD": if (valueArg instanceof LongExpression) { bb = newByteBuf(9, true); PositionedByteRange br = new SimplePositionedMutableByteRange(bb.array(), 0, 9); if (encodingType.endsWith("_OBD")) { org.apache.hadoop.hbase.util.OrderedBytes.encodeInt64(br, ((LongExpression) valueArg).getLong(), Order.DESCENDING); this.sortOrderAscending = false; } else { org.apache.hadoop.hbase.util.OrderedBytes.encodeInt64(br, ((LongExpression) valueArg).getLong(), Order.ASCENDING); } } break; case "INT_OB": case "INT_OBD": if (valueArg instanceof IntExpression) { bb = newByteBuf(5, true); PositionedByteRange br = new SimplePositionedMutableByteRange(bb.array(), 0, 5); if (encodingType.endsWith("_OBD")) { org.apache.hadoop.hbase.util.OrderedBytes.encodeInt32(br, ((IntExpression) valueArg).getInt(), Order.DESCENDING); this.sortOrderAscending = false; } else { org.apache.hadoop.hbase.util.OrderedBytes.encodeInt32(br, ((IntExpression) valueArg).getInt(), Order.ASCENDING); } } break; case "UTF8": // let visitSchemaPath() handle this. return e.getInput().accept(this, valueArg); } if (bb != null) { this.value = bb.array(); this.path = (SchemaPath) e.getInput(); return true; } } } return false; }
From source file:org.apache.drill.exec.store.mapr.db.binary.CompareFunctionsProcessor.java
License:Apache License
@Override public Boolean visitConvertExpression(ConvertExpression e, LogicalExpression valueArg) throws RuntimeException { if (e.getConvertFunction() == ConvertExpression.CONVERT_FROM) { String encodingType = e.getEncodingType(); int prefixLength = 0; // Handle scan pruning in the following scenario: // The row-key is a composite key and the CONVERT_FROM() function has byte_substr() as input function which is // querying for the first few bytes of the row-key(start-offset 1) // Example WHERE clause: // CONVERT_FROM(BYTE_SUBSTR(row_key, 1, 8), 'DATE_EPOCH_BE') < DATE '2015-06-17' if (e.getInput() instanceof FunctionCall) { // We can prune scan range only for big-endian encoded data if (encodingType.endsWith("_BE") == false) { return false; }/*from w ww.ja v a2 s .c o m*/ FunctionCall call = (FunctionCall) e.getInput(); String functionName = call.getName(); if (!functionName.equalsIgnoreCase("byte_substr")) { return false; } LogicalExpression nameArg = call.args.get(0); LogicalExpression valueArg1 = call.args.size() >= 2 ? call.args.get(1) : null; LogicalExpression valueArg2 = call.args.size() >= 3 ? call.args.get(2) : null; if (((nameArg instanceof SchemaPath) == false) || (valueArg1 == null) || ((valueArg1 instanceof IntExpression) == false) || (valueArg2 == null) || ((valueArg2 instanceof IntExpression) == false)) { return false; } boolean isRowKey = ((SchemaPath) nameArg).getAsUnescapedPath().equals(DrillHBaseConstants.ROW_KEY); int offset = ((IntExpression) valueArg1).getInt(); if (!isRowKey || (offset != 1)) { return false; } this.path = (SchemaPath) nameArg; prefixLength = ((IntExpression) valueArg2).getInt(); this.isRowKeyPrefixComparison = true; return visitRowKeyPrefixConvertExpression(e, prefixLength, valueArg); } if (e.getInput() instanceof SchemaPath) { ByteBuf bb = null; switch (encodingType) { case "INT_BE": case "INT": case "UINT_BE": case "UINT": case "UINT4_BE": case "UINT4": if (valueArg instanceof IntExpression && (isEqualityFn || encodingType.startsWith("U"))) { bb = newByteBuf(4, encodingType.endsWith("_BE")); bb.writeInt(((IntExpression) valueArg).getInt()); } break; case "BIGINT_BE": case "BIGINT": case "UINT8_BE": case "UINT8": if (valueArg instanceof LongExpression && (isEqualityFn || encodingType.startsWith("U"))) { bb = newByteBuf(8, encodingType.endsWith("_BE")); bb.writeLong(((LongExpression) valueArg).getLong()); } break; case "FLOAT": if (valueArg instanceof FloatExpression && isEqualityFn) { bb = newByteBuf(4, true); bb.writeFloat(((FloatExpression) valueArg).getFloat()); } break; case "DOUBLE": if (valueArg instanceof DoubleExpression && isEqualityFn) { bb = newByteBuf(8, true); bb.writeDouble(((DoubleExpression) valueArg).getDouble()); } break; case "TIME_EPOCH": case "TIME_EPOCH_BE": if (valueArg instanceof TimeExpression) { bb = newByteBuf(8, encodingType.endsWith("_BE")); bb.writeLong(((TimeExpression) valueArg).getTime()); } break; case "DATE_EPOCH": case "DATE_EPOCH_BE": if (valueArg instanceof DateExpression) { bb = newByteBuf(8, encodingType.endsWith("_BE")); bb.writeLong(((DateExpression) valueArg).getDate()); } break; case "BOOLEAN_BYTE": if (valueArg instanceof BooleanExpression) { bb = newByteBuf(1, false /* does not matter */); bb.writeByte(((BooleanExpression) valueArg).getBoolean() ? 1 : 0); } break; case "DOUBLE_OB": case "DOUBLE_OBD": if (valueArg instanceof DoubleExpression) { bb = newByteBuf(9, true); PositionedByteRange br = new SimplePositionedMutableByteRange(bb.array(), 0, 9); if (encodingType.endsWith("_OBD")) { org.apache.hadoop.hbase.util.OrderedBytes.encodeFloat64(br, ((DoubleExpression) valueArg).getDouble(), Order.DESCENDING); this.sortOrderAscending = false; } else { org.apache.hadoop.hbase.util.OrderedBytes.encodeFloat64(br, ((DoubleExpression) valueArg).getDouble(), Order.ASCENDING); } } break; case "FLOAT_OB": case "FLOAT_OBD": if (valueArg instanceof FloatExpression) { bb = newByteBuf(5, true); PositionedByteRange br = new SimplePositionedMutableByteRange(bb.array(), 0, 5); if (encodingType.endsWith("_OBD")) { org.apache.hadoop.hbase.util.OrderedBytes.encodeFloat32(br, ((FloatExpression) valueArg).getFloat(), Order.DESCENDING); this.sortOrderAscending = false; } else { org.apache.hadoop.hbase.util.OrderedBytes.encodeFloat32(br, ((FloatExpression) valueArg).getFloat(), Order.ASCENDING); } } break; case "BIGINT_OB": case "BIGINT_OBD": if (valueArg instanceof LongExpression) { bb = newByteBuf(9, true); PositionedByteRange br = new SimplePositionedMutableByteRange(bb.array(), 0, 9); if (encodingType.endsWith("_OBD")) { org.apache.hadoop.hbase.util.OrderedBytes.encodeInt64(br, ((LongExpression) valueArg).getLong(), Order.DESCENDING); this.sortOrderAscending = false; } else { org.apache.hadoop.hbase.util.OrderedBytes.encodeInt64(br, ((LongExpression) valueArg).getLong(), Order.ASCENDING); } } break; case "INT_OB": case "INT_OBD": if (valueArg instanceof IntExpression) { bb = newByteBuf(5, true); PositionedByteRange br = new SimplePositionedMutableByteRange(bb.array(), 0, 5); if (encodingType.endsWith("_OBD")) { org.apache.hadoop.hbase.util.OrderedBytes.encodeInt32(br, ((IntExpression) valueArg).getInt(), Order.DESCENDING); this.sortOrderAscending = false; } else { org.apache.hadoop.hbase.util.OrderedBytes.encodeInt32(br, ((IntExpression) valueArg).getInt(), Order.ASCENDING); } } break; case "UTF8_OB": case "UTF8_OBD": if (valueArg instanceof QuotedString) { int stringLen = ((QuotedString) valueArg).value.getBytes(Charsets.UTF_8).length; bb = newByteBuf(stringLen + 2, true); PositionedByteRange br = new SimplePositionedMutableByteRange(bb.array(), 0, stringLen + 2); if (encodingType.endsWith("_OBD")) { org.apache.hadoop.hbase.util.OrderedBytes.encodeString(br, ((QuotedString) valueArg).value, Order.DESCENDING); this.sortOrderAscending = false; } else { org.apache.hadoop.hbase.util.OrderedBytes.encodeString(br, ((QuotedString) valueArg).value, Order.ASCENDING); } } break; case "UTF8": // let visitSchemaPath() handle this. return e.getInput().accept(this, valueArg); } if (bb != null) { this.value = bb.array(); this.path = (SchemaPath) e.getInput(); return true; } } } return false; }
From source file:org.blockartistry.DynSurround.network.Locus.java
License:MIT License
public void toBytes(@Nonnull final ByteBuf buf) { buf.writeInt(this.dimension); buf.writeFloat((float) this.x); buf.writeFloat((float) this.y); buf.writeFloat((float) this.z); buf.writeFloat((float) this.range); buf.writeInt(this.entityId); }
From source file:org.blockartistry.DynSurround.network.PacketDisplayFootprint.java
License:MIT License
@Override public void toBytes(@Nonnull final ByteBuf buf) { this.locus.toBytes(buf); buf.writeFloat(this.rotation); buf.writeBoolean(this.isRightFoot); }
From source file:org.blockartistry.DynSurround.network.PacketHealthChange.java
License:MIT License
@Override public void toBytes(@Nonnull final ByteBuf buf) { buf.writeInt(this.entityId); buf.writeFloat(this.posX); buf.writeFloat(this.posY); buf.writeFloat(this.posZ); buf.writeBoolean(this.isCritical); buf.writeInt(this.amount); }
From source file:org.blockartistry.DynSurround.network.PacketWeatherUpdate.java
License:MIT License
@Override public void toBytes(@Nonnull final ByteBuf buf) { buf.writeShort(this.dimension); buf.writeFloat(this.intensity); buf.writeFloat(this.maxIntensity); buf.writeInt(this.nextRainChange); buf.writeFloat(this.thunderStrength); buf.writeInt(this.thunderChange); buf.writeInt(this.thunderEvent); }
From source file:org.blockartistry.mod.DynSurround.network.PacketHealthChange.java
License:MIT License
@Override public void toBytes(final ByteBuf buf) { buf.writeLong(this.entityId.getMostSignificantBits()); buf.writeLong(this.entityId.getLeastSignificantBits()); buf.writeFloat(this.posX); buf.writeFloat(this.posY); buf.writeFloat(this.posZ); buf.writeBoolean(this.isCritical); buf.writeInt(this.amount); }
From source file:org.blockartistry.mod.DynSurround.network.PacketRainIntensity.java
License:MIT License
public void toBytes(final ByteBuf buf) { buf.writeFloat(this.intensity); buf.writeInt(this.dimension); }
From source file:org.eclipse.neoscada.protocol.iec60870.asdu.types.TypeHelper.java
License:Open Source License
/** * Encode Short floating point number with quality descriptor */// ww w . j av a 2 s . c o m public static void encodeFloatValue(final ProtocolOptions options, final ByteBuf out, final Value<Float> value, final boolean withTimestamp) { final byte qds = (byte) (value.isOverflow() ? 0b00000001 : 0b00000000); final byte siq = value.getQualityInformation().apply(qds); out.writeFloat(value.getValue()); out.writeByte(siq); if (withTimestamp) { encodeTimestamp(options, out, value.getTimestamp()); } }