Skip to content

Commit

Permalink
处理tabtoyv3 C#二进制读取的字段兼容性
Browse files Browse the repository at this point in the history
  • Loading branch information
davyxu committed May 12, 2020
1 parent 1417193 commit 055548f
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 21 deletions.
123 changes: 123 additions & 0 deletions v3/api/csharp/TableReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,129 @@ public bool ReadTag(ref UInt32 v)
return false;
}

public void SkipFiled(UInt32 tag)
{
var fieldIndex = tag & 0xffff;
switch (tag >> 16)
{
case 1: // int16
{
Int16 dummy = 0;
this.ReadInt16(ref dummy);
}
break;
case 2: // int32
case 10: // enum
{
Int32 dummy = 0;
this.ReadInt32(ref dummy);
}
break;
case 3: // int64
{
Int64 dummy = 0;
this.ReadInt64(ref dummy);
}
break;
case 4: // uint16
{
UInt16 dummy = 0;
this.ReadUInt16(ref dummy);
}
break;
case 5: // uint32
{
UInt32 dummy = 0;
this.ReadUInt32(ref dummy);
}
break;
case 6: // uint64
{
UInt64 dummy = 0;
this.ReadUInt64(ref dummy);
}
break;
case 7: // float32
{
float dummy = 0;
this.ReadFloat(ref dummy);
}
break;
case 8: // string
{
string dummy = string.Empty;
this.ReadString(ref dummy);
}
break;
case 9: // bool
{
bool dummy = false;
this.ReadBool(ref dummy);
}
break;


case 101: // int16
{
var dummy = new List<Int16>();
this.ReadInt16(ref dummy);
}
break;
case 102: // int32
case 110: // enum
{
var dummy = new List<Int32>();
this.ReadInt32(ref dummy);
}
break;
case 103: // int64
{
var dummy = new List<Int64>();
this.ReadInt64(ref dummy);
}
break;
case 104: // uint16
{
var dummy = new List<UInt16>();
this.ReadUInt16(ref dummy);
}
break;
case 105: // uint32
{
var dummy = new List<UInt32>();
this.ReadUInt32(ref dummy);
}
break;
case 106: // uint64
{
var dummy = new List<UInt64>();
this.ReadUInt64(ref dummy);
}
break;
case 107: // float32
{
var dummy = new List<float>();
this.ReadFloat(ref dummy);
}
break;
case 108: // string
{
var dummy = new List<string>();
this.ReadString(ref dummy);
}
break;
case 109: // bool
{
var dummy = new List<bool>();
this.ReadBool(ref dummy);
}
break;
default:
throw new Exception("Invalid tag type");
}
}


static readonly UTF8Encoding encoding = new UTF8Encoding();

public void ReadInt16(ref Int16 v)
Expand Down
Binary file modified v3/example/binary/table_gen.bin
Binary file not shown.
26 changes: 24 additions & 2 deletions v3/example/csharp/TabtoyExample/table_gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public partial class ExampleData : tabtoy.ITableSerializable
public float Rate = 0;
public ActorType Type = ActorType.None;
public List<Int32> Skill = new List<Int32>();
public Int32 Buff = 0;
public List<string> TagList = new List<string>();

#region Deserialize Code
public void Deserialize( tabtoy.TableReader reader )
Expand Down Expand Up @@ -51,11 +53,26 @@ public void Deserialize( tabtoy.TableReader reader )
reader.ReadEnum( ref Type );
}
break;
case 0x20004:
case 0x660004:
{
reader.ReadInt32( ref Skill );
}
break;
case 0x20005:
{
reader.ReadInt32( ref Buff );
}
break;
case 0x6c0006:
{
reader.ReadString( ref TagList );
}
break;
default:
{
reader.SkipFiled(tag);
}
break;
}
}
}
Expand Down Expand Up @@ -86,11 +103,16 @@ public void Deserialize( tabtoy.TableReader reader )
reader.ReadUInt16( ref ServerPort );
}
break;
case 0x20002:
case 0x660002:
{
reader.ReadInt32( ref GroupID );
}
break;
default:
{
reader.SkipFiled(tag);
}
break;
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions v3/example/golang/table_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ func (self ActorType) String() string {
}

type ExampleData struct {
ID int32 `tb_name:"任务ID"`
Name string `tb_name:"名称"`
Rate float32 `tb_name:"比例"`
Type ActorType `tb_name:"类型"`
Skill []int32 `tb_name:"技能列表"`
ID int32 `tb_name:"任务ID"`
Name string `tb_name:"名称"`
Rate float32 `tb_name:"比例"`
Type ActorType `tb_name:"类型"`
Skill []int32 `tb_name:"技能列表"`
Buff int32 `tb_name:"增益"`
TagList []string `tb_name:"标记"`
}

type ExampleKV struct {
Expand Down
8 changes: 4 additions & 4 deletions v3/example/java/cfg/table_gen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"@Tool": "github.com/davyxu/tabtoy",
"@Version": "2.9.2",
"ExampleData":[
{ "ID": 100, "Name": "扎克镇", "Rate": 3.14, "Type": 2, "Skill": [3,1,2] },
{ "ID": 200, "Name": "阿努比斯神庙", "Rate": 1.2, "Type": 1, "Skill": [0,90] },
{ "ID": 300, "Name": "花村", "Rate": 79.4, "Type": 3, "Skill": [0] },
{ "ID": 400, "Name": "艾兴瓦尔德", "Rate": 0.63, "Type": 4, "Skill": [0] }
{ "ID": 100, "Name": "扎克镇", "Rate": 3.14, "Type": 2, "Skill": [3,1,2], "Buff": 100, "TagList": ["a","b"] },
{ "ID": 200, "Name": "阿努比斯神庙", "Rate": 1.2, "Type": 1, "Skill": [100,0,90], "Buff": 1, "TagList": ["c"] },
{ "ID": 300, "Name": "花村", "Rate": 79.4, "Type": 3, "Skill": [0], "Buff": 0, "TagList": [] },
{ "ID": 400, "Name": "艾兴瓦尔德", "Rate": 0.63, "Type": 4, "Skill": [0], "Buff": 0, "TagList": [] }
],
"ExampleKV":[
{ "ServerIP": "8.8.8.8", "ServerPort": 1024, "GroupID": [10,20] }
Expand Down
4 changes: 3 additions & 1 deletion v3/example/java/src/main/java/main/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public class ExampleData {
public String Name = ""; // 名称;
public float Rate = 0; // 比例;
public ActorType Type = ActorType.None; // 类型;
public int[] Skill = new int[]{}; // 技能列表;
public int[] Skill = new int[]{}; // 技能列表;
public int Buff = 0; // 增益;
public String[] TagList = new String[]{}; // 标记;
}

public class ExampleKV {
Expand Down
8 changes: 4 additions & 4 deletions v3/example/json/table_gen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"@Tool": "github.com/davyxu/tabtoy",
"@Version": "2.9.2",
"ExampleData":[
{ "ID": 100, "Name": "扎克镇", "Rate": 3.14, "Type": 2, "Skill": [3,1,2] },
{ "ID": 200, "Name": "阿努比斯神庙", "Rate": 1.2, "Type": 1, "Skill": [0,90] },
{ "ID": 300, "Name": "花村", "Rate": 79.4, "Type": 3, "Skill": [0] },
{ "ID": 400, "Name": "艾兴瓦尔德", "Rate": 0.63, "Type": 4, "Skill": [0] }
{ "ID": 100, "Name": "扎克镇", "Rate": 3.14, "Type": 2, "Skill": [3,1,2], "Buff": 100, "TagList": ["a","b"] },
{ "ID": 200, "Name": "阿努比斯神庙", "Rate": 1.2, "Type": 1, "Skill": [100,0,90], "Buff": 1, "TagList": ["c"] },
{ "ID": 300, "Name": "花村", "Rate": 79.4, "Type": 3, "Skill": [0], "Buff": 0, "TagList": [] },
{ "ID": 400, "Name": "艾兴瓦尔德", "Rate": 0.63, "Type": 4, "Skill": [0], "Buff": 0, "TagList": [] }
],
"ExampleKV":[
{ "ServerIP": "8.8.8.8", "ServerPort": 1024, "GroupID": [10,20] }
Expand Down
8 changes: 4 additions & 4 deletions v3/example/lua/table_gen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
-- Version: 2.9.2
local tab = {
ExampleData = {
{ ID = 100, Name = "扎克镇", Rate = 3.14, Type = 2, Skill = {3,1,2}, },
{ ID = 200, Name = "阿努比斯神庙", Rate = 1.2, Type = 1, Skill = {0,90}, },
{ ID = 300, Name = "花村", Rate = 79.4, Type = 3, Skill = {0}, },
{ ID = 400, Name = "艾兴瓦尔德", Rate = 0.63, Type = 4, Skill = {0}, },
{ ID = 100, Name = "扎克镇", Rate = 3.14, Type = 2, Skill = {3,1,2}, Buff = 100, TagList = {"a","b"}, },
{ ID = 200, Name = "阿努比斯神庙", Rate = 1.2, Type = 1, Skill = {100,0,90}, Buff = 1, TagList = {"c"}, },
{ ID = 300, Name = "花村", Rate = 79.4, Type = 3, Skill = {0}, Buff = 0, TagList = {}, },
{ ID = 400, Name = "艾兴瓦尔德", Rate = 0.63, Type = 4, Skill = {0}, Buff = 0, TagList = {}, },
},
ExampleKV = {
{ ServerIP = "8.8.8.8", ServerPort = 1024, GroupID = {10,20}, },
Expand Down
Binary file modified v3/example/xlsx/Data.xlsx
Binary file not shown.
2 changes: 1 addition & 1 deletion v3/example/xlsx/Run.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"c:\Program Files\Git\bin\bash.exe" --login -i .\Make.sh
"c:\Program Files\Git\bin\bash.exe" --login -i .\Run.sh
Binary file modified v3/example/xlsx/Type.xlsx
Binary file not shown.
4 changes: 4 additions & 0 deletions v3/gen/binpak/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func MakeTag(globals *model.Globals, tf *model.TypeDefine, fieldIndex int) uint3
panic("unknown type:" + tf.FieldType)
}

if tf.IsArray() {
t += 100
}

return uint32(t<<16 | fieldIndex)
}

Expand Down
5 changes: 5 additions & 0 deletions v3/gen/cssrc/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ namespace {{.PackageName}}
reader.Read{{CSReader $ $field}}( ref {{$field.FieldName}} );
}
break;{{end}}
default:
{
reader.SkipFiled(tag);
}
break;
}
}
}
Expand Down

0 comments on commit 055548f

Please sign in to comment.