コード例 #1
0
ファイル: KestrelProtocol.cs プロジェクト: twingly/KestrelApi
        //Private method for reading results of the "get" command.
        private bool ReadValue(WrappedSocket socket, out object value, out string key, out ulong unique)
        {
            string response = socket.ReadResponse();
            string[] parts = response.Split(' '); //Result line from server: "VALUE <key> <flags> <bytes> <cas unique>"
            if (parts[0] == "VALUE")
            {
                key = parts[1];

                byte[] rawFlags = new byte[2];
                var totalDataLength = Convert.ToUInt32(parts[3], CultureInfo.InvariantCulture);
                byte[] bytes = new byte[totalDataLength - 2];

                if (parts.Length > 4)
                {
                    unique = Convert.ToUInt64(parts[4]);
                }
                else
                {
                    unique = 0;
                }
                socket.Read(rawFlags);
                socket.Read(bytes);
                socket.SkipUntilEndOfLine(); //Skip the trailing \r\n
                SerializedType type = (SerializedType) ConvertFromLittleEndian(rawFlags);
                try
                {
                    value = Serializer.DeSerialize(bytes, type);
                }
                catch (Exception e)
                {
                    //If deserialization fails, return null
                    value = null;
                    throw new KestrelApiException("Error deserializing key " + key + " of type " + type, e);
                }
                return true;
            }
            else
            {
                key = null;
                value = null;
                unique = 0;
                return false;
            }
        }
コード例 #2
0
ファイル: KestrelProtocol.cs プロジェクト: twingly/KestrelApi
 public KestrelProtocol(WrappedSocket socket)
 {
     CompressionThreshold = 1024*128;
     _socket = socket;
 }
コード例 #3
0
ファイル: ServerPool.cs プロジェクト: twingly/KestrelApi
 protected KestrelClient CreateServer(IPEndPoint endpoint)
 {
     var socket = new WrappedSocket(endpoint, _configuration.SendReceiveTimeout);
     var protocol = new KestrelProtocol(socket);
     var server = new KestrelClient(protocol);
     return server;
 }