List of usage examples for io.netty.buffer ByteBuf readByte
public abstract byte readByte();
From source file:cn.academy.ability.api.Controllable.java
License:GNU General Public License
@RegInitCallback private static void init() { NetworkS11n.addDirect(Controllable.class, new NetS11nAdaptor<Controllable>() { @Override/*from w w w. ja va 2 s . c o m*/ public void write(ByteBuf buf, Controllable obj) { buf.writeByte(obj.getCategory().getCategoryID()); buf.writeByte(obj.getControlID()); } @Override public Controllable read(ByteBuf buf) throws ContextException { Category cat = CategoryManager.INSTANCE.getCategory(buf.readByte()); return cat.getControllable(buf.readByte()); } }); NBTS11n.addBase(Controllable.class, new BaseSerializer<NBTBase, Controllable>() { @Override public NBTBase write(Controllable value) { return new NBTTagByteArray( new byte[] { (byte) value.getCategory().getCategoryID(), (byte) value.getControlID() }); } @Override public Controllable read(NBTBase tag, Class<? extends Controllable> type) { byte[] bytes = ((NBTTagByteArray) tag).func_150292_c(); Category cat = CategoryManager.INSTANCE.getCategory(bytes[0]); return cat.getControllable(bytes[1]); } }); }
From source file:cn.academy.ability.api.data.PresetData.java
License:GNU General Public License
@RegInitCallback private static void init() { NBTS11n.addBase(Preset.class, new BaseSerializer<NBTBase, Preset>() { @Override/* w w w.java 2 s . c o m*/ public NBTBase write(Preset value) { NBTTagCompound tag = new NBTTagCompound(); IntStream.range(0, MAX_KEYS).forEach(idx -> { Controllable ctrl = value.data[idx]; if (ctrl != null) { tag.setTag(String.valueOf(idx), NBTS11n.writeBase(ctrl, Controllable.class)); } }); return tag; } @Override public Preset read(NBTBase tag_, Class<? extends Preset> type) { NBTTagCompound tag = (NBTTagCompound) tag_; Controllable[] data = new Controllable[MAX_KEYS]; IntStream.range(0, MAX_KEYS).forEach(idx -> { String tagName = String.valueOf(idx); if (tag.hasKey(tagName)) { data[idx] = NBTS11n.readBase(tag.getTag(tagName), Controllable.class); } }); return new Preset(data); } }); NetworkS11n.addDirect(Preset.class, new NetS11nAdaptor<Preset>() { @Override public void write(ByteBuf buf, Preset obj) { int count = (int) IntStream.range(0, MAX_KEYS).filter(idx -> obj.hasMapping(idx)).count(); buf.writeByte(count); IntStream.range(0, MAX_KEYS).forEach(idx -> { if (obj.hasMapping(idx)) { buf.writeByte(idx); NetworkS11n.serializeWithHint(buf, obj.getControllable(idx), Controllable.class); } }); } @Override public Preset read(ByteBuf buf) throws ContextException { Preset ret = new Preset(); int count = buf.readByte(); while (count-- > 0) { int id = buf.readByte(); ret.data[id] = NetworkS11n.deserializeWithHint(buf, Controllable.class); } return ret; } }); }
From source file:cn.academy.ability.teleport.data.ClientModifyMsg.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { opcode = buf.readByte(); if (opcode == ADD) { arg = new Location(buf); } else if (opcode == REMOVE) { arg = (Integer) buf.readInt(); }/*from www. jav a2 s .c o m*/ }
From source file:cn.academy.ability.teleport.data.SyncMsg.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { int n = buf.readByte(); for (int i = 0; i < n; ++i) { list.add(new Location(buf)); }// w ww .ja v a 2 s. c o m }
From source file:cn.academy.core.block.dev.MsgActionStart.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { x = buf.readInt(); y = buf.readInt(); z = buf.readInt(); id = buf.readByte(); par = buf.readByte(); }
From source file:cn.academy.core.block.dev.MsgDeveloper.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { x = buf.readInt();/* ww w.j a v a2 s . c o m*/ y = buf.readShort(); z = buf.readInt(); energy = buf.readInt(); isStimulating = buf.readBoolean(); stimSuccess = buf.readByte(); stimFailure = buf.readByte(); nMagIncr = buf.readByte(); userID = buf.readInt(); }
From source file:cn.academy.crafting.api.MetalFormerRecipes.java
License:GNU General Public License
@RegInitCallback private static void _init() { NetworkS11n.addDirect(RecipeObject.class, new NetS11nAdaptor<RecipeObject>() { @Override//from w w w .ja v a 2 s . co m public void write(ByteBuf buf, RecipeObject obj) { buf.writeByte(obj.id); } @Override public RecipeObject read(ByteBuf buf) throws ContextException { return INSTANCE.objects.get(buf.readByte()); } }); }
From source file:cn.academy.misc.msg.TeleportMsg.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { dim = buf.readByte(); x = buf.readFloat(); y = buf.readFloat(); z = buf.readFloat(); }
From source file:cn.david.handler.EchoServerHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { logger.info("Msg is incoming!"); ByteBuf in = (ByteBuf) msg; byte i = in.readByte(); logger.info("Receiving a byte : " + i); ctx.write(msg);/*ww w .j a v a 2 s . com*/ }
From source file:cn.david.main.EchoClientHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { logger.info("Client: Msg is incoming!"); ByteBuf in = (ByteBuf) msg; byte i = in.readByte(); logger.info("Client :Receiving a byte : " + i); ctx.write(msg);/*w w w .j a v a 2 s. c om*/ }