gmessages/libgm/binary/protoUtil.go

24 lines
487 B
Go
Raw Normal View History

2023-06-30 09:54:08 +00:00
package binary
import (
"fmt"
2023-06-30 09:55:49 +00:00
2023-06-30 09:54:08 +00:00
"google.golang.org/protobuf/proto"
)
func EncodeProtoMessage(message proto.Message) ([]byte, error) {
data, err := proto.Marshal(message)
if err != nil {
return nil, fmt.Errorf("failed to encode proto message: %v", err)
}
return data, nil
}
func DecodeProtoMessage(data []byte, message proto.Message) error {
err := proto.Unmarshal(data, message)
if err != nil {
return fmt.Errorf("failed to decode proto message: %v", err)
}
return nil
2023-06-30 09:55:49 +00:00
}