v2ray-core/transport/internet/header.go

27 lines
461 B
Go
Raw Normal View History

2016-12-08 15:27:41 +00:00
package internet
2017-01-12 21:47:10 +00:00
import (
"context"
"errors"
"v2ray.com/core/common"
)
2016-12-08 15:27:41 +00:00
type PacketHeader interface {
Size() int
2016-12-09 11:08:25 +00:00
Write([]byte) (int, error)
2016-12-08 15:27:41 +00:00
}
2017-01-12 21:47:10 +00:00
func CreatePacketHeader(config interface{}) (PacketHeader, error) {
header, err := common.CreateObject(context.Background(), config)
if err != nil {
return nil, err
2016-12-08 15:27:41 +00:00
}
2017-01-12 21:47:10 +00:00
switch h := header.(type) {
case PacketHeader:
return h, nil
default:
return nil, errors.New("Internet: Not a packet header.")
2016-12-08 15:27:41 +00:00
}
}