Source File
proto.go
Belonging Package
google.golang.org/grpc/encoding/proto
package proto
import (
)
const Name = "proto"
func () {
encoding.RegisterCodec(codec{})
}
type codec struct{}
type cachedProtoBuffer struct {
lastMarshaledSize uint32
proto.Buffer
}
func ( int) uint32 {
if > math.MaxInt32 {
return uint32(math.MaxInt32)
}
return uint32()
}
func ( interface{}, *cachedProtoBuffer) ([]byte, error) {
:= .(proto.Message)
:= make([]byte, 0, .lastMarshaledSize)
.SetBuf()
.Reset()
if := .Marshal(); != nil {
return nil,
}
:= .Bytes()
.lastMarshaledSize = capToMaxInt32(len())
return , nil
}
func (codec) ( interface{}) ([]byte, error) {
return .Marshal()
}
:= protoBufferPool.Get().(*cachedProtoBuffer)
, := marshal(, )
return .Unmarshal()
}
:= protoBufferPool.Get().(*cachedProtoBuffer)
.SetBuf()
:= .Unmarshal()
.SetBuf(nil)
protoBufferPool.Put()
return
}
func (codec) () string {
return Name
}
var protoBufferPool = &sync.Pool{
New: func() interface{} {
return &cachedProtoBuffer{
Buffer: proto.Buffer{},
lastMarshaledSize: 16,
}
},
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |