121 lines
3.7 KiB
Plaintext
121 lines
3.7 KiB
Plaintext
{{define "gpb_mgr"}}
|
|
// Code generated by xlsx2proto.
|
|
// DO NOT EDIT!
|
|
|
|
package srvdata
|
|
|
|
import (
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
"mongo.games.com/game/protocol/server"
|
|
)
|
|
|
|
var PB{{.ProtoName}}Mgr = &{{.ProtoName}}Mgr{
|
|
Datas: &server.{{.ProtoName}}Array{},
|
|
pool: make(map[int32]*server.{{.ProtoName}}),
|
|
{{ range $index, $col := .Cols }}{{ if $col.IsIndex }}
|
|
{{ if eq $col.ColType 1 }}{{$col.ColName}}: make(map[int32][]*server.{{$.ProtoName}}),
|
|
{{ else if eq $col.ColType 5 }}{{$col.ColName}}: make(map[int64][]*server.{{$.ProtoName}}),
|
|
{{ else if eq $col.ColType 2 }}{{$col.ColName}}: make(map[string][]*server.{{$.ProtoName}}),
|
|
{{end}}{{end}}{{end}}
|
|
}
|
|
|
|
type {{.ProtoName}}Mgr struct {
|
|
Datas *server.{{.ProtoName}}Array
|
|
pool map[int32]*server.{{.ProtoName}}
|
|
{{ range $index, $col := .Cols }}{{ if $col.IsIndex }}
|
|
{{ if eq $col.ColType 1 }}{{$col.ColName}} map[int32][]*server.{{$.ProtoName}}
|
|
{{ else if eq $col.ColType 5 }}{{$col.ColName}} map[int64][]*server.{{$.ProtoName}}
|
|
{{ else if eq $col.ColType 2 }}{{$col.ColName}} map[string][]*server.{{$.ProtoName}}
|
|
{{end}}{{end}}{{end}}
|
|
}
|
|
|
|
func (this *{{.ProtoName}}Mgr) unmarshal(data []byte) error {
|
|
err := proto.Unmarshal(data, this.Datas)
|
|
if err == nil {
|
|
this.arrangeData()
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (this *{{.ProtoName}}Mgr) reunmarshal(data []byte) error {
|
|
newDatas := &server.{{.ProtoName}}Array{}
|
|
err := proto.Unmarshal(data, newDatas)
|
|
if err == nil {
|
|
for _, item := range newDatas.Arr {
|
|
existItem := this.GetData(item.GetId())
|
|
if existItem == nil {
|
|
this.pool[item.GetId()] = item
|
|
this.Datas.Arr = append(this.Datas.Arr, item)
|
|
{{ range $index, $col := .Cols }}{{ if $col.IsIndex }}
|
|
this.{{$col.ColName}}[item.Get{{$col.ColName}}()] = append(this.{{$col.ColName}}[item.Get{{$col.ColName}}()], item)
|
|
{{end}}{{end}}
|
|
} else {
|
|
*existItem = *item
|
|
}
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (this *{{.ProtoName}}Mgr) arrangeData() {
|
|
if this.Datas == nil {
|
|
return
|
|
}
|
|
|
|
dataArr := this.Datas.GetArr()
|
|
if dataArr == nil {
|
|
return
|
|
}
|
|
|
|
for _, data := range dataArr {
|
|
this.pool[data.GetId()] = data
|
|
{{ range $index, $col := .Cols }}{{ if $col.IsIndex }}
|
|
this.{{$col.ColName}}[data.Get{{$col.ColName}}()] = append(this.{{$col.ColName}}[data.Get{{$col.ColName}}()], data)
|
|
{{end}}{{end}}
|
|
}
|
|
}
|
|
|
|
func (this *{{.ProtoName}}Mgr) GetData(id int32) *server.{{.ProtoName}} {
|
|
if data, ok := this.pool[id]; ok {
|
|
return data
|
|
}
|
|
return nil
|
|
}
|
|
{{ range $index, $col := .Cols }}{{ if $col.IsIndex }}
|
|
{{ if eq $col.ColType 1 }}func (this *{{$.ProtoName}}Mgr) Get{{$col.ColName}}(id int32) *server.{{$.ProtoName}} {
|
|
arr := this.{{$col.ColName}}[id]
|
|
if len(arr) == 0 {
|
|
return nil
|
|
}
|
|
return arr[0]
|
|
}
|
|
{{ else if eq $col.ColType 5 }}func (this *{{$.ProtoName}}Mgr) Get{{$col.ColName}}(id int64) *server.{{$.ProtoName}} {
|
|
arr := this.{{$col.ColName}}[id]
|
|
if len(arr) == 0 {
|
|
return nil
|
|
}
|
|
return arr[0]
|
|
}
|
|
{{ else if eq $col.ColType 2 }}func (this *{{$.ProtoName}}Mgr) Get{{$col.ColName}}(id string) *server.{{$.ProtoName}} {
|
|
arr := this.{{$col.ColName}}[id]
|
|
if len(arr) == 0 {
|
|
return nil
|
|
}
|
|
return arr[0]
|
|
}
|
|
{{end}}
|
|
{{ if eq $col.ColType 1 }}func (this *{{$.ProtoName}}Mgr) Get{{$col.ColName}}Arr(id int32) []*server.{{$.ProtoName}} {
|
|
return this.{{$col.ColName}}[id]
|
|
}
|
|
{{ else if eq $col.ColType 5 }}func (this *{{$.ProtoName}}Mgr) Get{{$col.ColName}}Arr(id int64) []*server.{{$.ProtoName}} {
|
|
return this.{{$col.ColName}}[id]
|
|
}
|
|
{{ else if eq $col.ColType 2 }}func (this *{{$.ProtoName}}Mgr) Get{{$col.ColName}}Arr(id string) []*server.{{$.ProtoName}} {
|
|
return this.{{$col.ColName}}[id]
|
|
}{{end}}{{end}}{{end}}
|
|
|
|
func init() {
|
|
DataMgr.register("{{.ProtoName}}.dat", &ProtobufDataLoader{dh: PB{{.ProtoName}}Mgr})
|
|
}
|
|
{{end}} |