1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-03-19 21:18:07 +02:00
jessetang 3393990cd8
test(encoding/form/encode): add test and fix code style ()
* test(encoding/form/encode): add test and fix code style

Signed-off-by: demoManito <1430482733@qq.com>

* fix lint

Signed-off-by: demoManito <1430482733@qq.com>

Signed-off-by: demoManito <1430482733@qq.com>
2022-11-30 12:17:19 +08:00

32 lines
695 B
Go

// Package proto defines the protobuf codec. Importing this package will
// register the codec.
package proto
import (
"google.golang.org/protobuf/proto"
"github.com/go-kratos/kratos/v2/encoding"
)
// Name is the name registered for the proto compressor.
const Name = "proto"
func init() {
encoding.RegisterCodec(codec{})
}
// codec is a Codec implementation with protobuf. It is the default codec for Transport.
type codec struct{}
func (codec) Marshal(v interface{}) ([]byte, error) {
return proto.Marshal(v.(proto.Message))
}
func (codec) Unmarshal(data []byte, v interface{}) error {
return proto.Unmarshal(data, v.(proto.Message))
}
func (codec) Name() string {
return Name
}