-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathvirtual_port.go
31 lines (25 loc) · 1.12 KB
/
virtual_port.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package nex
import "github.com/PretendoNetwork/nex-go/v2/constants"
// VirtualPort in an implementation of rdv::VirtualPort.
// PRUDP will reuse a single physical socket connection for many virtual PRUDP connections.
// VirtualPorts are a byte which represents a stream for a virtual PRUDP connection.
// This byte is two 4-bit fields. The upper 4 bits are the stream type, the lower 4 bits
// are the stream ID. The client starts with stream ID 15, decrementing by one with each new
// virtual connection.
type VirtualPort byte
// SetStreamType sets the VirtualPort stream type
func (vp *VirtualPort) SetStreamType(streamType constants.StreamType) {
*vp = VirtualPort((byte(*vp) & 0x0F) | (byte(streamType) << 4))
}
// StreamType returns the VirtualPort stream type
func (vp VirtualPort) StreamType() constants.StreamType {
return constants.StreamType(vp >> 4)
}
// SetStreamID sets the VirtualPort stream ID
func (vp *VirtualPort) SetStreamID(streamID uint8) {
*vp = VirtualPort((byte(*vp) & 0xF0) | (streamID & 0x0F))
}
// StreamID returns the VirtualPort stream ID
func (vp VirtualPort) StreamID() uint8 {
return uint8(vp & 0xF)
}