1
This commit is contained in:
parent
a10ae56c4f
commit
16f6ac3f01
52
metamgr.go
52
metamgr.go
@ -1,5 +1,16 @@
|
|||||||
package f5
|
package f5
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"bufio"
|
||||||
|
"strings"
|
||||||
|
"reflect"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
|
"github.com/golang/protobuf/jsonpb"
|
||||||
|
)
|
||||||
|
|
||||||
type MetaClass struct {
|
type MetaClass struct {
|
||||||
FileName string
|
FileName string
|
||||||
Idx int
|
Idx int
|
||||||
@ -10,7 +21,7 @@ type MetaClass struct {
|
|||||||
|
|
||||||
type MetaMgr struct {
|
type MetaMgr struct {
|
||||||
metaClasses *[]MetaClass
|
metaClasses *[]MetaClass
|
||||||
rawData []interface{}
|
rawList []interface{}
|
||||||
wrapList []interface{}
|
wrapList []interface{}
|
||||||
wrapIdHash []map[int32]interface{}
|
wrapIdHash []map[int32]interface{}
|
||||||
wrapNameHash []map[string]interface{}
|
wrapNameHash []map[string]interface{}
|
||||||
@ -29,9 +40,44 @@ func (this *MetaMgr) RegisterMetaClasses(metaClasses *[]MetaClass) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *MetaMgr) Load() {
|
func (this *MetaMgr) Load() {
|
||||||
for k, _ := range this.rawData {
|
this.rawList = make([]interface{}, len(*this.metaClasses))
|
||||||
_ = this.wrapList[k]
|
this.wrapList = make([]interface{}, len(*this.metaClasses))
|
||||||
|
for key, val := range *this.metaClasses {
|
||||||
|
f, _ := os.Open(val.FileName)
|
||||||
|
data, _ := bufio.NewReader(f).ReadString(0)
|
||||||
|
data = "{\"values\":" + data
|
||||||
|
data += "}"
|
||||||
|
|
||||||
|
u := jsonpb.Unmarshaler{AllowUnknownFields: true}
|
||||||
|
msgType := reflect.TypeOf(val.RawMeta).Elem()
|
||||||
|
msg := reflect.New(msgType)
|
||||||
|
msgPb := msg.Interface().(proto.Message)
|
||||||
|
err := u.Unmarshal(strings.NewReader(data), msgPb)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wrapMsgType := reflect.TypeOf(val.WrapMeta)
|
||||||
|
wrapMsgList := reflect.MakeSlice(reflect.SliceOf(wrapMsgType), 0, 100)
|
||||||
|
|
||||||
|
this.rawList[key] = msg
|
||||||
|
this.wrapList[key] = wrapMsgList
|
||||||
|
|
||||||
|
this.wrapMeta(msg, wrapMsgList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *MetaMgr) wrapMeta(rawMeta reflect.Value, wrapMetaList reflect.Value) {
|
||||||
|
values := rawMeta.Elem().FieldByName("Values")
|
||||||
|
for i := 0; i < values.Len(); i++ {
|
||||||
|
val := values.Index(i)
|
||||||
|
clsName := reflect.TypeOf(val.Elem().Interface()).Name()
|
||||||
|
wrapMeta := reflect.New(reflect.TypeOf(wrapMetaList.Interface()).Elem().Elem())
|
||||||
|
serverInfo := wrapMeta.Elem().FieldByName(clsName)
|
||||||
|
serverInfo.Set(val)
|
||||||
|
wrapMetaList = reflect.Append(wrapMetaList, wrapMeta)
|
||||||
|
}
|
||||||
|
fmt.Println(wrapMetaList)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MetaMgr) GetMetaById(idx int, id int32) interface{} {
|
func (this *MetaMgr) GetMetaById(idx int, id int32) interface{} {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user