Skip to content

Commit

Permalink
Fixed non-String and non-Bytes values not sent in JSON with binary da…
Browse files Browse the repository at this point in the history
…ta (#112)
  • Loading branch information
hypernoob authored and mattqs committed Aug 24, 2017
1 parent ba50d00 commit 57cfd7b
Showing 1 changed file with 49 additions and 45 deletions.
94 changes: 49 additions & 45 deletions Src/SocketIoClientDotNet.net45/Parser/Binary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,66 +25,70 @@ public static DeconstructedPacket DeconstructPacket(Packet packet)

private static JToken _deconstructPacket(object data, List<byte[]> buffers)
{
if (data == null) return null;
if (data == null)
{
return null;
}

if (data is byte[])
{
var byteArray = (byte[]) data;
var byteArray = (byte[])data;
return AddPlaceholder(buffers, byteArray);
}
if (data is JArray)
{
var newData = new JArray();
var _data = (JArray) data;
int len = _data.Count;
for (int i = 0; i < len; i ++)
{
try
{
newData.Add( _deconstructPacket(_data[i], buffers));
}
catch (Exception)
{
return null;
}
}
return newData;
}
if (!(data is JToken))

var jToken = data as JToken;
if (jToken == null)
{
throw new NotImplementedException();
}
var jtoken = (JToken) data;
if (jtoken.Type == JTokenType.String)
{
return jtoken.Value<string>();
}
else if (jtoken.Type == JTokenType.Bytes)
{
var byteArray = jtoken.Value<byte[]>();
return AddPlaceholder(buffers, byteArray);
}
else if (jtoken.Type == JTokenType.Object)
{

var newData2 = new JObject();
var _data2 = (JObject)jtoken;

foreach (var property in _data2.Properties())
{
try
switch (jToken.Type)
{
case JTokenType.Object:
var newJObject = new JObject();
var jObject = (JObject)jToken;
foreach (var property in jObject.Properties())
{
newData2[property.Name] = _deconstructPacket(property.Value, buffers);
try
{
newJObject[property.Name] = _deconstructPacket(property.Value, buffers);
}
catch (Exception)
{
return null;
}
}
catch (Exception)
return newJObject;

case JTokenType.Array:
var newJArray = new JArray();
var jArray = (JArray)jToken;
for (int i = 0; i < jArray.Count; i++)
{
return null;
try
{
newJArray.Add(_deconstructPacket(jArray[i], buffers));
}
catch (Exception)
{
return null;
}
}
return newJArray;

}
return newData2;
case JTokenType.Bytes:
var byteArray = jToken.Value<byte[]>();
return AddPlaceholder(buffers, byteArray);

case JTokenType.None:
case JTokenType.Constructor:
case JTokenType.Property:
case JTokenType.Comment:
throw new NotImplementedException();

default:
return jToken;
}
throw new NotImplementedException();
}

private static JToken AddPlaceholder(List<byte[]> buffers, byte[] byteArray)
Expand Down

0 comments on commit 57cfd7b

Please sign in to comment.