mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 14:42:26 +08:00
协议代理生成补充修改
This commit is contained in:
@@ -33,8 +33,8 @@ func TestClientProtoGen(t *testing.T) {
|
|||||||
clientCmdData := string(clientCmdFile)
|
clientCmdData := string(clientCmdFile)
|
||||||
clientCmdLineList := strings.Split(clientCmdData, "\n")
|
clientCmdLineList := strings.Split(clientCmdData, "\n")
|
||||||
// 生成代码文件
|
// 生成代码文件
|
||||||
var fileDataBuilder strings.Builder
|
var fileDataBuffer bytes.Buffer
|
||||||
fileDataBuilder.WriteString(`package client_proto
|
fileDataBuffer.WriteString(`package client_proto
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"hk4e/gate/client_proto/proto"
|
"hk4e/gate/client_proto/proto"
|
||||||
@@ -54,32 +54,32 @@ func (c *ClientCmdProtoMap) LoadClientCmdIdAndCmdName() {
|
|||||||
}
|
}
|
||||||
cmdName := item[0]
|
cmdName := item[0]
|
||||||
cmdId := item[1]
|
cmdId := item[1]
|
||||||
_, err = fmt.Fprintf(&fileDataBuilder, ` c.clientCmdIdCmdNameMap[uint16(%s)] = "%s"
|
_, err = fmt.Fprintf(&fileDataBuffer, ` c.clientCmdIdCmdNameMap[uint16(%s)] = "%s"
|
||||||
c.clientCmdNameCmdIdMap["%s"] = uint16(%s)
|
c.clientCmdNameCmdIdMap["%s"] = uint16(%s)
|
||||||
`, cmdId, cmdName, cmdName, cmdId)
|
`, cmdId, cmdName, cmdName, cmdId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fileDataBuilder.WriteString(`}
|
fileDataBuffer.WriteString(`}
|
||||||
|
|
||||||
func (c *ClientCmdProtoMap) GetClientProtoObjByName(protoObjName string) any {
|
func (c *ClientCmdProtoMap) GetClientProtoObjByName(protoObjName string) any {
|
||||||
switch protoObjName {
|
switch protoObjName {
|
||||||
`)
|
`)
|
||||||
for _, protoObjName := range protoObjNameList {
|
for _, protoObjName := range protoObjNameList {
|
||||||
_, err = fmt.Fprintf(&fileDataBuilder, ` case "%s":
|
_, err = fmt.Fprintf(&fileDataBuffer, ` case "%s":
|
||||||
return new(proto.%s)
|
return new(proto.%s)
|
||||||
`, protoObjName, protoObjName)
|
`, protoObjName, protoObjName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fileDataBuilder.WriteString(` default:
|
fileDataBuffer.WriteString(` default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
err = os.WriteFile("./client_proto_gen.go", []byte(fileDataBuilder.String()), 0644)
|
err = os.WriteFile("./client_proto_gen.go", []byte(fileDataBuffer.String()), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -91,10 +91,10 @@ func (c *ClientCmdProtoMap) GetClientProtoObjByName(protoObjName string) any {
|
|||||||
}
|
}
|
||||||
rawFileStr := string(rawFileData)
|
rawFileStr := string(rawFileData)
|
||||||
rawFileLine := strings.Split(rawFileStr, "\n")
|
rawFileLine := strings.Split(rawFileStr, "\n")
|
||||||
var newFileBuilder bytes.Buffer
|
var newFileBuffer bytes.Buffer
|
||||||
for i := 0; i < len(rawFileLine); i++ {
|
for i := 0; i < len(rawFileLine); i++ {
|
||||||
line := rawFileLine[i]
|
line := rawFileLine[i]
|
||||||
newFileBuilder.WriteString(line + "\n")
|
newFileBuffer.WriteString(line + "\n")
|
||||||
if !strings.Contains(line, "enum") {
|
if !strings.Contains(line, "enum") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ func (c *ClientCmdProtoMap) GetClientProtoObjByName(protoObjName string) any {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, ref := range refEnum {
|
for _, ref := range refEnum {
|
||||||
newFileBuilder.WriteString(ref + "\n")
|
newFileBuffer.WriteString(ref + "\n")
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
for {
|
for {
|
||||||
@@ -117,12 +117,12 @@ func (c *ClientCmdProtoMap) GetClientProtoObjByName(protoObjName string) any {
|
|||||||
if !strings.Contains(nextLine, "}") {
|
if !strings.Contains(nextLine, "}") {
|
||||||
i++
|
i++
|
||||||
} else {
|
} else {
|
||||||
newFileBuilder.WriteString(nextLine + "\n")
|
newFileBuffer.WriteString(nextLine + "\n")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = os.WriteFile("./proto/"+entry.Name(), newFileBuilder.Bytes(), 0644)
|
err = os.WriteFile("./proto/"+entry.Name(), newFileBuffer.Bytes(), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user