예제 #1
0
파일: tracing.go 프로젝트: uber/tchannel-go
func (s *Span) read(r *typed.ReadBuffer) error {
	s.spanID = r.ReadUint64()
	s.parentID = r.ReadUint64()
	s.traceID = r.ReadUint64()
	s.flags = r.ReadSingleByte()
	return r.Err()
}
예제 #2
0
func (m *callRes) read(r *typed.ReadBuffer) error {
	m.ResponseCode = ResponseCode(r.ReadSingleByte())
	m.Tracing.read(r)
	m.Headers = transportHeaders{}
	m.Headers.read(r)
	return r.Err()
}
예제 #3
0
파일: mex.go 프로젝트: dansimau/ringpop-go
// recvPeerFrameOfType waits for a new frame of a given type from the peer, failing
// if the next frame received is not of that type.
// If an error frame is returned, then the errorMessage is returned as the error.
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

	default:
		// TODO(mmihic): Should be treated as a protocol error
		mex.mexset.log.Warnf("Received unexpected message %v, expected %v for %d",
			frame.Header.messageType, msgType, frame.Header.ID)

		return nil, errUnexpectedFrameType
	}
}
예제 #4
0
파일: mex.go 프로젝트: uber/tchannel-go
// recvPeerFrameOfType waits for a new frame of a given type from the peer, failing
// if the next frame received is not of that type.
// If an error frame is returned, then the errorMessage is returned as the error.
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:
		// If we read an error frame, we can release it once we deserialize it.
		defer mex.framePool.Release(frame)

		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

	default:
		// TODO(mmihic): Should be treated as a protocol error
		mex.mexset.log.WithFields(
			LogField{"header", frame.Header},
			LogField{"expectedType", msgType},
			LogField{"expectedID", mex.msgID},
		).Warn("Received unexpected frame.")
		return nil, errUnexpectedFrameType
	}
}
예제 #5
0
func (ch transportHeaders) read(r *typed.ReadBuffer) {
	nh := r.ReadSingleByte()
	for i := 0; i < int(nh); i++ {
		k := r.ReadLen8String()
		v := r.ReadLen8String()
		ch[TransportHeaderName(k)] = v
	}
}
예제 #6
0
파일: buf.go 프로젝트: gosuper/tchannel-go
func readHeaders(rb *typed.ReadBuffer, form http.Header) {
	numHeaders := rb.ReadUint16()
	for i := 0; i < int(numHeaders); i++ {
		k := rb.ReadLen16String()
		v := rb.ReadLen16String()
		form[k] = append(form[k], v)
	}
}
예제 #7
0
// 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
}
예제 #8
0
func (m *initMessage) read(r *typed.ReadBuffer) error {
	m.Version = r.ReadUint16()

	m.initParams = initParams{}
	np := r.ReadUint16()
	for i := 0; i < int(np); i++ {
		k := r.ReadLen16String()
		v := r.ReadLen16String()
		m.initParams[k] = v
	}

	return r.Err()
}
예제 #9
0
func (m *callReq) read(r *typed.ReadBuffer) error {
	m.TimeToLive = time.Duration(r.ReadUint32()) * time.Millisecond
	m.Tracing.read(r)
	m.Service = r.ReadLen8String()
	m.Headers = transportHeaders{}
	m.Headers.read(r)
	return r.Err()
}
예제 #10
0
func (m *errorMessage) read(r *typed.ReadBuffer) error {
	m.errCode = SystemErrCode(r.ReadSingleByte())
	m.tracing.read(r)
	m.message = r.ReadLen16String()
	return r.Err()
}
예제 #11
0
func (fh *FrameHeader) read(r *typed.ReadBuffer) error {
	fh.size = r.ReadUint16()
	fh.messageType = messageType(r.ReadSingleByte())
	fh.reserved1 = r.ReadSingleByte()
	fh.ID = r.ReadUint32()
	r.ReadBytes(len(fh.reserved))
	return r.Err()
}
예제 #12
0
func (f *Frame) read(msg message) error {
	var rbuf typed.ReadBuffer
	rbuf.Wrap(f.SizedPayload())
	return msg.read(&rbuf)
}
예제 #13
0
파일: buf.go 프로젝트: gosuper/tchannel-go
func readVarintString(rb *typed.ReadBuffer) string {
	length := rb.ReadUvarint()
	return rb.ReadString(int(length))
}