Read() публичный Метод

Fills the given byte array with data from the socket.
public Read ( byte bytes ) : void
bytes byte
Результат void
Пример #1
0
        //Private method for reading results of the "get" command.
        private bool readValue(PooledSocket socket, out object value, out string key, out ulong unique)
        {
            string response = socket.ReadResponse();

            string[] parts = response.Split(' ');             //DResult line from server: "VALUE <key> <flags> <bytes> <cas unique>"
            if (parts[0] == "VALUE")
            {
                key = parts[1];
                SerializedType type  = (SerializedType)Enum.Parse(typeof(SerializedType), parts[2]);
                byte[]         bytes = new byte[Convert.ToUInt32(parts[3], CultureInfo.InvariantCulture)];
                if (parts.Length > 4)
                {
                    unique = Convert.ToUInt64(parts[4]);
                }
                else
                {
                    unique = 0;
                }
                socket.Read(bytes);
                socket.SkipUntilEndOfLine();                 //Skip the trailing \r\n
                try {
                    value = Serializer.DeSerialize(bytes, type);
                } catch (Exception e) {
                    //If deserialization fails, return null
                    value = null;
                    logger.Error("Error deserializing object for key '" + key + "' of type " + type + ".", e);
                }
                return(true);
            }
            else
            {
                key    = null;
                value  = null;
                unique = 0;
                return(false);
            }
        }
Пример #2
0
 //Private method for reading results of the "get" command.
 private bool readValue(PooledSocket socket, out object value, out string key, out ulong unique)
 {
     string response = socket.ReadResponse();
     string[] parts = response.Split(' '); //DResult line from server: "VALUE <key> <flags> <bytes> <cas unique>"
     if (parts[0] == "VALUE") {
         key = parts[1];
         SerializedType type = (SerializedType)Enum.Parse(typeof(SerializedType), parts[2]);
         byte[] bytes = new byte[Convert.ToUInt32(parts[3], CultureInfo.InvariantCulture)];
         if (parts.Length > 4) {
             unique = Convert.ToUInt64(parts[4]);
         } else {
             unique = 0;
         }
         socket.Read(bytes);
         socket.SkipUntilEndOfLine(); //Skip the trailing \r\n
         try {
             value = Serializer.DeSerialize(bytes, type);
         } catch (Exception e) {
             //If deserialization fails, return null
             value = null;
             logger.Error("Error deserializing object for key '" + key + "' of type " + type + ".", e);
         }
         return true;
     } else {
         key = null;
         value = null;
         unique = 0;
         return false;
     }
 }