List of usage examples for io.netty.buffer ByteBuf readLong
public abstract long readLong();
From source file:se.sics.caracaldb.paxos.PaxosSerializer.java
License:Open Source License
private Instance instanceFromBinary(ByteBuf buf) { long id = buf.readLong(); int ballot = buf.readInt(); Value v = (Value) Serializers.fromBinary(buf, Optional.absent()); return new Instance(id, ballot, v); }
From source file:se.sics.caracaldb.paxos.PaxosSerializer.java
License:Open Source License
private PaxosMsg paxosFromBinary(MessageFields fields, ByteBuf buf) { int ballot = buf.readInt(); byte type = buf.readByte(); View v;/*from ww w .j a va 2 s. c o m*/ Instance ins; int size; switch (type) { case PREPARE: return new Prepare(fields.src, fields.dst, ballot); case PROMISE: size = buf.readInt(); ImmutableSet.Builder<Instance> builder = ImmutableSet.builder(); for (int i = 0; i < size; i++) { builder.add(instanceFromBinary(buf)); } v = CustomSerialisers.deserialiseView(buf); return new Promise(fields.src, fields.dst, ballot, builder.build(), v); case NO_PROMISE: return new NoPromise(fields.src, fields.dst, ballot); case ACCEPT: ins = instanceFromBinary(buf); return new Accept(fields.src, fields.dst, ballot, ins); case ACCEPTED: ins = instanceFromBinary(buf); v = CustomSerialisers.deserialiseView(buf); return new Accepted(fields.src, fields.dst, ballot, ins, v); case REJECTED: ins = instanceFromBinary(buf); return new Rejected(fields.src, fields.dst, ballot, ins); case INSTALL: Reconfigure rec = (Reconfigure) Serializers.fromBinary(buf, Optional.absent()); long highestDecided = buf.readLong(); size = buf.readInt(); ImmutableSortedMap.Builder<Long, Value> mBuilder = ImmutableSortedMap.naturalOrder(); for (int i = 0; i < size; i++) { long k = buf.readLong(); Value val = (Value) Serializers.fromBinary(buf, Optional.absent()); mBuilder.put(k, val); } return new Install(fields.src, fields.dst, ballot, rec, highestDecided, mBuilder.build()); default: LOG.error("Unknown PaxosMsg type: {}", type); return null; } }
From source file:se.sics.caracaldb.vhostfd.FDSerializer.java
License:Open Source License
@Override public Object fromBinary(ByteBuf buf, Optional<Object> hint) { MessageFields fields = SpecialSerializers.MessageSerializationUtil.msgFromBinary(buf); UUID id = (UUID) SpecialSerializers.UUIDSerializer.INSTANCE.fromBinary(buf, Optional.absent()); long ts = buf.readLong(); if (fields.flag1 == PING) { return new Ping(id, ts, fields.src, fields.dst); }//from www.java 2 s. c o m if (fields.flag1 == PONG) { return new Pong(id, ts, fields.src, fields.dst); } return null; // Shouldn't get here }
From source file:se.sics.gvod.stream.congestion.PLedbatStateImplSerializer.java
License:Open Source License
@Override public Object fromBinary(ByteBuf buf, Optional<Object> hint) { Long sendingTime = buf.readLong(); return new PLedbatState.Impl(sendingTime); }
From source file:se.sics.ktoolbox.epfd.msg.EPFDPingSerializer.java
License:Open Source License
@Override public EPFDPing fromBinary(ByteBuf buf, Optional<Object> hint) { Identifier msgId = (Identifier) Serializers.fromBinary(buf, hint); UUID timeoutId = (UUID) Serializers.fromBinary(buf, hint); long ts = buf.readLong(); return new EPFDPing(msgId, timeoutId, ts); }
From source file:se.sics.ktoolbox.epfd.msg.EPFDPongSerializer.java
License:Open Source License
@Override public EPFDPong fromBinary(ByteBuf buf, Optional<Object> hint) { Identifier msgId = (Identifier) Serializers.lookupSerializer(msgIdType).fromBinary(buf, hint); UUID timeoutId = (UUID) Serializers.lookupSerializer(UUID.class).fromBinary(buf, hint); long ts = buf.readLong(); return new EPFDPong(new EPFDPing(msgId, timeoutId, ts)); }
From source file:se.sics.ktoolbox.util.identifiable.basic.UUIDIdFactory.java
License:Open Source License
@Override public UUIDId id(IdentifierBuilder builder) { UUID base;/*from ww w. j ava 2s. c o m*/ if (builder instanceof BasicBuilders.UUIDBuilder) { base = ((BasicBuilders.UUIDBuilder) builder).base; } else if (builder instanceof BasicBuilders.ByteBuilder) { BasicBuilders.ByteBuilder aux = (BasicBuilders.ByteBuilder) builder; ByteBuf buf = Unpooled.wrappedBuffer(aux.base); long mostSignificat = buf.readLong(); long leastSignificant = buf.readLong(); base = new UUID(mostSignificat, leastSignificant); } else if (builder instanceof BasicBuilders.StringBuilder) { BasicBuilders.StringBuilder aux = (BasicBuilders.StringBuilder) builder; base = UUID.fromString(aux.base); } else if (builder instanceof BasicBuilders.IntBuilder) { throw new UnsupportedOperationException("UUIDIdFactory does not support int builder"); } else { throw new UnsupportedOperationException("UUIDIdFactory does not support builder:" + builder.getClass()); } return new UUIDId(base); }
From source file:se.sics.ktoolbox.util.network.nat.NatTypeSerializer.java
License:Open Source License
@Override public Object fromBinary(ByteBuf buf, Optional<Object> hint) { byte[] bFlags = new byte[2]; buf.readBytes(bFlags);//w w w .j a v a 2s.com boolean[] traitFlags = BitBuffer.extract(flags, bFlags); Nat.Type type = getNatType(traitFlags); switch (type) { case OPEN: return NatType.open(); case FIREWALL: return NatType.firewall(); case UPNP: return NatType.upnp(); case UDP_BLOCKED: return NatType.udpBlocked(); case NAT: Nat.AllocationPolicy allocationPolicy = getAllocationPolicy(traitFlags); Nat.MappingPolicy mappingPolicy = getMappingPolicy(traitFlags); Nat.FilteringPolicy filteringPolicy = getFilterPolicy(traitFlags); int delta = buf.readInt(); long bindingTimeout = buf.readLong(); return NatType.nated(mappingPolicy, allocationPolicy, delta, filteringPolicy, bindingTimeout); case UNKNOWN: return NatType.unknown(); default: throw new RuntimeException("unknown NatType"); } }
From source file:se.sics.nstream.storage.cache.KHintSummarySerializer.java
License:Open Source License
@Override public Object fromBinary(ByteBuf buf, Optional<Object> hint) { long lStamp = buf.readLong(); int nrBlocks = buf.readInt(); Set<Integer> blocks = new TreeSet<>(); for (int j = 0; j < nrBlocks; j++) { blocks.add(buf.readInt());/*from w w w. ja v a 2 s . co m*/ } return new KHint.Summary(lStamp, blocks); }
From source file:se.sics.p2ptoolbox.serialization.serializer.UUIDSerializer.java
License:Open Source License
@Override public UUID decode(SerializationContext context, ByteBuf buf) throws SerializerException { Long uuidMSB = buf.readLong(); Long uuidLSB = buf.readLong(); return new UUID(uuidMSB, uuidLSB); }