github.com/nyan233/littlerpc@v0.4.6-0.20230316182519-0c8d5c48abaf/core/common/msgparser/nomux_handler.go (about) 1 package msgparser 2 3 import ( 4 message2 "github.com/nyan233/littlerpc/core/protocol/message" 5 ) 6 7 type noMuxHandler struct { 8 } 9 10 func (n *noMuxHandler) Header() []byte { 11 return []byte{message2.MagicNumber} 12 } 13 14 func (n *noMuxHandler) BaseLen() (BaseLenType, int) { 15 return MultiRequest, message2.BaseLen 16 } 17 18 func (n *noMuxHandler) MessageLength(base []byte) int { 19 var msg message2.Message 20 if err := message2.UnmarshalFromMux(base, &msg); err != nil { 21 return -1 22 } 23 return int(msg.Length()) 24 } 25 26 func (n *noMuxHandler) Unmarshal(data []byte, msg *message2.Message) (Action, error) { 27 err := message2.Unmarshal(data, msg) 28 if err != nil { 29 return -1, err 30 } 31 return UnmarshalComplete, nil 32 }