fix Pb2String

pull/333/head
wangchuxiao 2 years ago
parent 4f322254b0
commit 818ed107c6

@ -374,7 +374,7 @@ func (d *DataBases) DelMsgFromCache(uid string, seqList []uint32, operationID st
continue continue
} }
var msg pbCommon.MsgData var msg pbCommon.MsgData
if err := utils.String2Pb(result, &msg); err != nil { if err := jsonpb.UnmarshalString(result, &msg); err != nil {
log2.Error(operationID, utils.GetSelfFuncName(), "String2Pb failed", msg, result, key, err.Error()) log2.Error(operationID, utils.GetSelfFuncName(), "String2Pb failed", msg, result, key, err.Error())
continue continue
} }

@ -137,21 +137,17 @@ func RemoveRepeatedStringInList(slc []string) []string {
} }
func Pb2String(pb proto.Message) (string, error) { func Pb2String(pb proto.Message) (string, error) {
//marshaler := jsonpb.Marshaler{ marshaler := jsonpb.Marshaler{
// OrigName: true, OrigName: true,
// EnumsAsInts: false, EnumsAsInts: false,
// EmitDefaults: false, EmitDefaults: false,
//}
//return marshaler.MarshalToString(pb)
bytes, err := proto.Marshal(pb)
if err != nil {
return "", err
} }
return string(bytes), nil return marshaler.MarshalToString(pb)
} }
func String2Pb(s string, pb proto.Message) error { func String2Pb(s string, pb proto.Message) error {
return proto.Unmarshal([]byte(s), pb) err := jsonpb.UnmarshalString(s, pb)
return err
} }
func Map2Pb(m map[string]string) (pb proto.Message, err error) { func Map2Pb(m map[string]string) (pb proto.Message, err error) {

Loading…
Cancel
Save