MCPcopy Create free account
hub / github.com/apache/thrift / ReadMessageBegin

Method ReadMessageBegin

lib/go/thrift/compact_protocol.go:370–412  ·  view source on GitHub ↗

Reading methods. Read a message header.

(ctx context.Context)

Source from the content-addressed store, hash-verified

368
369// Read a message header.
370func (p *TCompactProtocol) ReadMessageBegin(ctx context.Context) (name string, typeId TMessageType, seqId int32, err error) {
371 var protocolId byte
372
373 _, deadlineSet := ctx.Deadline()
374 for {
375 protocolId, err = p.readByteDirect()
376 if deadlineSet && isTimeoutError(err) && ctx.Err() == nil {
377 // keep retrying I/O timeout errors since we still have
378 // time left
379 continue
380 }
381 // For anything else, don't retry
382 break
383 }
384 if err != nil {
385 return
386 }
387
388 if protocolId != COMPACT_PROTOCOL_ID {
389 e := fmt.Errorf("Expected protocol id %02x but got %02x", COMPACT_PROTOCOL_ID, protocolId)
390 return "", typeId, seqId, NewTProtocolExceptionWithType(BAD_VERSION, e)
391 }
392
393 versionAndType, err := p.readByteDirect()
394 if err != nil {
395 return
396 }
397
398 version := versionAndType & COMPACT_VERSION_MASK
399 typeId = TMessageType((versionAndType >> COMPACT_TYPE_SHIFT_AMOUNT) & COMPACT_TYPE_BITS)
400 if version != COMPACT_VERSION {
401 e := fmt.Errorf("Expected version %02x but got %02x", COMPACT_VERSION, version)
402 err = NewTProtocolExceptionWithType(BAD_VERSION, e)
403 return
404 }
405 seqId, e := p.readVarint32()
406 if e != nil {
407 err = NewTProtocolException(e)
408 return
409 }
410 name, err = p.ReadString(ctx)
411 return
412}
413
414func (p *TCompactProtocol) ReadMessageEnd(ctx context.Context) error { return nil }
415

Callers

nothing calls this directly

Calls 8

readByteDirectMethod · 0.95
readVarint32Method · 0.95
ReadStringMethod · 0.95
isTimeoutErrorFunction · 0.85
NewTProtocolExceptionFunction · 0.85
TMessageTypeTypeAlias · 0.70
ErrMethod · 0.65

Tested by

no test coverage detected