Skip to content

Commit

Permalink
fixes decoding int64/uint64
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed May 20, 2019
1 parent e03487f commit 17fce5d
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Assets/Plugins/Colyseus/Serializer/Schema/Decoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public object DecodePrimitiveType(string type, byte[] bytes, Iterator it)
{
return DecodeUint32(bytes, it);
}
else if (type == "int64")
{
return DecodeInt64(bytes, it);
}
else if (type == "uint64")
{
return DecodeUint64(bytes, it);
}
else if (type == "float32")
{
return DecodeFloat32(bytes, it);
Expand Down
10 changes: 10 additions & 0 deletions Assets/Tests/Schema/DoubleExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
namespace Application
{
public class NewClass
{
public NewClass()
{
}
}
}
51 changes: 51 additions & 0 deletions Assets/Tests/Schema/PrimitiveTypes/PrimitiveTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// THIS FILE HAS BEEN GENERATED AUTOMATICALLY
// DO NOT CHANGE IT MANUALLY UNLESS YOU KNOW WHAT YOU'RE DOING
//
// GENERATED USING @colyseus/schema 0.4.32
//

using Colyseus.Schema;

namespace SchemaTest.PrimitiveTypes {
public class PrimitiveTypes : Schema {
[Type(0, "int8")]
public int int8 = 0;

[Type(1, "uint8")]
public uint uint8 = 0;

[Type(2, "int16")]
public short int16 = 0;

[Type(3, "uint16")]
public ushort uint16 = 0;

[Type(4, "int32")]
public int int32 = 0;

[Type(5, "uint32")]
public uint uint32 = 0;

[Type(6, "int64")]
public long int64 = 0;

[Type(7, "uint64")]
public ulong uint64 = 0;

[Type(8, "float32")]
public float float32 = 0;

[Type(9, "float64")]
public double float64 = 0;

[Type(10, "number")]
public float varint = 0;

[Type(11, "string")]
public string str = "";

[Type(12, "boolean")]
public bool boolean = false;
}
}
43 changes: 43 additions & 0 deletions Assets/Tests/SchemaDeserializerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using NUnit.Framework;
using SchemaTest.PrimitiveTypes;
using UnityEngine;

public class SchemaDeserializerTest
{

[SetUp]
public void Init()
{

}

[TearDown]
public void Dispose()
{

}

[Test]
public void PrimitiveTypesTest()
{
PrimitiveTypes state = new PrimitiveTypes();

byte[] bytes = { 0, 128, 1, 255, 2, 0, 128, 3, 255, 255, 4, 0, 0, 0, 128, 5, 255, 255, 255, 255, 6, 0, 0, 0, 0, 0, 0, 0, 128, 7, 255, 255, 255, 255, 255, 255, 31, 0, 8, 255, 255, 127, 255, 9, 255, 255, 255, 255, 255, 255, 239, 127, 10, 205, 208, 7, 11, 171, 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 12, 1 };
state.Decode(bytes);

Assert.AreEqual(state.int8, -128);
Assert.AreEqual(state.uint8, 255);
Assert.AreEqual(state.int16, -32768);
Assert.AreEqual(state.uint16, 65535);
Assert.AreEqual(state.int32, -2147483648);
Assert.AreEqual(state.uint32, 4294967295);
Assert.AreEqual(state.int64, -9223372036854775808);
Assert.AreEqual(state.uint64, 9007199254740991);
Assert.AreEqual(state.float32, -3.40282347E+38f);
Assert.AreEqual(state.float64, 1.7976931348623157e+308);
Assert.AreEqual(state.varint, 2000);
Assert.AreEqual(state.str, "Hello world");
Assert.AreEqual(state.boolean, true);
}

}

0 comments on commit 17fce5d

Please sign in to comment.