1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 19:17:38 +08:00

feat: add a debug mode for internal/proto.Marshal

This commit is contained in:
wdvxdr 2022-06-05 17:32:11 +08:00
parent ae33763fe1
commit 831b36ef76
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6

View File

@ -1,11 +1,33 @@
package proto package proto
import "github.com/RomiChan/protobuf/proto" import (
"reflect"
"github.com/RomiChan/protobuf/proto"
)
// TODO: move to a new package
const debug = false
type Message = any type Message = any
func Marshal(m Message) ([]byte, error) { func Marshal(m Message) ([]byte, error) {
return proto.Marshal(m) b, err := proto.Marshal(m)
if err != nil {
return b, err
}
if debug {
t := reflect.TypeOf(m).Elem()
n := reflect.New(t)
err = Unmarshal(b, n.Interface())
if err != nil {
panic(err)
}
if reflect.DeepEqual(m, n) {
panic("not equal")
}
}
return b, err
} }
func Unmarshal(b []byte, m Message) error { func Unmarshal(b []byte, m Message) error {