Skip to content

Commit 17fce5d

Browse files
committed
fixes decoding int64/uint64
1 parent e03487f commit 17fce5d

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

Assets/Plugins/Colyseus/Serializer/Schema/Decoder.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ public object DecodePrimitiveType(string type, byte[] bytes, Iterator it)
5353
{
5454
return DecodeUint32(bytes, it);
5555
}
56+
else if (type == "int64")
57+
{
58+
return DecodeInt64(bytes, it);
59+
}
60+
else if (type == "uint64")
61+
{
62+
return DecodeUint64(bytes, it);
63+
}
5664
else if (type == "float32")
5765
{
5866
return DecodeFloat32(bytes, it);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
namespace Application
3+
{
4+
public class NewClass
5+
{
6+
public NewClass()
7+
{
8+
}
9+
}
10+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// THIS FILE HAS BEEN GENERATED AUTOMATICALLY
3+
// DO NOT CHANGE IT MANUALLY UNLESS YOU KNOW WHAT YOU'RE DOING
4+
//
5+
// GENERATED USING @colyseus/schema 0.4.32
6+
//
7+
8+
using Colyseus.Schema;
9+
10+
namespace SchemaTest.PrimitiveTypes {
11+
public class PrimitiveTypes : Schema {
12+
[Type(0, "int8")]
13+
public int int8 = 0;
14+
15+
[Type(1, "uint8")]
16+
public uint uint8 = 0;
17+
18+
[Type(2, "int16")]
19+
public short int16 = 0;
20+
21+
[Type(3, "uint16")]
22+
public ushort uint16 = 0;
23+
24+
[Type(4, "int32")]
25+
public int int32 = 0;
26+
27+
[Type(5, "uint32")]
28+
public uint uint32 = 0;
29+
30+
[Type(6, "int64")]
31+
public long int64 = 0;
32+
33+
[Type(7, "uint64")]
34+
public ulong uint64 = 0;
35+
36+
[Type(8, "float32")]
37+
public float float32 = 0;
38+
39+
[Type(9, "float64")]
40+
public double float64 = 0;
41+
42+
[Type(10, "number")]
43+
public float varint = 0;
44+
45+
[Type(11, "string")]
46+
public string str = "";
47+
48+
[Type(12, "boolean")]
49+
public bool boolean = false;
50+
}
51+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using NUnit.Framework;
2+
using SchemaTest.PrimitiveTypes;
3+
using UnityEngine;
4+
5+
public class SchemaDeserializerTest
6+
{
7+
8+
[SetUp]
9+
public void Init()
10+
{
11+
12+
}
13+
14+
[TearDown]
15+
public void Dispose()
16+
{
17+
18+
}
19+
20+
[Test]
21+
public void PrimitiveTypesTest()
22+
{
23+
PrimitiveTypes state = new PrimitiveTypes();
24+
25+
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 };
26+
state.Decode(bytes);
27+
28+
Assert.AreEqual(state.int8, -128);
29+
Assert.AreEqual(state.uint8, 255);
30+
Assert.AreEqual(state.int16, -32768);
31+
Assert.AreEqual(state.uint16, 65535);
32+
Assert.AreEqual(state.int32, -2147483648);
33+
Assert.AreEqual(state.uint32, 4294967295);
34+
Assert.AreEqual(state.int64, -9223372036854775808);
35+
Assert.AreEqual(state.uint64, 9007199254740991);
36+
Assert.AreEqual(state.float32, -3.40282347E+38f);
37+
Assert.AreEqual(state.float64, 1.7976931348623157e+308);
38+
Assert.AreEqual(state.varint, 2000);
39+
Assert.AreEqual(state.str, "Hello world");
40+
Assert.AreEqual(state.boolean, true);
41+
}
42+
43+
}

0 commit comments

Comments
 (0)