Skip to content

Commit

Permalink
C#支持TableReader设置ConvertNewLine将字符串字段将各种转义符恢复转义
Browse files Browse the repository at this point in the history
  • Loading branch information
davyxu committed Dec 3, 2020
1 parent 7f4b657 commit 461f555
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 12 deletions.
13 changes: 12 additions & 1 deletion v3/api/csharp/TableReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class TableReader
BinaryReader _binaryReader;
long _boundPos;

// 将字符串中的"\n"转换为\n
public bool ConvertNewLine { get; set; }

public TableReader(Stream stream)
{
_binaryReader = new BinaryReader(stream);
Expand All @@ -47,6 +50,7 @@ public TableReader(Stream stream, long boundpos)

public TableReader(TableReader reader, long boundpos)
{
ConvertNewLine = reader.ConvertNewLine;
_binaryReader = reader._binaryReader;
_boundPos = boundpos;
}
Expand Down Expand Up @@ -315,6 +319,13 @@ public void ReadString(ref string v)
ValidateDataBound(sizeof(Byte) * len);

v = encoding.GetString(_binaryReader.ReadBytes((int)len));

if (ConvertNewLine)
{

v = v.Replace("\\n", "\n");
}

}

public void ReadEnum<T>(ref T v)
Expand Down Expand Up @@ -413,7 +424,7 @@ public void ReadEnum<T>(ref List<T> v)

for (int i = 0; i < len; i++)
{
T element = default(T);
T element = default;
ReadStruct<T>(ref element);
v.Add(element);
}
Expand Down
1 change: 0 additions & 1 deletion v3/example/csharp/TabtoyExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ static void LoadAllTable()

var reader = new tabtoy.TableReader(stream);


var tab = new main.Table();

try
Expand Down
4 changes: 2 additions & 2 deletions v3/example/csharp/TabtoyExample/table_gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void Deserialize( tabtoy.TableReader reader )

public partial class ExampleKV : tabtoy.ITableSerializable
{
public string ServerIP() = string.Empty;
public string ServerIP = string.Empty;
public UInt16 ServerPort = 0;
public List<Int32> GroupID = new List<Int32>();

Expand All @@ -137,7 +137,7 @@ public void Deserialize( tabtoy.TableReader reader )
{
case 0x80000:
{
reader.ReadString( ref ServerIP() );
reader.ReadString( ref ServerIP );
}
break;
case 0x40001:
Expand Down
2 changes: 1 addition & 1 deletion v3/example/golang/table_gen.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Generated by github.com/davyxu/tabtoy
// DO NOT EDIT!!
// Version: 3.1.0
// Version:
package main

import "errors"
Expand Down
2 changes: 1 addition & 1 deletion v3/example/java/cfg/table_gen.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"@Tool": "github.com/davyxu/tabtoy",
"@Version": "3.1.0",
"@Version": "",
"ExampleData": [
{
"Accuracy": 1.602176,
Expand Down
2 changes: 1 addition & 1 deletion v3/example/java/src/main/java/main/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class ExtendData {
}

public class ExampleKV {
public String ServerIP() = ""; // 服务器IP;
public String ServerIP = ""; // 服务器IP;
public int ServerPort = 0; // 服务器端口;
public int[] GroupID = new int[]{}; // 分组;
}
Expand Down
2 changes: 1 addition & 1 deletion v3/example/json/table_gen.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
10,
20
],
"ServerIP()": "8.8.8.8",
"ServerIP": "8.8.8.8",
"ServerPort": 1024
}
],
Expand Down
2 changes: 1 addition & 1 deletion v3/example/jsondir/ExampleKV.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
10,
20
],
"ServerIP()": "8.8.8.8",
"ServerIP": "8.8.8.8",
"ServerPort": 1024
}
]
Expand Down
2 changes: 1 addition & 1 deletion v3/example/lua/table_gen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ return {
}

g.ExampleKV = {
{ ServerIP() = "8.8.8.8", ServerPort = 1024, GroupID = {10,20}, },
{ ServerIP = "8.8.8.8", ServerPort = 1024, GroupID = {10,20}, },
}


Expand Down
2 changes: 1 addition & 1 deletion v3/example/luadir/ExampleKV.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
return {
init = function( g )
g.ExampleKV = {
{ ServerIP() = "8.8.8.8", ServerPort = 1024, GroupID = {10,20}, },
{ ServerIP = "8.8.8.8", ServerPort = 1024, GroupID = {10,20}, },
}

return g
Expand Down
2 changes: 1 addition & 1 deletion v3/example/protobuf/table.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ message ExtendData

message ExampleKV
{
string ServerIP() = 1;
string ServerIP = 1;
uint32 ServerPort = 2;
repeated int32 GroupID = 3;
}
Expand Down

0 comments on commit 461f555

Please sign in to comment.