MCPcopy
hub / github.com/tinylib/msgp / WriteStringFromBytes

Method WriteStringFromBytes

msgp/write.go:537–558  ·  view source on GitHub ↗

WriteStringFromBytes writes a 'str' object from a []byte.

(str []byte)

Source from the content-addressed store, hash-verified

535// WriteStringFromBytes writes a 'str' object
536// from a []byte.
537func (mw *Writer) WriteStringFromBytes(str []byte) error {
538 if uint64(len(str)) > math.MaxUint32 {
539 return ErrLimitExceeded
540 }
541 sz := uint32(len(str))
542 var err error
543 switch {
544 case sz <= 31:
545 err = mw.push(wfixstr(uint8(sz)))
546 case sz <= math.MaxUint8:
547 err = mw.prefix8(mstr8, uint8(sz))
548 case sz <= math.MaxUint16:
549 err = mw.prefix16(mstr16, uint16(sz))
550 default:
551 err = mw.prefix32(mstr32, sz)
552 }
553 if err != nil {
554 return err
555 }
556 _, err = mw.Write(str)
557 return err
558}
559
560// WriteComplex64 writes a complex64 to the writer
561func (mw *Writer) WriteComplex64(f complex64) error {

Callers 1

Calls 6

pushMethod · 0.95
prefix8Method · 0.95
prefix16Method · 0.95
prefix32Method · 0.95
WriteMethod · 0.95
wfixstrFunction · 0.85

Tested by

no test coverage detected