1
This commit is contained in:
parent
2b0fde225f
commit
9f7943ca94
5
go.mod
5
go.mod
@ -1,3 +1,6 @@
|
||||
module f5
|
||||
|
||||
require github.com/golang/protobuf v1.4.2
|
||||
require (
|
||||
github.com/golang/protobuf v1.4.2
|
||||
google.golang.org/protobuf v1.23.0
|
||||
)
|
||||
|
@ -10,6 +10,7 @@ It is generated from these files:
|
||||
im_proto.proto
|
||||
|
||||
It has these top-level messages:
|
||||
MFTuple
|
||||
IMSocketConnect
|
||||
IMSocketDisconnect
|
||||
*/
|
||||
|
@ -45,18 +45,36 @@ func (x *ConstantE) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
func (ConstantE) EnumDescriptor() ([]byte, []int) { return fileDescriptor1, []int{0} }
|
||||
|
||||
type MFTuple struct {
|
||||
Values []string `protobuf:"bytes,1,rep,name=values" json:"values,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *MFTuple) Reset() { *m = MFTuple{} }
|
||||
func (m *MFTuple) String() string { return proto.CompactTextString(m) }
|
||||
func (*MFTuple) ProtoMessage() {}
|
||||
func (*MFTuple) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{0} }
|
||||
|
||||
func (m *MFTuple) GetValues() []string {
|
||||
if m != nil {
|
||||
return m.Values
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type IMSocketConnect struct {
|
||||
IsWebsocket *bool `protobuf:"varint,1,opt,name=is_websocket" json:"is_websocket,omitempty"`
|
||||
Host *string `protobuf:"bytes,2,opt,name=host" json:"host,omitempty"`
|
||||
Url *string `protobuf:"bytes,3,opt,name=url" json:"url,omitempty"`
|
||||
QueryStr *string `protobuf:"bytes,4,opt,name=query_str" json:"query_str,omitempty"`
|
||||
Tuples []*MFTuple `protobuf:"bytes,5,rep,name=tuples" json:"tuples,omitempty"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
|
||||
func (m *IMSocketConnect) Reset() { *m = IMSocketConnect{} }
|
||||
func (m *IMSocketConnect) String() string { return proto.CompactTextString(m) }
|
||||
func (*IMSocketConnect) ProtoMessage() {}
|
||||
func (*IMSocketConnect) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{0} }
|
||||
func (*IMSocketConnect) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{1} }
|
||||
|
||||
func (m *IMSocketConnect) GetIsWebsocket() bool {
|
||||
if m != nil && m.IsWebsocket != nil {
|
||||
@ -86,6 +104,13 @@ func (m *IMSocketConnect) GetQueryStr() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *IMSocketConnect) GetTuples() []*MFTuple {
|
||||
if m != nil {
|
||||
return m.Tuples
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type IMSocketDisconnect struct {
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
}
|
||||
@ -93,9 +118,10 @@ type IMSocketDisconnect struct {
|
||||
func (m *IMSocketDisconnect) Reset() { *m = IMSocketDisconnect{} }
|
||||
func (m *IMSocketDisconnect) String() string { return proto.CompactTextString(m) }
|
||||
func (*IMSocketDisconnect) ProtoMessage() {}
|
||||
func (*IMSocketDisconnect) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{1} }
|
||||
func (*IMSocketDisconnect) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{2} }
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*MFTuple)(nil), "im.MFTuple")
|
||||
proto.RegisterType((*IMSocketConnect)(nil), "im.IMSocketConnect")
|
||||
proto.RegisterType((*IMSocketDisconnect)(nil), "im.IMSocketDisconnect")
|
||||
proto.RegisterEnum("im.ConstantE", ConstantE_name, ConstantE_value)
|
||||
@ -104,16 +130,18 @@ func init() {
|
||||
func init() { proto.RegisterFile("im_proto.proto", fileDescriptor1) }
|
||||
|
||||
var fileDescriptor1 = []byte{
|
||||
// 161 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xcb, 0xcc, 0x8d, 0x2f,
|
||||
0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x03, 0x93, 0x42, 0x4c, 0x99, 0xb9, 0x4a, 0xa1, 0x5c, 0xfc, 0x9e,
|
||||
0xbe, 0xc1, 0xf9, 0xc9, 0xd9, 0xa9, 0x25, 0xce, 0xf9, 0x79, 0x79, 0xa9, 0xc9, 0x25, 0x42, 0x22,
|
||||
0x5c, 0x3c, 0x99, 0xc5, 0xf1, 0xe5, 0xa9, 0x49, 0xc5, 0x60, 0x61, 0x09, 0x46, 0x05, 0x46, 0x0d,
|
||||
0x0e, 0x21, 0x1e, 0x2e, 0x96, 0x8c, 0xfc, 0xe2, 0x12, 0x09, 0x26, 0x05, 0x46, 0x0d, 0x4e, 0x21,
|
||||
0x6e, 0x2e, 0xe6, 0xd2, 0xa2, 0x1c, 0x09, 0x66, 0x30, 0x47, 0x90, 0x8b, 0xb3, 0xb0, 0x34, 0xb5,
|
||||
0xa8, 0x32, 0xbe, 0xb8, 0xa4, 0x48, 0x82, 0x05, 0x24, 0xa4, 0x24, 0xc2, 0x25, 0x04, 0x33, 0xd6,
|
||||
0x25, 0xb3, 0x38, 0x19, 0x62, 0xb2, 0x96, 0x0c, 0x17, 0x97, 0x73, 0x7e, 0x5e, 0x71, 0x49, 0x62,
|
||||
0x5e, 0x49, 0x7c, 0xaa, 0x10, 0x1f, 0x17, 0x97, 0x6f, 0x62, 0x85, 0xa7, 0xaf, 0x6f, 0x71, 0xba,
|
||||
0x67, 0x8a, 0x00, 0x3b, 0x20, 0x00, 0x00, 0xff, 0xff, 0x62, 0x1d, 0x43, 0x64, 0x9f, 0x00, 0x00,
|
||||
0x00,
|
||||
// 204 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x34, 0x8e, 0xbd, 0x4e, 0xc3, 0x30,
|
||||
0x14, 0x46, 0x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x00, 0x00, 0xff, 0xff, 0xef, 0x03, 0x9f, 0xae, 0xd7, 0x00, 0x00, 0x00,
|
||||
}
|
||||
|
@ -6,12 +6,18 @@ enum Constant_e
|
||||
MaxIMMsgId = 7;
|
||||
}
|
||||
|
||||
message MFTuple
|
||||
{
|
||||
repeated string values = 1;
|
||||
}
|
||||
|
||||
message IMSocketConnect
|
||||
{
|
||||
optional bool is_websocket = 1;
|
||||
optional string host = 2;
|
||||
optional string url = 3;
|
||||
optional string query_str = 4;
|
||||
repeated MFTuple tuples = 5;
|
||||
}
|
||||
|
||||
message IMSocketDisconnect
|
||||
|
102
metautils.go
102
metautils.go
@ -1,10 +1,102 @@
|
||||
package f5
|
||||
|
||||
func ReadCsvMetaFile(fileName string, clsName string, list interface{}) {
|
||||
//listType := reflect.TypeOf(list)
|
||||
//listElemType := listType.Elem()
|
||||
import (
|
||||
"q5"
|
||||
"os"
|
||||
"bufio"
|
||||
"reflect"
|
||||
"fmt"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoregistry"
|
||||
)
|
||||
|
||||
func ReadCsvMetaFile(fileName string, list interface{}) {
|
||||
msgType := reflect.TypeOf(list).Elem().Elem().Elem()
|
||||
|
||||
csvReader := &q5.CsvReader{}
|
||||
csvReader.Load(fileName)
|
||||
for csvReader.NextLine() {
|
||||
msg := reflect.New(msgType)
|
||||
msgPb := msg.Interface().(proto.Message)
|
||||
|
||||
msgReflect := proto.MessageReflect(msgPb)
|
||||
msgDesc := msgReflect.Descriptor()
|
||||
fields := msgDesc.Fields()
|
||||
for i := 0; i < fields.Len(); i++ {
|
||||
field := fields.Get(i)
|
||||
|
||||
value := csvReader.GetValue(string(field.Name()))
|
||||
xvalueToPBSampleField(value, field, msgReflect)
|
||||
}
|
||||
|
||||
func ReadJsonMetaFile() {
|
||||
|
||||
newList := reflect.Append(reflect.ValueOf(list), msg)
|
||||
reflect.ValueOf(list).Elem().Set(newList)
|
||||
}
|
||||
}
|
||||
|
||||
func ReadJsonMetaFile(fileName string, list interface{}) {
|
||||
msgType := reflect.TypeOf(list).Elem().Elem().Elem()
|
||||
msg := reflect.New(msgType)
|
||||
msgPb := msg.Interface().(proto.Message)
|
||||
msgReflect := proto.MessageReflect(msgPb)
|
||||
msgDesc := msgReflect.Descriptor()
|
||||
|
||||
meta, _ := protoregistry.GlobalTypes.FindMessageByName(msgDesc.FullName() + "Metas")
|
||||
metaList := meta.New()
|
||||
f, _ := os.Open(fileName)
|
||||
data, _ := bufio.NewReader(f).ReadString(0)
|
||||
data = "{\"values\":" + data
|
||||
data += "}"
|
||||
err := jsonpb.Unmarshal(f, proto.MessageV1(metaList))
|
||||
if err == nil {
|
||||
fmt.Println("json decode ok", data)
|
||||
}
|
||||
|
||||
/* msgReflect = proto.MessageReflect(proto.MessageV1(metaList))
|
||||
msgDesc = msgReflect.Descriptor()
|
||||
valuesField := msgDesc.Fields().ByName("values")
|
||||
values := msgReflect.Get(valuesField)
|
||||
reflect.ValueOf(list).Elem().Set(reflect.ValueOf(values.List()))
|
||||
_ = valuesField
|
||||
fmt.Println(valuesField, values)*/
|
||||
}
|
||||
|
||||
func xvalueToPBSampleField(
|
||||
value *q5.XValue,
|
||||
field protoreflect.FieldDescriptor,
|
||||
msgReflect protoreflect.Message) {
|
||||
switch field.Kind() {
|
||||
case protoreflect.BoolKind:
|
||||
msgReflect.Set(field, protoreflect.ValueOfBool(value.GetInt64() != 0))
|
||||
break
|
||||
case protoreflect.EnumKind:
|
||||
break
|
||||
case
|
||||
protoreflect.Int32Kind, protoreflect.Sint32Kind,
|
||||
protoreflect.Sfixed32Kind, protoreflect.Fixed32Kind:
|
||||
break
|
||||
case protoreflect.Uint32Kind:
|
||||
break
|
||||
case
|
||||
protoreflect.Int64Kind, protoreflect.Sint64Kind,
|
||||
protoreflect.Sfixed64Kind, protoreflect.Fixed64Kind:
|
||||
break
|
||||
case protoreflect.Uint64Kind:
|
||||
break
|
||||
case protoreflect.FloatKind:
|
||||
break
|
||||
case protoreflect.DoubleKind:
|
||||
break
|
||||
case protoreflect.StringKind:
|
||||
break
|
||||
case protoreflect.BytesKind:
|
||||
break
|
||||
case protoreflect.MessageKind:
|
||||
break
|
||||
case protoreflect.GroupKind:
|
||||
break
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user