1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-15 16:56:08 -05:00
v2fly/transport/internet/header.go
2016-12-09 12:08:25 +01:00

33 lines
669 B
Go

package internet
import "v2ray.com/core/common"
type PacketHeader interface {
Size() int
Write([]byte) (int, error)
}
type PacketHeaderFactory interface {
Create(interface{}) PacketHeader
}
var (
headerCache = make(map[string]PacketHeaderFactory)
)
func RegisterPacketHeader(name string, factory PacketHeaderFactory) error {
if _, found := headerCache[name]; found {
return common.ErrDuplicatedName
}
headerCache[name] = factory
return nil
}
func CreatePacketHeader(name string, config interface{}) (PacketHeader, error) {
factory, found := headerCache[name]
if !found {
return nil, common.ErrObjectNotFound
}
return factory.Create(config), nil
}