List of usage examples for io.netty.buffer ByteBuf writeLong
public abstract ByteBuf writeLong(long value);
From source file:se.sics.caracaldb.global.LookupTable.java
License:Open Source License
public byte[] serialise() { ByteBuf buf = Unpooled.buffer(); buf.writeLong(versionId); buf.writeInt(scatterWidth);/*from www .ja va2s . c o m*/ // schemas schemas.serialise(buf); // hosts buf.writeInt(hosts.size()); for (Address addr : hosts) { SpecialSerializers.AddressSerializer.INSTANCE.toBinary(addr, buf); } // replicationgroups buf.writeInt(replicationSets.size()); for (ListIterator<Integer[]> it = replicationSets.listIterator(); it.hasNext();) { int pos = it.nextIndex(); Integer[] group = it.next(); Integer version = replicationSetVersions.get(pos); serialiseReplicationSet(version, group, buf); } // virtualHostGroups for (int i = 0; i < NUM_VIRT_GROUPS; i++) { buf.writeLong(virtualHostGroupVersions[i]); byte[] lgbytes = virtualHostGroups[i].serialise(); buf.writeInt(lgbytes.length); buf.writeBytes(lgbytes); } byte[] data = new byte[buf.readableBytes()]; buf.readBytes(data); buf.release(); return data; }
From source file:se.sics.caracaldb.global.NodeStats.java
License:Open Source License
public void serialise(ByteBuf buf) throws IOException { SpecialSerializers.AddressSerializer.INSTANCE.toBinary(node, buf); CustomSerialisers.serialiseKeyRange(range, buf); buf.writeLong(storeSize); buf.writeLong(storeNumberOfKeys);/*from w w w. j a v a2 s . c o m*/ buf.writeLong(ops); }
From source file:se.sics.caracaldb.global.SchemaData.java
License:Open Source License
public void serialise(ByteBuf buf) { buf.writeLong(version); serialiseData(buf); }
From source file:se.sics.caracaldb.paxos.PaxosSerializer.java
License:Open Source License
@Override public void toBinary(Object o, ByteBuf buf) { // Non PaxosMsg if (o instanceof Forward) { Forward f = (Forward) o;/*from ww w. j ava2 s. c o m*/ SpecialSerializers.MessageSerializationUtil.msgToBinary(f, buf, true, false); buf.writeByte(FORWARD); Serializers.toBinary(f.p, buf); return; } if (!(o instanceof PaxosMsg)) { return; } // PaxosMsg PaxosMsg msg = (PaxosMsg) o; SpecialSerializers.MessageSerializationUtil.msgToBinary(msg, buf, false, false); buf.writeInt(msg.ballot); if (o instanceof Prepare) { buf.writeByte(PREPARE); return; } if (o instanceof Promise) { buf.writeByte(PROMISE); Promise p = (Promise) o; buf.writeInt(p.maxInstances.size()); for (Instance i : p.maxInstances) { instanceToBinary(i, buf); } CustomSerialisers.serialiseView(p.view, buf); return; } if (o instanceof NoPromise) { buf.writeByte(NO_PROMISE); return; } if (o instanceof Accept) { buf.writeByte(ACCEPT); Accept a = (Accept) o; instanceToBinary(a.i, buf); return; } if (o instanceof Accepted) { buf.writeByte(ACCEPTED); Accepted a = (Accepted) o; instanceToBinary(a.i, buf); CustomSerialisers.serialiseView(a.view, buf); return; } if (o instanceof Rejected) { buf.writeByte(REJECTED); Rejected r = (Rejected) o; instanceToBinary(r.i, buf); return; } if (o instanceof Install) { buf.writeByte(INSTALL); Install inst = (Install) o; Serializers.toBinary(inst.event, buf); buf.writeLong(inst.highestDecided); buf.writeInt(inst.log.size()); for (Entry<Long, Value> e : inst.log.entrySet()) { Long k = e.getKey(); Value v = e.getValue(); buf.writeLong(k); Serializers.toBinary(v, buf); } return; } LOG.error("Could not find serializer for {}:{}!", o, o.getClass()); }
From source file:se.sics.caracaldb.paxos.PaxosSerializer.java
License:Open Source License
private void instanceToBinary(Instance i, ByteBuf buf) { buf.writeLong(i.id); buf.writeInt(i.ballot); Serializers.toBinary(i.value, buf); }
From source file:se.sics.caracaldb.vhostfd.FDSerializer.java
License:Open Source License
@Override public void toBinary(Object o, ByteBuf buf) { if (o instanceof Ping) { Ping p = (Ping) o;/* ww w.j a v a 2 s . c o m*/ SpecialSerializers.MessageSerializationUtil.msgToBinary(p, buf, PING, false); SpecialSerializers.UUIDSerializer.INSTANCE.toBinary(p.id, buf); buf.writeLong(p.ts); return; } if (o instanceof Pong) { Pong p = (Pong) o; SpecialSerializers.MessageSerializationUtil.msgToBinary(p, buf, PONG, false); SpecialSerializers.UUIDSerializer.INSTANCE.toBinary(p.id, buf); buf.writeLong(p.ts); return; } LOG.warn("Couldn't serialise instance {} of {}", o, o.getClass()); }
From source file:se.sics.gvod.stream.congestion.PLedbatStateImplSerializer.java
License:Open Source License
@Override public void toBinary(Object o, ByteBuf buf) { PLedbatState obj = (PLedbatState) o; buf.writeLong(obj.getSendingTime()); }
From source file:se.sics.ktoolbox.epfd.msg.EPFDPingSerializer.java
License:Open Source License
@Override public void toBinary(Object o, ByteBuf buf) { EPFDPing obj = (EPFDPing) o;/*from w w w.java 2 s .co m*/ Serializers.lookupSerializer(msgIdType).toBinary(obj.msgId, buf); Serializers.lookupSerializer(UUID.class).toBinary(obj.timeoutId, buf); buf.writeLong(obj.ts); }
From source file:se.sics.ktoolbox.epfd.msg.EPFDPongSerializer.java
License:Open Source License
@Override public void toBinary(Object o, ByteBuf buf) { EPFDPong obj = (EPFDPong) o;/*from ww w. j a v a2 s. co m*/ Serializers.lookupSerializer(msgIdType).toBinary(obj.ping.msgId, buf); Serializers.lookupSerializer(UUID.class).toBinary(obj.ping.timeoutId, buf); buf.writeLong(obj.ping.ts); }
From source file:se.sics.ktoolbox.util.network.nat.NatTypeSerializer.java
License:Open Source License
@Override public void toBinary(Object o, ByteBuf buf) { NatType nat = (NatType) o;/* w w w. j av a2 s.co m*/ BitBuffer bb = BitBuffer.create(flags); switch (nat.type) { case OPEN: buf.writeBytes(bb.finalise()); return; case NAT: bb.write(Pair.with(0, true)); break; case UPNP: bb.write(Pair.with(1, true)); buf.writeBytes(bb.finalise()); return; case FIREWALL: bb.write(Pair.with(0, true), Pair.with(1, true)); buf.writeBytes(bb.finalise()); return; case UDP_BLOCKED: bb.write(Pair.with(2, true)); buf.writeBytes(bb.finalise()); return; case UNKNOWN: bb.write(Pair.with(0, true), Pair.with(2, true)); buf.writeBytes(bb.finalise()); return; default: throw new IllegalArgumentException("unknown type:" + nat.type); } switch (nat.allocationPolicy) { case PORT_PRESERVATION: break; case PORT_CONTIGUITY: bb.write(Pair.with(3, true)); break; case RANDOM: bb.write(Pair.with(4, true)); break; default: throw new IllegalArgumentException("unknown allocation policy:" + nat.allocationPolicy); } switch (nat.mappingPolicy) { case ENDPOINT_INDEPENDENT: break; case HOST_DEPENDENT: bb.write(Pair.with(5, true)); break; case PORT_DEPENDENT: bb.write(Pair.with(6, true)); break; default: throw new IllegalArgumentException("unknown mapping policy:" + nat.mappingPolicy); } switch (nat.filteringPolicy) { case ENDPOINT_INDEPENDENT: break; case HOST_DEPENDENT: bb.write(Pair.with(7, true)); break; case PORT_DEPENDENT: bb.write(Pair.with(8, true)); break; default: throw new IllegalArgumentException("unknown mapping policy:" + nat.mappingPolicy); } buf.writeBytes(bb.finalise()); buf.writeInt(nat.delta); buf.writeLong(nat.bindingTimeout); }