List of usage examples for io.netty.buffer ByteBuf readFloat
public abstract float readFloat();
From source file:org.starnub.starbounddata.types.vectors.Vec2F.java
License:Open Source License
@Override public void read(ByteBuf in) { this.x = in.readFloat(); this.y = in.readFloat(); }
From source file:org.traccar.protocol.TeltonikaProtocolDecoder.java
License:Apache License
private void decodeLocation(Position position, ByteBuf buf, int codec) { int globalMask = 0x0f; if (codec == CODEC_GH3000) { long time = buf.readUnsignedInt() & 0x3fffffff; time += 1167609600; // 2007-01-01 00:00:00 globalMask = buf.readUnsignedByte(); if (BitUtil.check(globalMask, 0)) { position.setTime(new Date(time * 1000)); int locationMask = buf.readUnsignedByte(); if (BitUtil.check(locationMask, 0)) { position.setLatitude(buf.readFloat()); position.setLongitude(buf.readFloat()); }//from ww w. j a va 2 s. co m if (BitUtil.check(locationMask, 1)) { position.setAltitude(buf.readUnsignedShort()); } if (BitUtil.check(locationMask, 2)) { position.setCourse(buf.readUnsignedByte() * 360.0 / 256); } if (BitUtil.check(locationMask, 3)) { position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); } if (BitUtil.check(locationMask, 4)) { position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); } if (BitUtil.check(locationMask, 5)) { CellTower cellTower = CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort()); if (BitUtil.check(locationMask, 6)) { cellTower.setSignalStrength((int) buf.readUnsignedByte()); } if (BitUtil.check(locationMask, 7)) { cellTower.setOperator(buf.readUnsignedInt()); } position.setNetwork(new Network(cellTower)); } else { if (BitUtil.check(locationMask, 6)) { position.set(Position.KEY_RSSI, buf.readUnsignedByte()); } if (BitUtil.check(locationMask, 7)) { position.set(Position.KEY_OPERATOR, buf.readUnsignedInt()); } } } else { getLastLocation(position, new Date(time * 1000)); } } else { position.setTime(new Date(buf.readLong())); position.set("priority", buf.readUnsignedByte()); position.setLongitude(buf.readInt() / 10000000.0); position.setLatitude(buf.readInt() / 10000000.0); position.setAltitude(buf.readShort()); position.setCourse(buf.readUnsignedShort()); int satellites = buf.readUnsignedByte(); position.set(Position.KEY_SATELLITES, satellites); position.setValid(satellites != 0); position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort())); position.set(Position.KEY_EVENT, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16)); if (codec == CODEC_16) { buf.readUnsignedByte(); // generation type } readExtByte(buf, codec, CODEC_8_EXT); // total IO data records } // Read 1 byte data if (BitUtil.check(globalMask, 1)) { int cnt = readExtByte(buf, codec, CODEC_8_EXT); for (int j = 0; j < cnt; j++) { decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 1, codec); } } // Read 2 byte data if (BitUtil.check(globalMask, 2)) { int cnt = readExtByte(buf, codec, CODEC_8_EXT); for (int j = 0; j < cnt; j++) { decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 2, codec); } } // Read 4 byte data if (BitUtil.check(globalMask, 3)) { int cnt = readExtByte(buf, codec, CODEC_8_EXT); for (int j = 0; j < cnt; j++) { decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 4, codec); } } // Read 8 byte data if (codec == CODEC_8 || codec == CODEC_8_EXT || codec == CODEC_16) { int cnt = readExtByte(buf, codec, CODEC_8_EXT); for (int j = 0; j < cnt; j++) { decodeOtherParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 8); } } // Read 16 byte data if (extended) { int cnt = readExtByte(buf, codec, CODEC_8_EXT); for (int j = 0; j < cnt; j++) { int id = readExtByte(buf, codec, CODEC_8_EXT, CODEC_16); position.set(Position.PREFIX_IO + id, ByteBufUtil.hexDump(buf.readSlice(16))); } } // Read X byte data if (codec == CODEC_8_EXT) { int cnt = buf.readUnsignedShort(); for (int j = 0; j < cnt; j++) { int id = buf.readUnsignedShort(); int length = buf.readUnsignedShort(); if (id == 256) { position.set(Position.KEY_VIN, buf.readSlice(length).toString(StandardCharsets.US_ASCII)); } else { position.set(Position.PREFIX_IO + id, ByteBufUtil.hexDump(buf.readSlice(length))); } } } decodeNetwork(position); }
From source file:org.traccar.protocol.TytanProtocolDecoder.java
License:Apache License
private void decodeExtraData(Position position, ByteBuf buf, int end) { while (buf.readerIndex() < end) { int type = buf.readUnsignedByte(); int length = buf.readUnsignedByte(); if (length == 255) { length += buf.readUnsignedByte(); }/*from w w w . j a v a2s . co m*/ int n; switch (type) { case 2: position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedMedium()); break; case 5: position.set(Position.KEY_INPUT, buf.readUnsignedByte()); break; case 6: n = buf.readUnsignedByte() >> 4; if (n < 2) { position.set(Position.PREFIX_ADC + n, buf.readFloat()); } else { position.set("di" + (n - 2), buf.readFloat()); } break; case 7: int alarm = buf.readUnsignedByte(); buf.readUnsignedByte(); if (BitUtil.check(alarm, 5)) { position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); } break; case 8: position.set("antihijack", buf.readUnsignedByte()); break; case 9: position.set("unauthorized", ByteBufUtil.hexDump(buf.readSlice(8))); break; case 10: position.set("authorized", ByteBufUtil.hexDump(buf.readSlice(8))); break; case 24: for (int i = 0; i < length / 2; i++) { position.set(Position.PREFIX_TEMP + buf.readUnsignedByte(), buf.readByte()); } break; case 28: position.set(Position.KEY_AXLE_WEIGHT, buf.readUnsignedShort()); buf.readUnsignedByte(); break; case 90: position.set(Position.KEY_POWER, buf.readFloat()); break; case 101: position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte()); break; case 102: position.set(Position.KEY_RPM, buf.readUnsignedByte() * 50); break; case 107: int fuel = buf.readUnsignedShort(); int fuelFormat = fuel >> 14; if (fuelFormat == 1) { position.set("fuelValue", (fuel & 0x3fff) * 0.4 + "%"); } else if (fuelFormat == 2) { position.set("fuelValue", (fuel & 0x3fff) * 0.5 + " l"); } else if (fuelFormat == 3) { position.set("fuelValue", (fuel & 0x3fff) * -0.5 + " l"); } break; case 108: position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 5); break; case 150: position.set(Position.KEY_DOOR, buf.readUnsignedByte()); break; default: buf.skipBytes(length); break; } } }
From source file:org.wso2.carbon.tcp.transport.util.SiddhiEventConverter.java
License:Open Source License
public Object[] toObjectArray(ByteBuf byteBuffer, Attribute.Type[] attributeTypeOrder) { if (attributeTypeOrder != null) { if (byteBuffer == null) { throw new MalformedEventException("Received byte stream in null. Hence cannot convert to event"); }// w w w .j a v a2s .c o m Object[] objects = new Object[attributeTypeOrder.length]; for (int i = 0; i < attributeTypeOrder.length; i++) { switch (attributeTypeOrder[i]) { case INT: objects[i] = byteBuffer.readInt(); break; case LONG: objects[i] = byteBuffer.readLong(); break; case STRING: int stringSize = byteBuffer.readInt(); if (stringSize == 0) { objects[i] = null; } else { objects[i] = BinaryMessageConverterUtil.getString(byteBuffer, stringSize); } break; case DOUBLE: objects[i] = byteBuffer.readDouble(); break; case FLOAT: objects[i] = byteBuffer.readFloat(); break; case BOOL: objects[i] = byteBuffer.readByte() == 1; break; } } return objects; } else { return null; } }
From source file:pneumaticCraft.common.network.PacketPlaySound.java
License:LGPL
@Override public void fromBytes(ByteBuf buffer) { super.fromBytes(buffer); sound = ByteBufUtils.readUTF8String(buffer); volume = buffer.readFloat(); pitch = buffer.readFloat();//from w ww.j a va2 s. c o m bool = buffer.readBoolean(); }
From source file:steamcraft.common.packets.CopperPipeFluidPacket.java
License:Minecraft Mod Public
@Override public void fromBytes(ByteBuf buf) { this.x = buf.readInt(); this.y = buf.readInt(); this.z = buf.readInt(); this.fluidScaled = buf.readFloat(); this.fluidName = ByteBufUtils.readUTF8String(buf); }
From source file:valkyrienwarfare.api.Vector.java
License:Open Source License
public static Vector readFromBuffer(ByteBuf buffer) { return new Vector(buffer.readFloat(), buffer.readFloat(), buffer.readFloat()); }
From source file:zeldaswordskills.entity.projectile.EntityMagicSpell.java
License:Open Source License
@Override public void readSpawnData(ByteBuf buffer) { super.readSpawnData(buffer); type = (MagicType.values()[buffer.readInt() % MagicType.values().length]); radius = buffer.readFloat(); spawnParticles = buffer.readBoolean(); }
From source file:zeldaswordskills.entity.projectile.EntityMobThrowable.java
License:Open Source License
@Override public void readSpawnData(ByteBuf buffer) { gravity = buffer.readFloat(); }