iprotocol.go 434 B

123456789101112131415
  1. package nnet
  2. type IPacket interface {
  3. // if need to close socket after sending this packet
  4. ShouldClose() (bool, int32)
  5. }
  6. // Simple definition of Encoder/Decoder
  7. // NO middleware-like mechanism here, just do it directly within those 2 functions.
  8. type IProtocol interface {
  9. // parse by raw data to a packet
  10. ReadPacket(conn IConn) (IPacket, error)
  11. // encode user-impl packet to []byte
  12. Serialize(packet IPacket) ([]byte, error)
  13. }