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

Method ReadString

lib/go/thrift/compact_protocol.go:615–636  ·  view source on GitHub ↗

Reads a []byte (via readBinary), and then UTF-8 decodes it.

(ctx context.Context)

Source from the content-addressed store, hash-verified

613
614// Reads a []byte (via readBinary), and then UTF-8 decodes it.
615func (p *TCompactProtocol) ReadString(ctx context.Context) (value string, err error) {
616 length, e := p.readVarint32()
617 if e != nil {
618 return "", NewTProtocolException(e)
619 }
620 err = checkSizeForProtocol(length, p.cfg)
621 if err != nil {
622 return
623 }
624 if length == 0 {
625 return "", nil
626 }
627 if length < int32(len(p.buffer)) {
628 // Avoid allocation on small reads
629 buf := p.buffer[:length]
630 read, e := io.ReadFull(p.trans, buf)
631 return string(buf[:read]), NewTProtocolException(e)
632 }
633
634 buf, e := safeReadBytes(length, p.trans)
635 return string(buf), NewTProtocolException(e)
636}
637
638// Read a []byte from the wire.
639func (p *TCompactProtocol) ReadBinary(ctx context.Context) (value []byte, err error) {

Callers 2

parseHeadersMethod · 0.95
ReadMessageBeginMethod · 0.95

Calls 5

readVarint32Method · 0.95
NewTProtocolExceptionFunction · 0.85
checkSizeForProtocolFunction · 0.85
stringFunction · 0.85
safeReadBytesFunction · 0.85

Tested by

no test coverage detected