新增options来配置

This commit is contained in:
bense
2024-10-03 02:11:09 +08:00
parent bfff0f62be
commit 432b27f52b
11 changed files with 119 additions and 99 deletions

View File

@@ -3,7 +3,6 @@ package proto
import (
"bytes"
"encoding/binary"
"github.com/bensema/gotdx/util"
)
type GetSecurityList struct {
@@ -88,7 +87,7 @@ func (obj *GetSecurityList) UnSerialize(header interface{}, data []byte) error {
binary.Read(bytes.NewBuffer(data[pos:pos+8]), binary.LittleEndian, &name)
pos += 8
ele.Name = util.Utf8ToGbk(name[:])
ele.Name = Utf8ToGbk(name[:])
pos += 4
binary.Read(bytes.NewBuffer(data[pos:pos+1]), binary.LittleEndian, &ele.DecimalPoint)

View File

@@ -5,7 +5,6 @@ import (
"encoding/binary"
"encoding/hex"
"fmt"
"github.com/bensema/gotdx/util"
)
type GetSecurityQuotes struct {
@@ -146,7 +145,7 @@ func (obj *GetSecurityQuotes) UnSerialize(header interface{}, data []byte) error
binary.Read(bytes.NewBuffer(data[pos:pos+6]), binary.LittleEndian, &code)
//enc := mahonia.NewDecoder("gbk")
//ele.Code = enc.ConvertString(string(code[:]))
ele.Code = util.Utf8ToGbk(code[:])
ele.Code = Utf8ToGbk(code[:])
pos += 6
binary.Read(bytes.NewBuffer(data[pos:pos+2]), binary.LittleEndian, &ele.Active1)
pos += 2

View File

@@ -4,7 +4,6 @@ import (
"bytes"
"encoding/binary"
"encoding/hex"
"github.com/bensema/gotdx/util"
)
type Hello1 struct {
@@ -60,7 +59,7 @@ func (obj *Hello1) Serialize() ([]byte, error) {
func (obj *Hello1) UnSerialize(header interface{}, data []byte) error {
obj.respHeader = header.(*RespHeader)
serverInfo := util.Utf8ToGbk(data[68:])
serverInfo := Utf8ToGbk(data[68:])
obj.reply.Info = serverInfo
return nil

View File

@@ -4,7 +4,6 @@ import (
"bytes"
"encoding/binary"
"encoding/hex"
"github.com/bensema/gotdx/util"
)
type Hello2 struct {
@@ -57,7 +56,7 @@ func (obj *Hello2) Serialize() ([]byte, error) {
func (obj *Hello2) UnSerialize(header interface{}, data []byte) error {
obj.respHeader = header.(*RespHeader)
serverInfo := util.Utf8ToGbk(data[58:])
serverInfo := Utf8ToGbk(data[58:])
//fmt.Println(hex.EncodeToString(data))
obj.reply.Info = serverInfo
return nil

20
proto/util.go Normal file
View File

@@ -0,0 +1,20 @@
package proto
import (
"bytes"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
"io/ioutil"
"strings"
)
func Utf8ToGbk(text []byte) string {
r := bytes.NewReader(text)
decoder := transform.NewReader(r, simplifiedchinese.GBK.NewDecoder()) //GB18030
content, _ := ioutil.ReadAll(decoder)
return strings.ReplaceAll(string(content), string([]byte{0x00}), "")
}