File: adaptor.go

package info (click to toggle)
golang-github-inconshreveable-muxado 0.0~git20140312.0.f693c7e-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 256 kB
  • sloc: makefile: 2
file content (54 lines) | stat: -rw-r--r-- 1,511 bytes parent folder | download | duplicates (3)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package muxado

import (
	"github.com/inconshreveable/muxado/proto"
	"github.com/inconshreveable/muxado/proto/frame"
)

// streamAdaptor recasts the types of some function calls by the proto/Stream implementation
// so that it satisfies the public interface
type streamAdaptor struct {
	proto.IStream
}

func (a *streamAdaptor) Id() StreamId {
	return StreamId(a.IStream.Id())
}

func (a *streamAdaptor) StreamType() StreamType {
	return StreamType(a.IStream.StreamType())
}

func (a *streamAdaptor) Session() Session {
	return &sessionAdaptor{a.IStream.Session()}
}

// sessionAdaptor recasts the types of some function calls by the proto/Session implementation
// so that it satisfies the public interface
type sessionAdaptor struct {
	proto.ISession
}

func (a *sessionAdaptor) Accept() (Stream, error) {
	str, err := a.ISession.Accept()
	return &streamAdaptor{str}, err
}

func (a *sessionAdaptor) Open() (Stream, error) {
	str, err := a.ISession.Open()
	return &streamAdaptor{str}, err
}

func (a *sessionAdaptor) OpenStream(priority StreamPriority, streamType StreamType, fin bool) (Stream, error) {
	str, err := a.ISession.OpenStream(frame.StreamPriority(priority), frame.StreamType(streamType), fin)
	return &streamAdaptor{str}, err
}

func (a *sessionAdaptor) GoAway(code ErrorCode, debug []byte) error {
	return a.ISession.GoAway(frame.ErrorCode(code), debug)
}

func (a *sessionAdaptor) Wait() (ErrorCode, error, []byte) {
	code, err, debug := a.ISession.Wait()
	return ErrorCode(code), err, debug
}