Skip to content

Commit 022ebca

Browse files
committed
双精度C#端读取问题 davyxu#64
1 parent 1a13e70 commit 022ebca

File tree

14 files changed

+78
-48
lines changed

14 files changed

+78
-48
lines changed

v3/api/csharp/TableReader.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ internal enum FieldType
1818
String = 8,
1919
Bool = 9,
2020
Enum = 10,
21-
Struct =11,
21+
Struct = 11,
22+
Double = 12,
2223
}
2324

2425
public interface ITableSerializable
@@ -159,7 +160,12 @@ public void SkipFiled(UInt32 tag)
159160
this.ReadBool(ref dummy);
160161
}
161162
break;
162-
163+
case 12: // float64
164+
{
165+
double dummy = 0;
166+
this.ReadDouble(ref dummy);
167+
}
168+
break;
163169

164170
case 101: // int16
165171
{
@@ -287,6 +293,13 @@ public void ReadFloat(ref float v)
287293
v = _binaryReader.ReadSingle();
288294
}
289295

296+
public void ReadDouble(ref double v)
297+
{
298+
ValidateDataBound(sizeof(float));
299+
300+
v = _binaryReader.ReadDouble();
301+
}
302+
290303
public void ReadBool(ref bool v)
291304
{
292305
ValidateDataBound(sizeof(bool));

v3/example/csharp/TabtoyExample/table_gen.cs

+14-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public partial class ExampleData : tabtoy.ITableSerializable
1919
{
2020
public Int32 ID = 0;
2121
public string Name = string.Empty;
22-
public double Rate = 0;
22+
public float Rate = 0;
23+
public double Accuracy = 0;
2324
public ActorType Type = ActorType.None;
2425
public List<Int32> Skill = new List<Int32>();
2526
public Int32 Buff = 0;
@@ -44,32 +45,37 @@ public void Deserialize( tabtoy.TableReader reader )
4445
reader.ReadString( ref Name );
4546
}
4647
break;
47-
case 0xb0002:
48+
case 0x70002:
4849
{
49-
reader.Readdouble( ref Rate );
50+
reader.ReadFloat( ref Rate );
5051
}
5152
break;
52-
case 0xa0003:
53+
case 0xc0003:
54+
{
55+
reader.ReadDouble( ref Accuracy );
56+
}
57+
break;
58+
case 0xa0004:
5359
{
5460
reader.ReadEnum( ref Type );
5561
}
5662
break;
57-
case 0x660004:
63+
case 0x660005:
5864
{
5965
reader.ReadInt32( ref Skill );
6066
}
6167
break;
62-
case 0x20005:
68+
case 0x20006:
6369
{
6470
reader.ReadInt32( ref Buff );
6571
}
6672
break;
67-
case 0x6c0006:
73+
case 0x6c0007:
6874
{
6975
reader.ReadString( ref TagList );
7076
}
7177
break;
72-
case 0x660007:
78+
case 0x660008:
7379
{
7480
reader.ReadInt32( ref Multi );
7581
}

v3/example/csv/Data.csv

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
ID,����,����,�����б�,����,�����б�,�����б�,����,���,����,����
2-
100,������,3.14,3,����,1,2,100,a|b,1,3
3-
200,��Ŭ��˹����,1.2,100,����,,90,1,c,4,
4-
,,,,,,,,,,
5-
,,,,,,,,,,
6-
,,,,,,,,,,
7-
,,,,,,,,,,
8-
,,,,,,,,,,
9-
,,,,,,,,,,
10-
,,,,,,,,,,
11-
,,,,,,,,,,
12-
,,,,,,,,,,
13-
,,,,,,,,,,
14-
,,,,,,,,,,
1+
ID,����,����,����,�����б�,����,�����б�,�����б�,����,���,����,����
2+
100,������,3.14,1.602176,3,����,1,2,100,a|b,1,3
3+
200,��Ŭ��˹����,1.2,3.14159,100,����,,90,1,c,4,
4+
,,,,,,,,,,,
5+
,,,,,,,,,,,
6+
,,,,,,,,,,,
7+
,,,,,,,,,,,
8+
,,,,,,,,,,,
9+
,,,,,,,,,,,
10+
,,,,,,,,,,,
11+
,,,,,,,,,,,
12+
,,,,,,,,,,,
13+
,,,,,,,,,,,
14+
,,,,,,,,,,,

v3/example/csv/Type.csv

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
��ͷ,ExampleData,����ID,ID,int,,,��,,,
33
��ͷ,ExampleData,����,Name,string,,,,,,
44
��ͷ,ExampleData,����,Rate,float,,,,,,
5+
��ͷ,ExampleData,����,Accuracy,double,,,,,,
56
��ͷ,ExampleData,����,Type,ActorType,,,,,,
67
��ͷ,ExampleData,�����б�,Skill,int,|,,,,,
78
��ͷ,ExampleData,����,Buff,int,,,,���ֶ����ڲ��Զ�������������,,

v3/example/golang/table_gen.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ func (self ActorType) String() string {
3636
}
3737

3838
type ExampleData struct {
39-
ID int32 `tb_name:"任务ID"`
40-
Name string `tb_name:"名称"`
41-
Rate float64 `tb_name:"比例"`
42-
Type ActorType `tb_name:"类型"`
43-
Skill []int32 `tb_name:"技能列表"`
44-
Buff int32 `tb_name:"增益"`
45-
TagList []string `tb_name:"标记"`
46-
Multi []int32 `tb_name:"多列"`
39+
ID int32 `tb_name:"任务ID"`
40+
Name string `tb_name:"名称"`
41+
Rate float32 `tb_name:"比例"`
42+
Accuracy float64 `tb_name:"精度"`
43+
Type ActorType `tb_name:"类型"`
44+
Skill []int32 `tb_name:"技能列表"`
45+
Buff int32 `tb_name:"增益"`
46+
TagList []string `tb_name:"标记"`
47+
Multi []int32 `tb_name:"多列"`
4748
}
4849

4950
type ExtendData struct {

v3/example/java/cfg/table_gen.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"@Tool": "github.com/davyxu/tabtoy",
3-
"@Version": "3.0.0",
3+
"@Version": "3.0.1",
44
"ExampleData":[
5-
{ "ID": 100, "Name": "扎克镇", "Rate": 3.14, "Type": 2, "Skill": [3,1,2], "Buff": 100, "TagList": ["a","b"], "Multi": [1,3] },
6-
{ "ID": 200, "Name": "阿努比斯神庙", "Rate": 1.2, "Type": 1, "Skill": [100,0,90], "Buff": 1, "TagList": ["c"], "Multi": [4,0] },
7-
{ "ID": 300, "Name": "花村", "Rate": 79.4, "Type": 3, "Skill": [], "Buff": 0, "TagList": [], "Multi": [] },
8-
{ "ID": 400, "Name": "艾兴瓦尔德", "Rate": 0.63, "Type": 4, "Skill": [], "Buff": 0, "TagList": [], "Multi": [] }
5+
{ "ID": 100, "Name": "扎克镇", "Rate": 3.14, "Accuracy": 1.602176, "Type": 2, "Skill": [3,1,2], "Buff": 100, "TagList": ["a","b"], "Multi": [1,3] },
6+
{ "ID": 200, "Name": "阿努比斯神庙", "Rate": 1.2, "Accuracy": 3.14159, "Type": 1, "Skill": [100,0,90], "Buff": 1, "TagList": ["c"], "Multi": [4,0] },
7+
{ "ID": 300, "Name": "花村", "Rate": 79.4, "Accuracy": 0, "Type": 3, "Skill": [], "Buff": 0, "TagList": [], "Multi": [] },
8+
{ "ID": 400, "Name": "艾兴瓦尔德", "Rate": 0.63, "Accuracy": 0, "Type": 4, "Skill": [], "Buff": 0, "TagList": [], "Multi": [] }
99
],
1010
"ExtendData":[
1111
{ "Additive": 1.1 },

v3/example/java/src/main/java/main/Table.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public static ActorType fromInt( int v ){
4747
public class ExampleData {
4848
public int ID = 0; // 任务ID;
4949
public String Name = ""; // 名称;
50-
public double Rate = 0; // 比例;
50+
public float Rate = 0; // 比例;
51+
public double Accuracy = 0; // 精度;
5152
public ActorType Type = ActorType.None; // 类型;
5253
public int[] Skill = new int[]{}; // 技能列表;
5354
public int Buff = 0; // 增益;

v3/example/json/table_gen.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"@Tool": "github.com/davyxu/tabtoy",
33
"@Version": "3.0.1",
44
"ExampleData":[
5-
{ "ID": 100, "Name": "扎克镇", "Rate": 3.14, "Type": 2, "Skill": [3,1,2], "Buff": 100, "TagList": ["a","b"], "Multi": [1,3] },
6-
{ "ID": 200, "Name": "阿努比斯神庙", "Rate": 1.2, "Type": 1, "Skill": [100,0,90], "Buff": 1, "TagList": ["c"], "Multi": [4,0] },
7-
{ "ID": 300, "Name": "花村", "Rate": 79.4, "Type": 3, "Skill": [], "Buff": 0, "TagList": [], "Multi": [] },
8-
{ "ID": 400, "Name": "艾兴瓦尔德", "Rate": 0.63, "Type": 4, "Skill": [], "Buff": 0, "TagList": [], "Multi": [] }
5+
{ "ID": 100, "Name": "扎克镇", "Rate": 3.14, "Accuracy": 1.602176, "Type": 2, "Skill": [3,1,2], "Buff": 100, "TagList": ["a","b"], "Multi": [1,3] },
6+
{ "ID": 200, "Name": "阿努比斯神庙", "Rate": 1.2, "Accuracy": 3.14159, "Type": 1, "Skill": [100,0,90], "Buff": 1, "TagList": ["c"], "Multi": [4,0] },
7+
{ "ID": 300, "Name": "花村", "Rate": 79.4, "Accuracy": 0, "Type": 3, "Skill": [], "Buff": 0, "TagList": [], "Multi": [] },
8+
{ "ID": 400, "Name": "艾兴瓦尔德", "Rate": 0.63, "Accuracy": 0, "Type": 4, "Skill": [], "Buff": 0, "TagList": [], "Multi": [] }
99
],
1010
"ExtendData":[
1111
{ "Additive": 1.1 },

v3/example/jsontype/type_gen.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"@Tool": "github.com/davyxu/tabtoy",
3-
"@Version": "3.0.0",
3+
"@Version": "3.0.1",
44
"Objects": [
55
{
66
"Name": "ActorType",
@@ -58,6 +58,11 @@
5858
"Type": "float",
5959
"Comment": "比例"
6060
},
61+
{
62+
"Name": "Accuracy",
63+
"Type": "double",
64+
"Comment": "精度"
65+
},
6166
{
6267
"Name": "Type",
6368
"Type": "ActorType",

v3/example/lua/table_gen.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
-- Version: 3.0.1
33
local tab = {
44
ExampleData = {
5-
{ ID = 100, Name = "扎克镇", Rate = 3.14, Type = 2, Skill = [3,1,2], Buff = 100, TagList = ["a","b"], Multi = [1,3], },
6-
{ ID = 200, Name = "阿努比斯神庙", Rate = 1.2, Type = 1, Skill = [100,0,90], Buff = 1, TagList = ["c"], Multi = [4,0], },
7-
{ ID = 300, Name = "花村", Rate = 79.4, Type = 3, Skill = [], Buff = 0, TagList = [], Multi = [], },
8-
{ ID = 400, Name = "艾兴瓦尔德", Rate = 0.63, Type = 4, Skill = [], Buff = 0, TagList = [], Multi = [], },
5+
{ ID = 100, Name = "扎克镇", Rate = 3.14, Accuracy = 1.602176, Type = 2, Skill = [3,1,2], Buff = 100, TagList = ["a","b"], Multi = [1,3], },
6+
{ ID = 200, Name = "阿努比斯神庙", Rate = 1.2, Accuracy = 3.14159, Type = 1, Skill = [100,0,90], Buff = 1, TagList = ["c"], Multi = [4,0], },
7+
{ ID = 300, Name = "花村", Rate = 79.4, Accuracy = 0, Type = 3, Skill = [], Buff = 0, TagList = [], Multi = [], },
8+
{ ID = 400, Name = "艾兴瓦尔德", Rate = 0.63, Accuracy = 0, Type = 4, Skill = [], Buff = 0, TagList = [], Multi = [], },
99
},
1010
ExtendData = {
1111
{ Additive = 1.1, },

v3/example/xlsx/Data.xlsx

74 Bytes
Binary file not shown.

v3/example/xlsx/Type.xlsx

57 Bytes
Binary file not shown.

v3/gen/bindata/tag.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ func MakeTag(globals *model.Globals, tf *model.TypeDefine, fieldIndex int) uint3
3030
case globals.Types.IsEnumKind(tf.FieldType):
3131
t = 10
3232
case convertedType == "float64":
33-
t = 11
33+
t = 12
34+
// 注意, t = 11是结构体
3435
default:
3536
panic("unknown type:" + tf.FieldType)
3637
}

v3/gen/cssrc/func.go

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ func init() {
7979
switch {
8080
case convertedType == "float":
8181
ret = "Float"
82+
case convertedType == "double":
83+
ret = "Double"
8284
case convertedType == "string":
8385
ret = "String"
8486
case convertedType == "bool":

0 commit comments

Comments
 (0)