protected override CommandResult <byte[]> ReadResult(IRespReader reader) { RespDataType dataType = reader.ReadDataType(); if (dataType == RespDataType.Error) { string err = reader.ReadErrorValue(); return(CommandResult <byte[]> .Error(err)); } if (dataType != RespDataType.BulkString) { throw new InvalidDataException(); } byte[] value = reader.ReadBulkStringValue(); return(CommandResult.Success(value)); }
protected override CommandResult <long> ReadResult(IRespReader reader) { RespDataType dataType = reader.ReadDataType(); if (dataType == RespDataType.Error) { string err = reader.ReadErrorValue(); return(CommandResult <long> .Error(err)); } if (dataType != RespDataType.Integer) { throw new InvalidDataException(); } long value = reader.ReadIntegerValue(); return(CommandResult.Success(value)); }
protected override CommandResult <IList <byte[]> > ReadResult(IRespReader reader) { RespDataType dataType = reader.ReadDataType(); if (dataType == RespDataType.Error) { string err = reader.ReadErrorValue(); return(CommandResult <IList <byte[]> > .Error(err)); } if (dataType != RespDataType.Array) { throw new InvalidDataException(); } if (!reader.TryReadStartArray(out long length)) { return(CommandResult <IList <byte[]> > .Success(null)); } var values = new byte[length][]; for (var i = 0; i < length; i++) { dataType = reader.ReadDataType(); if (dataType != RespDataType.BulkString) { throw new InvalidDataException(); } values[i] = reader.ReadBulkStringValue(); } return(CommandResult.Success((IList <byte[]>)values)); }