Commit c3f1f2e9 authored by Nick Craver's avatar Nick Craver

Cleanup: RawResult

parent b7e78d8f
...@@ -3,15 +3,13 @@ ...@@ -3,15 +3,13 @@
namespace StackExchange.Redis namespace StackExchange.Redis
{ {
internal struct RawResult internal struct RawResult
{ {
public static readonly RawResult EmptyArray = new RawResult(new RawResult[0]); public static readonly RawResult EmptyArray = new RawResult(new RawResult[0]);
public static readonly RawResult Nil = new RawResult(); public static readonly RawResult Nil = new RawResult();
private static readonly byte[] emptyBlob = new byte[0]; private static readonly byte[] emptyBlob = new byte[0];
private readonly int offset, count; private readonly int offset, count;
private Array arr; private readonly Array arr;
public RawResult(ResultType resultType, byte[] buffer, int offset, int count) public RawResult(ResultType resultType, byte[] buffer, int offset, int count)
{ {
switch (resultType) switch (resultType)
...@@ -67,6 +65,7 @@ public override string ToString() ...@@ -67,6 +65,7 @@ public override string ToString()
return "(unknown)"; return "(unknown)";
} }
} }
internal RedisChannel AsRedisChannel(byte[] channelPrefix, RedisChannel.PatternMode mode) internal RedisChannel AsRedisChannel(byte[] channelPrefix, RedisChannel.PatternMode mode)
{ {
switch (Type) switch (Type)
...@@ -102,6 +101,7 @@ internal RedisKey AsRedisKey() ...@@ -102,6 +101,7 @@ internal RedisKey AsRedisKey()
throw new InvalidCastException("Cannot convert to RedisKey: " + Type); throw new InvalidCastException("Cannot convert to RedisKey: " + Type);
} }
} }
internal RedisValue AsRedisValue() internal RedisValue AsRedisValue()
{ {
switch (Type) switch (Type)
...@@ -157,6 +157,7 @@ internal bool AssertStarts(byte[] expected) ...@@ -157,6 +157,7 @@ internal bool AssertStarts(byte[] expected)
} }
return true; return true;
} }
internal byte[] GetBlob() internal byte[] GetBlob()
{ {
var src = (byte[])arr; var src = (byte[])arr;
...@@ -230,7 +231,8 @@ internal RedisValue[] GetItemsAsValues() ...@@ -230,7 +231,8 @@ internal RedisValue[] GetItemsAsValues()
return arr; return arr;
} }
} }
static readonly string[] NilStrings = new string[0];
private static readonly string[] NilStrings = new string[0];
internal string[] GetItemsAsStrings() internal string[] GetItemsAsStrings()
{ {
RawResult[] items = GetItems(); RawResult[] items = GetItems();
...@@ -252,6 +254,7 @@ internal string[] GetItemsAsStrings() ...@@ -252,6 +254,7 @@ internal string[] GetItemsAsStrings()
return arr; return arr;
} }
} }
internal GeoPosition? GetItemsAsGeoPosition() internal GeoPosition? GetItemsAsGeoPosition()
{ {
RawResult[] items = GetItems(); RawResult[] items = GetItems();
...@@ -259,14 +262,15 @@ internal string[] GetItemsAsStrings() ...@@ -259,14 +262,15 @@ internal string[] GetItemsAsStrings()
{ {
return null; return null;
} }
var coords = items[0].GetArrayOfRawResults(); var coords = items[0].GetArrayOfRawResults();
if (coords == null) if (coords == null)
{ {
return null; return null;
} }
return new GeoPosition((double)coords[1].AsRedisValue(), (double)coords[0].AsRedisValue()); return new GeoPosition((double)coords[1].AsRedisValue(), (double)coords[0].AsRedisValue());
} }
internal GeoPosition?[] GetItemsAsGeoPositionArray() internal GeoPosition?[] GetItemsAsGeoPositionArray()
{ {
RawResult[] items = GetItems(); RawResult[] items = GetItems();
...@@ -302,7 +306,6 @@ internal RawResult[] GetItemsAsRawResults() ...@@ -302,7 +306,6 @@ internal RawResult[] GetItemsAsRawResults()
return GetItems(); return GetItems();
} }
// returns an array of RawResults // returns an array of RawResults
internal RawResult[] GetArrayOfRawResults() internal RawResult[] GetArrayOfRawResults()
{ {
...@@ -341,8 +344,7 @@ internal bool TryGetDouble(out double val) ...@@ -341,8 +344,7 @@ internal bool TryGetDouble(out double val)
val = 0; val = 0;
return false; return false;
} }
long i64; if (TryGetInt64(out long i64))
if (TryGetInt64(out i64))
{ {
val = i64; val = i64;
return true; return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment