mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-09-05 19:44:32 -04:00
27 lines
461 B
Go
27 lines
461 B
Go
package internet
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"v2ray.com/core/common"
|
|
)
|
|
|
|
type PacketHeader interface {
|
|
Size() int
|
|
Write([]byte) (int, error)
|
|
}
|
|
|
|
func CreatePacketHeader(config interface{}) (PacketHeader, error) {
|
|
header, err := common.CreateObject(context.Background(), config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
switch h := header.(type) {
|
|
case PacketHeader:
|
|
return h, nil
|
|
default:
|
|
return nil, errors.New("Internet: Not a packet header.")
|
|
}
|
|
}
|