github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/srpc/frames.go (about)

     1  /* For license and copyright information please see LEGAL file in repository */
     2  
     3  package srpc
     4  
     5  import (
     6  	"../protocol"
     7  )
     8  
     9  func HandleFrames(conn protocol.Connection, frames []byte) (err protocol.Error) {
    10  	for len(frames) > 0 {
    11  		var frame = frame(frames)
    12  		switch frame.Type() {
    13  		case frameTypePadding:
    14  			var paddingFrame = paddingFrame(frame.Payload())
    15  			// Nothing to do, just ignore padding data
    16  			frames = paddingFrame.NextFrame()
    17  		case frameTypePing:
    18  			var pingFrame = pingFrame(frame.Payload())
    19  			// TODO:::
    20  			frames = pingFrame.NextFrame()
    21  		case frameTypeCallService:
    22  			var serviceFrame = serviceFrame(frame.Payload())
    23  			err = callService(conn, serviceFrame)
    24  			if err != nil {
    25  				return
    26  			}
    27  			frames = serviceFrame.NextFrame()
    28  		case frameTypeOpenStream:
    29  			var openStreamFrame = openStreamFrame(frame.Payload())
    30  			err = openStream(conn, openStreamFrame)
    31  			if err != nil {
    32  				return
    33  			}
    34  			frames = openStreamFrame.NextFrame()
    35  		case frameTypeData:
    36  			var dataFrame = dataFrame(frame.Payload())
    37  			err = appendData(conn, dataFrame)
    38  			if err != nil {
    39  				return
    40  			}
    41  			frames = dataFrame.NextFrame()
    42  		case frameTypeSignature:
    43  			var signatureFrame = signatureFrame(frame.Payload())
    44  			err = registerStreamSignature(conn, signatureFrame)
    45  			if err != nil {
    46  				return
    47  			}
    48  			frames = signatureFrame.NextFrame()
    49  		default:
    50  			// TODO:::
    51  		}
    52  	}
    53  	return
    54  }