// recvPeerFrameOfType waits for a new frame of a given type from the peer, failing // if the next frame received is not of that type func (mex *messageExchange) recvPeerFrameOfType(msgType messageType) (*Frame, error) { frame, err := mex.recvPeerFrame() if err != nil { return nil, err } switch frame.Header.messageType { case msgType: return frame, nil case messageTypeError: errMsg := errorMessage{ id: frame.Header.ID, } var rbuf typed.ReadBuffer rbuf.Wrap(frame.SizedPayload()) if err := errMsg.read(&rbuf); err != nil { return nil, err } return nil, errMsg.AsSystemError() default: // TODO(mmihic): Should be treated as a protocol error mex.mexset.log.Warnf("Received unexpected message %d for %d", int(frame.Header.messageType), frame.Header.ID) return nil, errUnexpectedFrameType } }
// ReadIn reads the frame from the given io.Reader func (f *Frame) ReadIn(r io.Reader) error { var rbuf typed.ReadBuffer rbuf.Wrap(f.headerBuffer) if _, err := rbuf.FillFrom(r, FrameHeaderSize); err != nil { return err } if err := f.Header.read(&rbuf); err != nil { return err } if f.Header.PayloadSize() > 0 { if _, err := io.ReadFull(r, f.SizedPayload()); err != nil { return err } } return nil }
func (f *Frame) read(msg message) error { var rbuf typed.ReadBuffer rbuf.Wrap(f.SizedPayload()) return msg.read(&rbuf) }