github.com/xraypb/xray-core@v1.6.6/transport/internet/headers/srtp/srtp.go (about) 1 package srtp 2 3 import ( 4 "context" 5 "encoding/binary" 6 7 "github.com/xraypb/xray-core/common" 8 "github.com/xraypb/xray-core/common/dice" 9 ) 10 11 type SRTP struct { 12 header uint16 13 number uint16 14 } 15 16 func (*SRTP) Size() int32 { 17 return 4 18 } 19 20 // Serialize implements PacketHeader. 21 func (s *SRTP) Serialize(b []byte) { 22 s.number++ 23 binary.BigEndian.PutUint16(b, s.header) 24 binary.BigEndian.PutUint16(b[2:], s.number) 25 } 26 27 // New returns a new SRTP instance based on the given config. 28 func New(ctx context.Context, config interface{}) (interface{}, error) { 29 return &SRTP{ 30 header: 0xB5E8, 31 number: dice.RollUint16(), 32 }, nil 33 } 34 35 func init() { 36 common.Must(common.RegisterConfig((*Config)(nil), New)) 37 }