-
Notifications
You must be signed in to change notification settings - Fork 3
/
GETWITHMETADATA.cs
58 lines (53 loc) · 2.18 KB
/
GETWITHMETADATA.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using BeetleX.Buffers;
using System;
using System.Collections.Generic;
using System.Text;
namespace Infinispan.Hotrod.Core.Commands
{
public class GETWITHMETADATA<K, V> : CommandWithKey<K>
{
public GETWITHMETADATA(Marshaller<K> km, Marshaller<V> vm, K key)
{
Key = key;
KeyMarshaller = km;
ValueMarshaller = vm;
NetworkReceive = OnReceive;
}
public Marshaller<V> ValueMarshaller;
public ValueWithMetadata<V> ValueWithMetadata { get; set; }
public override string Name => "GETWITHMETADATA";
public override Byte Code => 0x1B;
internal override void OnExecute(CommandContext ctx)
{
base.OnExecute(ctx);
}
internal override void Execute(CommandContext ctx, InfinispanClient client, PipeStream stream)
{
base.Execute(ctx, client, stream);
Codec.writeArray(KeyMarshaller.marshall(Key), stream);
stream.Flush();
}
public override Result OnReceive(InfinispanRequest request, ResponseStream stream)
{
if (request.ResponseStatus == Codec30.KEY_DOES_NOT_EXIST_STATUS)
{
return new Result { Status = ResultStatus.Completed, ResultType = ResultType.Null };
}
ValueWithMetadata = new ValueWithMetadata<V>();
var expirationInfoFlags = (byte)stream.ReadByte();
if ((expirationInfoFlags & 0x01) == 0)
{ // no infinite lifespan
ValueWithMetadata.Created = (Int64)Codec.readLong(stream);
ValueWithMetadata.Lifespan = (Int32)Codec.readVInt(stream);
}
if ((expirationInfoFlags & 0x02) == 0)
{ // no infinite maxidle
ValueWithMetadata.LastUsed = (Int64)Codec.readLong(stream);
ValueWithMetadata.MaxIdle = (Int32)Codec.readVInt(stream);
}
ValueWithMetadata.Version = Codec.readLong(stream);
ValueWithMetadata.Value = ValueMarshaller.unmarshall(Codec.readArray(stream));
return new Result { Status = ResultStatus.Completed, ResultType = ResultType.Object };
}
}
}