mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
669 B
33 lines
669 B
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
|
|
}
|