-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wsutil: simplify send and recv extension interfaces
- Loading branch information
Showing
7 changed files
with
151 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
package wsutil | ||
|
||
import "github.com/gobwas/ws" | ||
|
||
// RecvExtension is an interface for clearing fragment header RSV bits. | ||
type RecvExtension interface { | ||
BitsRecv(seq int, rsv byte) (byte, error) | ||
UnsetBits(ws.Header) (ws.Header, error) | ||
} | ||
|
||
// RecvExtensionFunc is an adapter to allow the use of ordinary functions as | ||
// RecvExtension. | ||
type RecvExtensionFunc func(int, byte) (byte, error) | ||
type RecvExtensionFunc func(ws.Header) (ws.Header, error) | ||
|
||
// BitsRecv implements RecvExtension. | ||
func (fn RecvExtensionFunc) BitsRecv(seq int, rsv byte) (byte, error) { | ||
return fn(seq, rsv) | ||
func (fn RecvExtensionFunc) UnsetBits(h ws.Header) (ws.Header, error) { | ||
return fn(h) | ||
} | ||
|
||
// SendExtension is an interface for setting fragment header RSV bits. | ||
type SendExtension interface { | ||
BitsSend(seq int, rsv byte) (byte, error) | ||
SetBits(ws.Header) (ws.Header, error) | ||
} | ||
|
||
// SendExtensionFunc is an adapter to allow the use of ordinary functions as | ||
// SendExtension. | ||
type SendExtensionFunc func(int, byte) (byte, error) | ||
type SendExtensionFunc func(ws.Header) (ws.Header, error) | ||
|
||
// BitsSend implements SendExtension. | ||
func (fn SendExtensionFunc) BitsSend(seq int, rsv byte) (byte, error) { | ||
return fn(seq, rsv) | ||
func (fn SendExtensionFunc) SetBits(h ws.Header) (ws.Header, error) { | ||
return fn(h) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters