public static SegmentBasedTopologyInfo fromBytes(List <Byte> bytes, ref ulong pos) { SegmentBasedTopologyInfo resp = new SegmentBasedTopologyInfo(); ulong numNodes; resp.topologyId = HotRodUtils.bytesToVLong(bytes, ref pos); numNodes = HotRodUtils.bytesToVLong(bytes, ref pos); resp.nodes = new NodeAddress[numNodes]; for (uint i = 0; i < numNodes; i++) { ulong addressLength = HotRodUtils.bytesToVLong(bytes, ref pos); string address = Encoding.UTF8.GetString(bytes.GetRange((int)pos, (int)addressLength).ToArray()); pos += addressLength; ushort port = HotRodUtils.bytesToUShort(bytes, ref pos); resp.nodes[i] = new NodeAddress(address, port); } resp.hashFuncVersion = bytes[(int)pos++]; resp.numSegments = HotRodUtils.bytesToVLong(bytes, ref pos); resp.segmentSize = (ulong)0x7FFFFFFF / resp.numSegments; resp.segmentsToOwners = new List <int> [resp.numSegments]; for (uint i = 0; i < resp.numSegments; i++) { resp.segmentsToOwners[i] = new List <int>(); int numOwner = bytes[(int)pos++]; for (uint j = 0; j < numOwner; j++) { ulong idx = HotRodUtils.bytesToVLong(bytes, ref pos); resp.segmentsToOwners[i].Add((int)idx); } } return(resp); }
public List <Byte> toBytes() { List <Byte> list = header.toBytes(); list.AddRange(HotRodUtils.vIntegerToBytes(keyLength)); list.AddRange(key); return(list); }
public static OpGetResponse fromBytes(List <byte> list) { OpGetResponse newResp = new OpGetResponse(); ulong pos = 0; newResp.header = HeaderResponse.fromBytes(list, ref pos); newResp.valueLength = HotRodUtils.bytesToVLong(list, ref pos); if (newResp.valueLength != 0) { newResp.value = list.GetRange((int)pos, (int)(newResp.valueLength)); pos += newResp.valueLength; } return(newResp); }
public List <Byte> toBytes() { List <Byte> list = new List <Byte>(); list.Add(0xa0); list.AddRange(HotRodUtils.vIntegerToBytes(messageId)); list.Add(version); list.Add(opcode); list.AddRange(HotRodUtils.vIntegerToBytes(cacheNameLength)); if (cacheNameLength > 0) { list.AddRange(HotRodUtils.stringToBytes(cacheName)); } list.AddRange(HotRodUtils.vIntegerToBytes(flags)); list.Add(clientIntelligence); list.AddRange(HotRodUtils.vIntegerToBytes(topologyId)); return(list); }
public List <Byte> toBytes() { List <Byte> list = header.toBytes(); list.AddRange(HotRodUtils.vIntegerToBytes(keyLength)); list.AddRange(key); list.Add(timeUnits); if ((timeUnits & 0xf0) != 0x70 && (timeUnits & 0xf0) != 0x80) { list.AddRange(HotRodUtils.vIntegerToBytes(lifeSpan)); } if ((timeUnits & 0x0f) != 0x07 && (timeUnits & 0x0f) != 0x08) { list.AddRange(HotRodUtils.vIntegerToBytes(maxIdle)); } list.AddRange(HotRodUtils.vIntegerToBytes(valueLength)); list.AddRange(value); return(list); }
public static HashAwareTopologyInfo fromBytes(List <Byte> bytes, ref ulong pos) { HashAwareTopologyInfo resp = new HashAwareTopologyInfo(); ulong numNodes; resp.topologyId = HotRodUtils.bytesToVLong(bytes, ref pos); numNodes = HotRodUtils.bytesToVLong(bytes, ref pos); resp.nodes = new List <HashAwareNodeAddress>((int)numNodes); for (uint i = 0; i < numNodes; i++) { ulong addressLength = HotRodUtils.bytesToVLong(bytes, ref pos); string address = Encoding.UTF8.GetString(bytes.GetRange((int)pos, (int)addressLength).ToArray()); pos += addressLength; ushort port = HotRodUtils.bytesToUShort(bytes, ref pos); ulong hashcode = HotRodUtils.bytesToULong(bytes, ref pos); resp.nodes.Add(new HashAwareNodeAddress(address, port, hashcode)); } return(resp); }
public static HeaderResponse fromBytes(List <Byte> bytes, ref ulong pos) { HeaderResponse resp = new HeaderResponse(); if (bytes[0] != 0xA1) { throw new Exception("Bad magic number received: " + bytes[0]); } resp.magic = bytes[(int)pos++]; resp.messageId = HotRodUtils.bytesToVLong(bytes, ref pos); resp.opcode = bytes[(int)pos++]; resp.status = bytes[(int)pos++]; resp.topologyChangeMarker = bytes[(int)pos++]; if (resp.topologyChangeMarker != 0) { HashAwareTopologyInfo.fromBytes(bytes, ref pos); } return(resp); }