Debian Codegraph @

adaptor.go

raw
1 package muxado
2
3 import (
4 "github.com/inconshreveable/muxado/proto"
5 "github.com/inconshreveable/muxado/proto/frame"
6 )
7
8 // streamAdaptor recasts the types of some function calls by the proto/Stream implementation
9 // so that it satisfies the public interface
10 type streamAdaptor struct {
11 proto.IStream
12 }
13
14 func (a *streamAdaptor) Id() StreamId {
15 return StreamId(a.IStream.Id())
16 }
17
18 func (a *streamAdaptor) StreamType() StreamType {
19 return StreamType(a.IStream.StreamType())
20 }
21
22 func (a *streamAdaptor) Session() Session {
23 return &sessionAdaptor{a.IStream.Session()}
24 }
25
26 // sessionAdaptor recasts the types of some function calls by the proto/Session implementation
27 // so that it satisfies the public interface
28 type sessionAdaptor struct {
29 proto.ISession
30 }
31
32 func (a *sessionAdaptor) Accept() (Stream, error) {
33 str, err := a.ISession.Accept()
34 return &streamAdaptor{str}, err
35 }
36
37 func (a *sessionAdaptor) Open() (Stream, error) {
38 str, err := a.ISession.Open()
39 return &streamAdaptor{str}, err
40 }
41
42 func (a *sessionAdaptor) OpenStream(priority StreamPriority, streamType StreamType, fin bool) (Stream, error) {
43 str, err := a.ISession.OpenStream(frame.StreamPriority(priority), frame.StreamType(streamType), fin)
44 return &streamAdaptor{str}, err
45 }
46
47 func (a *sessionAdaptor) GoAway(code ErrorCode, debug []byte) error {
48 return a.ISession.GoAway(frame.ErrorCode(code), debug)
49 }
50
51 func (a *sessionAdaptor) Wait() (ErrorCode, error, []byte) {
52 code, err, debug := a.ISession.Wait()
53 return ErrorCode(code), err, debug
54 }