| 1 |
package frame |
| 2 |
|
| 3 |
const ( |
| 4 |
// offsets for packing/unpacking frames |
| 5 |
lengthOffset = 32 + 16 |
| 6 |
flagsOffset = 32 + 8 |
| 7 |
typeOffset = 32 + 3 |
| 8 |
|
| 9 |
// masks for packing/unpacking frames |
| 10 |
lengthMask = 0x3FFF |
| 11 |
streamMask = 0x7FFFFFFF |
| 12 |
flagsMask = 0xFF |
| 13 |
typeMask = 0x1F |
| 14 |
wndIncMask = 0x7FFFFFFF |
| 15 |
priorityMask = 0x7FFFFFFF |
| 16 |
) |
| 17 |
|
| 18 |
// a frameType is a 5-bit integer in the frame header that identifies the type of frame |
| 19 |
type FrameType uint8 |
| 20 |
|
| 21 |
const ( |
| 22 |
TypeStreamSyn = 0x1 |
| 23 |
TypeStreamRst = 0x2 |
| 24 |
TypeStreamData = 0x3 |
| 25 |
TypeStreamWndInc = 0x4 |
| 26 |
TypeStreamPri = 0x5 |
| 27 |
TypeGoAway = 0x6 |
| 28 |
) |
| 29 |
|
| 30 |
// a flagsType is an 8-bit integer containing frame-specific flag bits in the frame header |
| 31 |
type flagsType uint8 |
| 32 |
|
| 33 |
const ( |
| 34 |
flagFin = 0x1 |
| 35 |
flagStreamPriority = 0x2 |
| 36 |
flagStreamType = 0x4 |
| 37 |
) |
| 38 |
|
| 39 |
func (ft flagsType) IsSet(f flagsType) bool { |
| 40 |
return (ft & f) != 0 |
| 41 |
} |
| 42 |
|
| 43 |
func (ft *flagsType) Set(f flagsType) { |
| 44 |
*ft |= f |
| 45 |
} |
| 46 |
|
| 47 |
func (ft *flagsType) Unset(f flagsType) { |
| 48 |
*ft = *ft &^ f |
| 49 |
} |
| 50 |
|
| 51 |
// StreamId is 31-bit integer uniquely identifying a stream within a session |
| 52 |
type StreamId uint32 |
| 53 |
|
| 54 |
// StreamPriority is 31-bit integer specifying a stream's priority |
| 55 |
type StreamPriority uint32 |
| 56 |
|
| 57 |
// StreamType is 32-bit integer specifying a stream's type |
| 58 |
type StreamType uint32 |
| 59 |
|
| 60 |
// ErrorCode is a 32-bit integer indicating a error condition included in rst/goaway frames |
| 61 |
type ErrorCode uint32 |