代码拉取完成,页面将自动刷新
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://gitee.com/micro-tools/wf/extend/utils.
package grpcutils
import (
"fmt"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
)
var (
jsonPbMarshaller = &jsonpb.Marshaler{
EmitDefaults: true,
}
)
// MarshalPbMessageToJsonString marshals protobuf message to json string.
func MarshalPbMessageToJsonString(msg proto.Message) string {
msgJsonStr, _ := jsonPbMarshaller.MarshalToString(msg)
if len(msgJsonStr) > 10000 {
msgJsonStr = "内容太长,不显示"
}
return msgJsonStr
}
func MarshalMessageToJsonStringForTracing(value interface{}, msgType string, maxBytes int) string {
var messageContent string
if msg, ok := value.(proto.Message); ok {
if proto.Size(msg) <= maxBytes {
messageContent = MarshalPbMessageToJsonString(msg)
} else {
messageContent = fmt.Sprintf(
"[%s Message Too Large For Tracing, Max: %d bytes]",
msgType,
maxBytes,
)
}
} else {
messageContent = fmt.Sprintf("%v", value)
}
return messageContent
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。