golang定义func类型

如下,定义一个DecodeFunc类型,DecodeFunc是一个func([]byte, PacketBuilder)类型,可以通过d(data, p)调用

1
2
3
4
5
6
7
8
9
10
11
12
type DecodeFunc func([]byte, PacketBuilder) error

// Decode implements Decoder by calling itself.
func (d DecodeFunc) Decode(data []byte, p PacketBuilder) error {
// function, call thyself.
return d(data, p)
}

// DecodePayload is a Decoder that returns a Payload layer containing all
// remaining bytes.
var DecodePayload Decoder = DecodeFunc(decodePayload)
func decodePayload(data []byte, p PacketBuilder) error {return nil}

golang定义func类型
https://nrbackback.github.io/2023/02/06/golang定义func类型/
作者
John Doe
发布于
2023年2月6日
许可协议