Skip to content

Commit

Permalink
Native deserializer manages both native type and Java type (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
masesdevelopers authored Oct 5, 2023
1 parent 71641b5 commit 1cd6321
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions src/net/KNet/Specific/Serialization/KNetSerialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,12 @@ public static Bytes DeserializeBytes(string topic, byte[] data)
/// </summary>
public static double DeserializeDouble(string topic, byte[] data)
{
return JVMBridgeBase.Wraps<Java.Lang.Double>(_DoubleDeserializer.Deserialize(topic, data) as IJavaObject);
var result = _DoubleDeserializer.Deserialize(topic, data);
if (result is IJavaObject ijo)
{
return JVMBridgeBase.Wraps<Java.Lang.Double>(ijo);
}
return (double)result;
}

static readonly FloatDeserializer _FloatDeserializer = new FloatDeserializer();
Expand All @@ -281,7 +286,12 @@ public static double DeserializeDouble(string topic, byte[] data)
/// </summary>
public static float DeserializeFloat(string topic, byte[] data)
{
return JVMBridgeBase.Wraps<Java.Lang.Float>(_FloatDeserializer.Deserialize(topic, data) as IJavaObject);
var result = _FloatDeserializer.Deserialize(topic, data);
if (result is IJavaObject ijo)
{
return JVMBridgeBase.Wraps<Java.Lang.Float>(ijo);
}
return (float)result;
}

static readonly IntegerDeserializer _IntDeserializer = new IntegerDeserializer();
Expand All @@ -290,7 +300,12 @@ public static float DeserializeFloat(string topic, byte[] data)
/// </summary>
public static int DeserializeInt(string topic, byte[] data)
{
return JVMBridgeBase.Wraps<Java.Lang.Integer>(_IntDeserializer.Deserialize(topic, data) as IJavaObject);
var result = _IntDeserializer.Deserialize(topic, data);
if (result is IJavaObject ijo)
{
return JVMBridgeBase.Wraps<Java.Lang.Integer>(ijo);
}
return (int)result;

//if (data == null)
//{
Expand Down Expand Up @@ -324,7 +339,12 @@ public static int DeserializeInt(string topic, byte[] data)
/// </summary>
public static long DeserializeLong(string topic, byte[] data)
{
return JVMBridgeBase.Wraps<Java.Lang.Long>(_LongDeserializer.Deserialize(topic, data) as IJavaObject);
var result = _LongDeserializer.Deserialize(topic, data);
if (result is IJavaObject ijo)
{
return JVMBridgeBase.Wraps<Java.Lang.Long>(ijo);
}
return (long)result;

//if (data == null)
//{
Expand Down Expand Up @@ -358,7 +378,12 @@ public static long DeserializeLong(string topic, byte[] data)
/// </summary>
public static short DeserializeShort(string topic, byte[] data)
{
return JVMBridgeBase.Wraps<Java.Lang.Short>(_ShortDeserializer.Deserialize(topic, data) as IJavaObject);
var result = _ShortDeserializer.Deserialize(topic, data);
if (result is IJavaObject ijo)
{
return JVMBridgeBase.Wraps<Java.Lang.Short>(ijo);
}
return (short)result;

//if (data == null)
//{
Expand Down

0 comments on commit 1cd6321

Please sign in to comment.