1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-10 00:29:01 +02:00
kratos/encoding/proto/proto.go
Tony Chen 496edc6fb1
Http/refactor register service (#734)
* refactor http handle
2021-03-03 22:22:59 +08:00

32 lines
695 B
Go

// Package proto defines the protobuf codec. Importing this package will
// register the codec.
package proto
import (
"github.com/go-kratos/kratos/v2/encoding"
"google.golang.org/protobuf/proto"
)
// 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
}