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

     1  /* For license and copyright information please see LEGAL file in repository */
     2  
     3  package srpc
     4  
     5  import (
     6  	"../protocol"
     7  	"../syllab"
     8  )
     9  
    10  /*
    11  type serviceFrame struct {
    12  	Length     [2]byte // including the header fields
    13  	ServiceID  uint64
    14  	CompressID uint64
    15  	Time       int64 // It is used to match the request and response and drop if TTL
    16  	Payload    []byte
    17  }
    18  */
    19  type serviceFrame []byte
    20  
    21  func (f serviceFrame) Length() uint16     { return syllab.GetUInt16(f, 0) }
    22  func (f serviceFrame) ServiceID() uint64  { return syllab.GetUInt64(f, 2) }
    23  func (f serviceFrame) CompressID() uint64 { return syllab.GetUInt64(f, 10) }
    24  func (f serviceFrame) Time() int64        { return syllab.GetInt64(f, 18) }
    25  func (f serviceFrame) Payload() []byte    { return f[26:f.Length()] }
    26  func (f serviceFrame) NextFrame() []byte  { return f[f.Length():] }
    27  
    28  // callService use to call a service without need to open any stream.
    29  // It can also use when service request data is smaller than network MTU.
    30  // Or use for time sensitive data like audio and video that streams shape in app layer
    31  func callService(conn protocol.Connection, frame serviceFrame) (err protocol.Error) {
    32  	// var serviceID uint32 = serviceFrame.ServiceID()
    33  	// TODO:::
    34  	return
    35  }