1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-08 11:17:44 -05:00
v2fly/transport/internet/header.go

27 lines
461 B
Go
Raw Normal View History

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