diff --git a/tars/protocol/res/NotifyF.tars b/tars/protocol/res/NotifyF.tars index ea3a87d6..d28dd551 100644 --- a/tars/protocol/res/NotifyF.tars +++ b/tars/protocol/res/NotifyF.tars @@ -16,36 +16,36 @@ module notifyf { - -/** -* notify信息的键值 -*/ -struct NotifyKey -{ - 1 require string name; //为app+servername 例如:Comm.BindServer - 2 require string ip; //ip - 3 require int page; -}; - -/** -* 上报信息的单条内容 -*/ -struct NotifyItem -{ - 1 require string sTimeStamp; - 2 require string sServerId; - 3 require int iLevel; - 4 require string sMessage; -}; - -/** -* 上报的信息分页记录 -*/ -struct NotifyInfo -{ - 1 require int nextpage; - 2 require vector notifyItems; -}; +// +///** +//* notify信息的键值 +//*/ +//struct NotifyKey +//{ +// 1 require string name; //为app+servername 例如:Comm.BindServer +// 2 require string ip; //ip +// 3 require int page; +//}; +// +///** +//* 上报信息的单条内容 +//*/ +//struct NotifyItem +//{ +// 1 require string sTimeStamp; +// 2 require string sServerId; +// 3 require int iLevel; +// 4 require string sMessage; +//}; +// +///** +//* 上报的信息分页记录 +//*/ +//struct NotifyInfo +//{ +// 1 require int nextpage; +// 2 require vector notifyItems; +//}; /** * 定义上报信息的等级 @@ -85,30 +85,30 @@ struct ReportInfo interface Notify { - /** - * 框架上报的信息, 保存于数据库中 - * @param sServerName, server name - * @param sThreadId, server current thread id - * @param sMessage, message - **/ - void reportServer(string sServerName, string sThreadId, string sMessage); - - - /** - * 业务上报的信息, 用于报警 - * @param sServerName, server name - * @param level, notify level - * @param sMessage, message - **/ - void notifyServer(string sServerName, NOTIFYLEVEL level, string sMessage); - - /** - * 获取上报信息 - * @param sServerName, server name - * @param out , notify info detail - * @return int 0=success, others=failed - **/ - int getNotifyInfo(NotifyKey stKey, out NotifyInfo stInfo); + ///** + //* 框架上报的信息, 保存于数据库中 + //* @param sServerName, server name + //* @param sThreadId, server current thread id + //* @param sMessage, message + //**/ + //void reportServer(string sServerName, string sThreadId, string sMessage); + // + // + ///** + //* 业务上报的信息, 用于报警 + //* @param sServerName, server name + //* @param level, notify level + //* @param sMessage, message + //**/ + //void notifyServer(string sServerName, NOTIFYLEVEL level, string sMessage); + // + ///** + //* 获取上报信息 + //* @param sServerName, server name + //* @param out , notify info detail + //* @return int 0=success, others=failed + //**/ + //int getNotifyInfo(NotifyKey stKey, out NotifyInfo stInfo); /* *上报框架信息以及业务告警信息 diff --git a/tars/protocol/res/basef/BaseF.go b/tars/protocol/res/basef/BaseF.go index becf8add..d12d746d 100644 --- a/tars/protocol/res/basef/BaseF.go +++ b/tars/protocol/res/basef/BaseF.go @@ -13,7 +13,7 @@ import ( var _ = fmt.Errorf var _ = codec.FromInt8 -// const as define in tars file +//const as define in tars file const ( TARSVERSION int16 = 0x01 TUPVERSION int16 = 0x03 diff --git a/tars/protocol/res/endpointf/EndpointF.go b/tars/protocol/res/endpointf/EndpointF.go index e6708e97..58c056f0 100644 --- a/tars/protocol/res/endpointf/EndpointF.go +++ b/tars/protocol/res/endpointf/EndpointF.go @@ -1,5 +1,5 @@ // Code generated by tars2go 1.2.3, DO NOT EDIT. -// This file was generated from EndpointF.tars +// This file was generated from ./EndpointF.tars // Package endpointf comment package endpointf diff --git a/tars/protocol/res/notifyf/Notify.tars.go b/tars/protocol/res/notifyf/Notify.tars.go index d68e85f2..8d60b09c 100644 --- a/tars/protocol/res/notifyf/Notify.tars.go +++ b/tars/protocol/res/notifyf/Notify.tars.go @@ -27,16 +27,10 @@ var ( ) type NotifyServant interface { - ReportServer(sServerName string, sThreadId string, sMessage string) (err error) - NotifyServer(sServerName string, level NOTIFYLEVEL, sMessage string) (err error) - GetNotifyInfo(stKey *NotifyKey, stInfo *NotifyInfo) (ret int32, err error) ReportNotifyInfo(info *ReportInfo) (err error) } type NotifyServantWithContext interface { - ReportServer(tarsCtx context.Context, sServerName string, sThreadId string, sMessage string) (err error) - NotifyServer(tarsCtx context.Context, sServerName string, level NOTIFYLEVEL, sMessage string) (err error) - GetNotifyInfo(tarsCtx context.Context, stKey *NotifyKey, stInfo *NotifyInfo) (ret int32, err error) ReportNotifyInfo(tarsCtx context.Context, info *ReportInfo) (err error) } @@ -70,145 +64,20 @@ func (obj *Notify) Endpoints() []*endpoint.Endpoint { return obj.servant.Endpoints() } -// ReportServer is the proxy function for the method defined in the tars file, with the context -func (obj *Notify) ReportServer(sServerName string, sThreadId string, sMessage string, opts ...map[string]string) error { - return obj.ReportServerWithContext(context.Background(), sServerName, sThreadId, sMessage, opts...) -} - -// ReportServerWithContext is the proxy function for the method defined in the tars file, with the context -func (obj *Notify) ReportServerWithContext(tarsCtx context.Context, sServerName string, sThreadId string, sMessage string, opts ...map[string]string) (err error) { - var ( - length int32 - have bool - ty byte - ) - buf := codec.NewBuffer() - err = buf.WriteString(sServerName, 1) - if err != nil { - return err - } - - err = buf.WriteString(sThreadId, 2) - if err != nil { - return err - } - - err = buf.WriteString(sMessage, 3) - if err != nil { - return err - } - - var statusMap map[string]string - var contextMap map[string]string - if len(opts) == 1 { - contextMap = opts[0] - } else if len(opts) == 2 { - contextMap = opts[0] - statusMap = opts[1] - } - - tarsResp := new(requestf.ResponsePacket) - err = obj.servant.TarsInvoke(tarsCtx, 0, "reportServer", buf.ToBytes(), statusMap, contextMap, tarsResp) - if err != nil { - return err - } - - if len(opts) == 1 { - for k := range contextMap { - delete(contextMap, k) - } - for k, v := range tarsResp.Context { - contextMap[k] = v - } - } else if len(opts) == 2 { - for k := range contextMap { - delete(contextMap, k) - } - for k, v := range tarsResp.Context { - contextMap[k] = v - } - for k := range statusMap { - delete(statusMap, k) - } - for k, v := range tarsResp.Status { - statusMap[k] = v - } - } - - _ = length - _ = have - _ = ty - return nil -} - -// ReportServerOneWayWithContext is the proxy function for the method defined in the tars file, with the context -func (obj *Notify) ReportServerOneWayWithContext(tarsCtx context.Context, sServerName string, sThreadId string, sMessage string, opts ...map[string]string) (err error) { - var ( - length int32 - have bool - ty byte - ) - buf := codec.NewBuffer() - err = buf.WriteString(sServerName, 1) - if err != nil { - return err - } - - err = buf.WriteString(sThreadId, 2) - if err != nil { - return err - } - - err = buf.WriteString(sMessage, 3) - if err != nil { - return err - } - - var statusMap map[string]string - var contextMap map[string]string - if len(opts) == 1 { - contextMap = opts[0] - } else if len(opts) == 2 { - contextMap = opts[0] - statusMap = opts[1] - } - - tarsResp := new(requestf.ResponsePacket) - err = obj.servant.TarsInvoke(tarsCtx, 1, "reportServer", buf.ToBytes(), statusMap, contextMap, tarsResp) - if err != nil { - return err - } - - _ = length - _ = have - _ = ty - return nil -} - -// NotifyServer is the proxy function for the method defined in the tars file, with the context -func (obj *Notify) NotifyServer(sServerName string, level NOTIFYLEVEL, sMessage string, opts ...map[string]string) error { - return obj.NotifyServerWithContext(context.Background(), sServerName, level, sMessage, opts...) +// ReportNotifyInfo is the proxy function for the method defined in the tars file, with the context +func (obj *Notify) ReportNotifyInfo(info *ReportInfo, opts ...map[string]string) error { + return obj.ReportNotifyInfoWithContext(context.Background(), info, opts...) } -// NotifyServerWithContext is the proxy function for the method defined in the tars file, with the context -func (obj *Notify) NotifyServerWithContext(tarsCtx context.Context, sServerName string, level NOTIFYLEVEL, sMessage string, opts ...map[string]string) (err error) { +// ReportNotifyInfoWithContext is the proxy function for the method defined in the tars file, with the context +func (obj *Notify) ReportNotifyInfoWithContext(tarsCtx context.Context, info *ReportInfo, opts ...map[string]string) (err error) { var ( length int32 have bool ty byte ) buf := codec.NewBuffer() - err = buf.WriteString(sServerName, 1) - if err != nil { - return err - } - - err = buf.WriteInt32(int32(level), 2) - if err != nil { - return err - } - - err = buf.WriteString(sMessage, 3) + err = info.WriteBlock(buf, 1) if err != nil { return err } @@ -223,7 +92,7 @@ func (obj *Notify) NotifyServerWithContext(tarsCtx context.Context, sServerName } tarsResp := new(requestf.ResponsePacket) - err = obj.servant.TarsInvoke(tarsCtx, 0, "notifyServer", buf.ToBytes(), statusMap, contextMap, tarsResp) + err = obj.servant.TarsInvoke(tarsCtx, 0, "reportNotifyInfo", buf.ToBytes(), statusMap, contextMap, tarsResp) if err != nil { return err } @@ -256,25 +125,15 @@ func (obj *Notify) NotifyServerWithContext(tarsCtx context.Context, sServerName return nil } -// NotifyServerOneWayWithContext is the proxy function for the method defined in the tars file, with the context -func (obj *Notify) NotifyServerOneWayWithContext(tarsCtx context.Context, sServerName string, level NOTIFYLEVEL, sMessage string, opts ...map[string]string) (err error) { +// ReportNotifyInfoOneWayWithContext is the proxy function for the method defined in the tars file, with the context +func (obj *Notify) ReportNotifyInfoOneWayWithContext(tarsCtx context.Context, info *ReportInfo, opts ...map[string]string) (err error) { var ( length int32 have bool ty byte ) buf := codec.NewBuffer() - err = buf.WriteString(sServerName, 1) - if err != nil { - return err - } - - err = buf.WriteInt32(int32(level), 2) - if err != nil { - return err - } - - err = buf.WriteString(sMessage, 3) + err = info.WriteBlock(buf, 1) if err != nil { return err } @@ -289,7 +148,7 @@ func (obj *Notify) NotifyServerOneWayWithContext(tarsCtx context.Context, sServe } tarsResp := new(requestf.ResponsePacket) - err = obj.servant.TarsInvoke(tarsCtx, 1, "notifyServer", buf.ToBytes(), statusMap, contextMap, tarsResp) + err = obj.servant.TarsInvoke(tarsCtx, 1, "reportNotifyInfo", buf.ToBytes(), statusMap, contextMap, tarsResp) if err != nil { return err } @@ -300,548 +159,16 @@ func (obj *Notify) NotifyServerOneWayWithContext(tarsCtx context.Context, sServe return nil } -// GetNotifyInfo is the proxy function for the method defined in the tars file, with the context -func (obj *Notify) GetNotifyInfo(stKey *NotifyKey, stInfo *NotifyInfo, opts ...map[string]string) (int32, error) { - return obj.GetNotifyInfoWithContext(context.Background(), stKey, stInfo, opts...) -} - -// GetNotifyInfoWithContext is the proxy function for the method defined in the tars file, with the context -func (obj *Notify) GetNotifyInfoWithContext(tarsCtx context.Context, stKey *NotifyKey, stInfo *NotifyInfo, opts ...map[string]string) (ret int32, err error) { - var ( - length int32 - have bool - ty byte - ) - buf := codec.NewBuffer() - err = stKey.WriteBlock(buf, 1) - if err != nil { - return ret, err - } - - err = (*stInfo).WriteBlock(buf, 2) - if err != nil { - return ret, err - } - - var statusMap map[string]string - var contextMap map[string]string - if len(opts) == 1 { - contextMap = opts[0] - } else if len(opts) == 2 { - contextMap = opts[0] - statusMap = opts[1] - } - - tarsResp := new(requestf.ResponsePacket) - err = obj.servant.TarsInvoke(tarsCtx, 0, "getNotifyInfo", buf.ToBytes(), statusMap, contextMap, tarsResp) - if err != nil { - return ret, err - } - readBuf := codec.NewReader(tools.Int8ToByte(tarsResp.SBuffer)) - err = readBuf.ReadInt32(&ret, 0, true) - if err != nil { - return ret, err - } - - err = (*stInfo).ReadBlock(readBuf, 2, true) - if err != nil { - return ret, err - } - - if len(opts) == 1 { - for k := range contextMap { - delete(contextMap, k) - } - for k, v := range tarsResp.Context { - contextMap[k] = v - } - } else if len(opts) == 2 { - for k := range contextMap { - delete(contextMap, k) - } - for k, v := range tarsResp.Context { - contextMap[k] = v - } - for k := range statusMap { - delete(statusMap, k) - } - for k, v := range tarsResp.Status { - statusMap[k] = v - } - } - - _ = length - _ = have - _ = ty - return ret, nil -} - -// GetNotifyInfoOneWayWithContext is the proxy function for the method defined in the tars file, with the context -func (obj *Notify) GetNotifyInfoOneWayWithContext(tarsCtx context.Context, stKey *NotifyKey, stInfo *NotifyInfo, opts ...map[string]string) (ret int32, err error) { - var ( - length int32 - have bool - ty byte - ) - buf := codec.NewBuffer() - err = stKey.WriteBlock(buf, 1) - if err != nil { - return ret, err - } - - err = (*stInfo).WriteBlock(buf, 2) - if err != nil { - return ret, err - } - - var statusMap map[string]string - var contextMap map[string]string - if len(opts) == 1 { - contextMap = opts[0] - } else if len(opts) == 2 { - contextMap = opts[0] - statusMap = opts[1] - } - - tarsResp := new(requestf.ResponsePacket) - err = obj.servant.TarsInvoke(tarsCtx, 1, "getNotifyInfo", buf.ToBytes(), statusMap, contextMap, tarsResp) - if err != nil { - return ret, err - } - - _ = length - _ = have - _ = ty - return ret, nil -} - -// ReportNotifyInfo is the proxy function for the method defined in the tars file, with the context -func (obj *Notify) ReportNotifyInfo(info *ReportInfo, opts ...map[string]string) error { - return obj.ReportNotifyInfoWithContext(context.Background(), info, opts...) -} - -// ReportNotifyInfoWithContext is the proxy function for the method defined in the tars file, with the context -func (obj *Notify) ReportNotifyInfoWithContext(tarsCtx context.Context, info *ReportInfo, opts ...map[string]string) (err error) { +// Dispatch is used to call the server side implement for the method defined in the tars file. withContext shows using context or not. +func (obj *Notify) Dispatch(tarsCtx context.Context, val interface{}, tarsReq *requestf.RequestPacket, tarsResp *requestf.ResponsePacket, withContext bool) (err error) { var ( length int32 have bool ty byte ) - buf := codec.NewBuffer() - err = info.WriteBlock(buf, 1) - if err != nil { - return err - } - - var statusMap map[string]string - var contextMap map[string]string - if len(opts) == 1 { - contextMap = opts[0] - } else if len(opts) == 2 { - contextMap = opts[0] - statusMap = opts[1] - } - - tarsResp := new(requestf.ResponsePacket) - err = obj.servant.TarsInvoke(tarsCtx, 0, "reportNotifyInfo", buf.ToBytes(), statusMap, contextMap, tarsResp) - if err != nil { - return err - } - - if len(opts) == 1 { - for k := range contextMap { - delete(contextMap, k) - } - for k, v := range tarsResp.Context { - contextMap[k] = v - } - } else if len(opts) == 2 { - for k := range contextMap { - delete(contextMap, k) - } - for k, v := range tarsResp.Context { - contextMap[k] = v - } - for k := range statusMap { - delete(statusMap, k) - } - for k, v := range tarsResp.Status { - statusMap[k] = v - } - } - - _ = length - _ = have - _ = ty - return nil -} - -// ReportNotifyInfoOneWayWithContext is the proxy function for the method defined in the tars file, with the context -func (obj *Notify) ReportNotifyInfoOneWayWithContext(tarsCtx context.Context, info *ReportInfo, opts ...map[string]string) (err error) { - var ( - length int32 - have bool - ty byte - ) - buf := codec.NewBuffer() - err = info.WriteBlock(buf, 1) - if err != nil { - return err - } - - var statusMap map[string]string - var contextMap map[string]string - if len(opts) == 1 { - contextMap = opts[0] - } else if len(opts) == 2 { - contextMap = opts[0] - statusMap = opts[1] - } - - tarsResp := new(requestf.ResponsePacket) - err = obj.servant.TarsInvoke(tarsCtx, 1, "reportNotifyInfo", buf.ToBytes(), statusMap, contextMap, tarsResp) - if err != nil { - return err - } - - _ = length - _ = have - _ = ty - return nil -} - -// Dispatch is used to call the server side implement for the method defined in the tars file. withContext shows using context or not. -func (obj *Notify) Dispatch(tarsCtx context.Context, val interface{}, tarsReq *requestf.RequestPacket, tarsResp *requestf.ResponsePacket, withContext bool) (err error) { - var ( - length int32 - have bool - ty byte - ) - readBuf := codec.NewReader(tools.Int8ToByte(tarsReq.SBuffer)) + readBuf := codec.NewReader(tools.Int8ToByte(tarsReq.SBuffer)) buf := codec.NewBuffer() switch tarsReq.SFuncName { - case "reportServer": - var sServerName string - var sThreadId string - var sMessage string - if tarsReq.IVersion == basef.TARSVERSION { - err = readBuf.ReadString(&sServerName, 1, true) - if err != nil { - return err - } - err = readBuf.ReadString(&sThreadId, 2, true) - if err != nil { - return err - } - err = readBuf.ReadString(&sMessage, 3, true) - if err != nil { - return err - } - } else if tarsReq.IVersion == basef.TUPVERSION { - reqTup := tup.NewUniAttribute() - reqTup.Decode(readBuf) - - var tupBuffer []byte - - reqTup.GetBuffer("sServerName", &tupBuffer) - readBuf.Reset(tupBuffer) - err = readBuf.ReadString(&sServerName, 0, true) - if err != nil { - return err - } - - reqTup.GetBuffer("sThreadId", &tupBuffer) - readBuf.Reset(tupBuffer) - err = readBuf.ReadString(&sThreadId, 0, true) - if err != nil { - return err - } - - reqTup.GetBuffer("sMessage", &tupBuffer) - readBuf.Reset(tupBuffer) - err = readBuf.ReadString(&sMessage, 0, true) - if err != nil { - return err - } - } else if tarsReq.IVersion == basef.JSONVERSION { - var jsonData map[string]interface{} - decoder := json.NewDecoder(bytes.NewReader(readBuf.ToBytes())) - decoder.UseNumber() - err = decoder.Decode(&jsonData) - if err != nil { - return fmt.Errorf("decode reqpacket failed, error: %+v", err) - } - { - jsonStr, _ := json.Marshal(jsonData["sServerName"]) - if err = json.Unmarshal(jsonStr, &sServerName); err != nil { - return err - } - } - { - jsonStr, _ := json.Marshal(jsonData["sThreadId"]) - if err = json.Unmarshal(jsonStr, &sThreadId); err != nil { - return err - } - } - { - jsonStr, _ := json.Marshal(jsonData["sMessage"]) - if err = json.Unmarshal(jsonStr, &sMessage); err != nil { - return err - } - } - } else { - err = fmt.Errorf("decode reqpacket fail, error version: %d", tarsReq.IVersion) - return err - } - - if !withContext { - imp := val.(NotifyServant) - err = imp.ReportServer(sServerName, sThreadId, sMessage) - } else { - imp := val.(NotifyServantWithContext) - err = imp.ReportServer(tarsCtx, sServerName, sThreadId, sMessage) - } - if err != nil { - return err - } - - if tarsReq.IVersion == basef.TARSVERSION { - buf.Reset() - - } else if tarsReq.IVersion == basef.TUPVERSION { - rspTup := tup.NewUniAttribute() - - buf.Reset() - err = rspTup.Encode(buf) - if err != nil { - return err - } - } else if tarsReq.IVersion == basef.JSONVERSION { - rspJson := map[string]interface{}{} - - var rspByte []byte - if rspByte, err = json.Marshal(rspJson); err != nil { - return err - } - - buf.Reset() - err = buf.WriteSliceUint8(rspByte) - if err != nil { - return err - } - } - case "notifyServer": - var sServerName string - var level NOTIFYLEVEL - var sMessage string - if tarsReq.IVersion == basef.TARSVERSION { - err = readBuf.ReadString(&sServerName, 1, true) - if err != nil { - return err - } - err = readBuf.ReadInt32((*int32)(&level), 2, true) - if err != nil { - return err - } - err = readBuf.ReadString(&sMessage, 3, true) - if err != nil { - return err - } - } else if tarsReq.IVersion == basef.TUPVERSION { - reqTup := tup.NewUniAttribute() - reqTup.Decode(readBuf) - - var tupBuffer []byte - - reqTup.GetBuffer("sServerName", &tupBuffer) - readBuf.Reset(tupBuffer) - err = readBuf.ReadString(&sServerName, 0, true) - if err != nil { - return err - } - - reqTup.GetBuffer("level", &tupBuffer) - readBuf.Reset(tupBuffer) - err = readBuf.ReadInt32((*int32)(&level), 0, true) - if err != nil { - return err - } - - reqTup.GetBuffer("sMessage", &tupBuffer) - readBuf.Reset(tupBuffer) - err = readBuf.ReadString(&sMessage, 0, true) - if err != nil { - return err - } - } else if tarsReq.IVersion == basef.JSONVERSION { - var jsonData map[string]interface{} - decoder := json.NewDecoder(bytes.NewReader(readBuf.ToBytes())) - decoder.UseNumber() - err = decoder.Decode(&jsonData) - if err != nil { - return fmt.Errorf("decode reqpacket failed, error: %+v", err) - } - { - jsonStr, _ := json.Marshal(jsonData["sServerName"]) - if err = json.Unmarshal(jsonStr, &sServerName); err != nil { - return err - } - } - { - jsonStr, _ := json.Marshal(jsonData["level"]) - if err = json.Unmarshal(jsonStr, &level); err != nil { - return err - } - } - { - jsonStr, _ := json.Marshal(jsonData["sMessage"]) - if err = json.Unmarshal(jsonStr, &sMessage); err != nil { - return err - } - } - } else { - err = fmt.Errorf("decode reqpacket fail, error version: %d", tarsReq.IVersion) - return err - } - - if !withContext { - imp := val.(NotifyServant) - err = imp.NotifyServer(sServerName, level, sMessage) - } else { - imp := val.(NotifyServantWithContext) - err = imp.NotifyServer(tarsCtx, sServerName, level, sMessage) - } - if err != nil { - return err - } - - if tarsReq.IVersion == basef.TARSVERSION { - buf.Reset() - - } else if tarsReq.IVersion == basef.TUPVERSION { - rspTup := tup.NewUniAttribute() - - buf.Reset() - err = rspTup.Encode(buf) - if err != nil { - return err - } - } else if tarsReq.IVersion == basef.JSONVERSION { - rspJson := map[string]interface{}{} - - var rspByte []byte - if rspByte, err = json.Marshal(rspJson); err != nil { - return err - } - - buf.Reset() - err = buf.WriteSliceUint8(rspByte) - if err != nil { - return err - } - } - case "getNotifyInfo": - var stKey NotifyKey - var stInfo NotifyInfo - if tarsReq.IVersion == basef.TARSVERSION { - err = stKey.ReadBlock(readBuf, 1, true) - if err != nil { - return err - } - } else if tarsReq.IVersion == basef.TUPVERSION { - reqTup := tup.NewUniAttribute() - reqTup.Decode(readBuf) - - var tupBuffer []byte - - reqTup.GetBuffer("stKey", &tupBuffer) - readBuf.Reset(tupBuffer) - err = stKey.ReadBlock(readBuf, 0, true) - if err != nil { - return err - } - } else if tarsReq.IVersion == basef.JSONVERSION { - var jsonData map[string]interface{} - decoder := json.NewDecoder(bytes.NewReader(readBuf.ToBytes())) - decoder.UseNumber() - err = decoder.Decode(&jsonData) - if err != nil { - return fmt.Errorf("decode reqpacket failed, error: %+v", err) - } - { - jsonStr, _ := json.Marshal(jsonData["stKey"]) - stKey.ResetDefault() - if err = json.Unmarshal(jsonStr, &stKey); err != nil { - return err - } - } - } else { - err = fmt.Errorf("decode reqpacket fail, error version: %d", tarsReq.IVersion) - return err - } - - var funRet int32 - if !withContext { - imp := val.(NotifyServant) - funRet, err = imp.GetNotifyInfo(&stKey, &stInfo) - } else { - imp := val.(NotifyServantWithContext) - funRet, err = imp.GetNotifyInfo(tarsCtx, &stKey, &stInfo) - } - if err != nil { - return err - } - - if tarsReq.IVersion == basef.TARSVERSION { - buf.Reset() - - err = buf.WriteInt32(funRet, 0) - if err != nil { - return err - } - err = stInfo.WriteBlock(buf, 2) - if err != nil { - return err - } - } else if tarsReq.IVersion == basef.TUPVERSION { - rspTup := tup.NewUniAttribute() - - err = buf.WriteInt32(funRet, 0) - if err != nil { - return err - } - - rspTup.PutBuffer("", buf.ToBytes()) - rspTup.PutBuffer("tars_ret", buf.ToBytes()) - - buf.Reset() - err = stInfo.WriteBlock(buf, 0) - if err != nil { - return err - } - rspTup.PutBuffer("stInfo", buf.ToBytes()) - - buf.Reset() - err = rspTup.Encode(buf) - if err != nil { - return err - } - } else if tarsReq.IVersion == basef.JSONVERSION { - rspJson := map[string]interface{}{} - rspJson["tars_ret"] = funRet - rspJson["stInfo"] = stInfo - - var rspByte []byte - if rspByte, err = json.Marshal(rspJson); err != nil { - return err - } - - buf.Reset() - err = buf.WriteSliceUint8(rspByte) - if err != nil { - return err - } - } case "reportNotifyInfo": var info ReportInfo if tarsReq.IVersion == basef.TARSVERSION { diff --git a/tars/protocol/res/notifyf/NotifyF.go b/tars/protocol/res/notifyf/NotifyF.go index 21e007b8..a009f8a2 100644 --- a/tars/protocol/res/notifyf/NotifyF.go +++ b/tars/protocol/res/notifyf/NotifyF.go @@ -30,381 +30,6 @@ const ( ReportType_NOTIFY ReportType = 1 ) -// NotifyKey struct implement -type NotifyKey struct { - Name string `json:"name" tars:"name,tag:1,require:true"` - Ip string `json:"ip" tars:"ip,tag:2,require:true"` - Page int32 `json:"page" tars:"page,tag:3,require:true"` -} - -func (st *NotifyKey) ResetDefault() { -} - -// ReadFrom reads from readBuf and put into struct. -func (st *NotifyKey) ReadFrom(readBuf *codec.Reader) error { - var ( - err error - length int32 - have bool - ty byte - ) - st.ResetDefault() - - err = readBuf.ReadString(&st.Name, 1, true) - if err != nil { - return err - } - - err = readBuf.ReadString(&st.Ip, 2, true) - if err != nil { - return err - } - - err = readBuf.ReadInt32(&st.Page, 3, true) - if err != nil { - return err - } - - _ = err - _ = length - _ = have - _ = ty - return nil -} - -// ReadBlock reads struct from the given tag , require or optional. -func (st *NotifyKey) ReadBlock(readBuf *codec.Reader, tag byte, require bool) error { - var ( - err error - have bool - ) - st.ResetDefault() - - have, err = readBuf.SkipTo(codec.StructBegin, tag, require) - if err != nil { - return err - } - if !have { - if require { - return fmt.Errorf("require NotifyKey, but not exist. tag %d", tag) - } - return nil - } - - err = st.ReadFrom(readBuf) - if err != nil { - return err - } - - err = readBuf.SkipToStructEnd() - if err != nil { - return err - } - _ = have - return nil -} - -// WriteTo encode struct to buffer -func (st *NotifyKey) WriteTo(buf *codec.Buffer) (err error) { - err = buf.WriteString(st.Name, 1) - if err != nil { - return err - } - - err = buf.WriteString(st.Ip, 2) - if err != nil { - return err - } - - err = buf.WriteInt32(st.Page, 3) - if err != nil { - return err - } - - return err -} - -// WriteBlock encode struct -func (st *NotifyKey) WriteBlock(buf *codec.Buffer, tag byte) error { - var err error - err = buf.WriteHead(codec.StructBegin, tag) - if err != nil { - return err - } - - err = st.WriteTo(buf) - if err != nil { - return err - } - - err = buf.WriteHead(codec.StructEnd, 0) - if err != nil { - return err - } - return nil -} - -// NotifyItem struct implement -type NotifyItem struct { - STimeStamp string `json:"sTimeStamp" tars:"sTimeStamp,tag:1,require:true"` - SServerId string `json:"sServerId" tars:"sServerId,tag:2,require:true"` - ILevel int32 `json:"iLevel" tars:"iLevel,tag:3,require:true"` - SMessage string `json:"sMessage" tars:"sMessage,tag:4,require:true"` -} - -func (st *NotifyItem) ResetDefault() { -} - -// ReadFrom reads from readBuf and put into struct. -func (st *NotifyItem) ReadFrom(readBuf *codec.Reader) error { - var ( - err error - length int32 - have bool - ty byte - ) - st.ResetDefault() - - err = readBuf.ReadString(&st.STimeStamp, 1, true) - if err != nil { - return err - } - - err = readBuf.ReadString(&st.SServerId, 2, true) - if err != nil { - return err - } - - err = readBuf.ReadInt32(&st.ILevel, 3, true) - if err != nil { - return err - } - - err = readBuf.ReadString(&st.SMessage, 4, true) - if err != nil { - return err - } - - _ = err - _ = length - _ = have - _ = ty - return nil -} - -// ReadBlock reads struct from the given tag , require or optional. -func (st *NotifyItem) ReadBlock(readBuf *codec.Reader, tag byte, require bool) error { - var ( - err error - have bool - ) - st.ResetDefault() - - have, err = readBuf.SkipTo(codec.StructBegin, tag, require) - if err != nil { - return err - } - if !have { - if require { - return fmt.Errorf("require NotifyItem, but not exist. tag %d", tag) - } - return nil - } - - err = st.ReadFrom(readBuf) - if err != nil { - return err - } - - err = readBuf.SkipToStructEnd() - if err != nil { - return err - } - _ = have - return nil -} - -// WriteTo encode struct to buffer -func (st *NotifyItem) WriteTo(buf *codec.Buffer) (err error) { - err = buf.WriteString(st.STimeStamp, 1) - if err != nil { - return err - } - - err = buf.WriteString(st.SServerId, 2) - if err != nil { - return err - } - - err = buf.WriteInt32(st.ILevel, 3) - if err != nil { - return err - } - - err = buf.WriteString(st.SMessage, 4) - if err != nil { - return err - } - - return err -} - -// WriteBlock encode struct -func (st *NotifyItem) WriteBlock(buf *codec.Buffer, tag byte) error { - var err error - err = buf.WriteHead(codec.StructBegin, tag) - if err != nil { - return err - } - - err = st.WriteTo(buf) - if err != nil { - return err - } - - err = buf.WriteHead(codec.StructEnd, 0) - if err != nil { - return err - } - return nil -} - -// NotifyInfo struct implement -type NotifyInfo struct { - Nextpage int32 `json:"nextpage" tars:"nextpage,tag:1,require:true"` - NotifyItems []NotifyItem `json:"notifyItems" tars:"notifyItems,tag:2,require:true"` -} - -func (st *NotifyInfo) ResetDefault() { -} - -// ReadFrom reads from readBuf and put into struct. -func (st *NotifyInfo) ReadFrom(readBuf *codec.Reader) error { - var ( - err error - length int32 - have bool - ty byte - ) - st.ResetDefault() - - err = readBuf.ReadInt32(&st.Nextpage, 1, true) - if err != nil { - return err - } - - _, ty, err = readBuf.SkipToNoCheck(2, true) - if err != nil { - return err - } - if ty == codec.LIST { - err = readBuf.ReadInt32(&length, 0, true) - if err != nil { - return err - } - st.NotifyItems = make([]NotifyItem, length) - for i0, e0 := int32(0), length; i0 < e0; i0++ { - err = st.NotifyItems[i0].ReadBlock(readBuf, 0, true) - if err != nil { - return err - } - } - } else if ty == codec.SimpleList { - err = fmt.Errorf("not support SimpleList type") - if err != nil { - return err - } - } else { - err = fmt.Errorf("require vector, but not") - if err != nil { - return err - } - } - - _ = err - _ = length - _ = have - _ = ty - return nil -} - -// ReadBlock reads struct from the given tag , require or optional. -func (st *NotifyInfo) ReadBlock(readBuf *codec.Reader, tag byte, require bool) error { - var ( - err error - have bool - ) - st.ResetDefault() - - have, err = readBuf.SkipTo(codec.StructBegin, tag, require) - if err != nil { - return err - } - if !have { - if require { - return fmt.Errorf("require NotifyInfo, but not exist. tag %d", tag) - } - return nil - } - - err = st.ReadFrom(readBuf) - if err != nil { - return err - } - - err = readBuf.SkipToStructEnd() - if err != nil { - return err - } - _ = have - return nil -} - -// WriteTo encode struct to buffer -func (st *NotifyInfo) WriteTo(buf *codec.Buffer) (err error) { - err = buf.WriteInt32(st.Nextpage, 1) - if err != nil { - return err - } - - err = buf.WriteHead(codec.LIST, 2) - if err != nil { - return err - } - err = buf.WriteInt32(int32(len(st.NotifyItems)), 0) - if err != nil { - return err - } - for _, v := range st.NotifyItems { - err = v.WriteBlock(buf, 0) - if err != nil { - return err - } - } - - return err -} - -// WriteBlock encode struct -func (st *NotifyInfo) WriteBlock(buf *codec.Buffer, tag byte) error { - var err error - err = buf.WriteHead(codec.StructBegin, tag) - if err != nil { - return err - } - - err = st.WriteTo(buf) - if err != nil { - return err - } - - err = buf.WriteHead(codec.StructEnd, 0) - if err != nil { - return err - } - return nil -} - // ReportInfo struct implement type ReportInfo struct { EType ReportType `json:"eType" tars:"eType,tag:1,require:true"` diff --git a/tars/protocol/res/queryf/QueryF.tars.go b/tars/protocol/res/queryf/QueryF.tars.go index 9ce1a79d..7f3df8f5 100644 --- a/tars/protocol/res/queryf/QueryF.tars.go +++ b/tars/protocol/res/queryf/QueryF.tars.go @@ -12,12 +12,13 @@ import ( "github.com/TarsCloud/TarsGo/tars/model" "github.com/TarsCloud/TarsGo/tars/protocol/codec" "github.com/TarsCloud/TarsGo/tars/protocol/res/basef" - "github.com/TarsCloud/TarsGo/tars/protocol/res/endpointf" "github.com/TarsCloud/TarsGo/tars/protocol/res/requestf" "github.com/TarsCloud/TarsGo/tars/protocol/tup" "github.com/TarsCloud/TarsGo/tars/util/current" "github.com/TarsCloud/TarsGo/tars/util/endpoint" "github.com/TarsCloud/TarsGo/tars/util/tools" + + "github.com/TarsCloud/TarsGo/tars/protocol/res/endpointf" ) // Reference imports to suppress errors if they are not otherwise used.