MCPcopy
hub / github.com/TarsCloud/TarsGo / WriteString

Method WriteString

tars/protocol/codec/codec.go:314–338  ·  view source on GitHub ↗

WriteString writes string data with the tag.

(data string, tag byte)

Source from the content-addressed store, hash-verified

312
313// WriteString writes string data with the tag.
314func (b *Buffer) WriteString(data string, tag byte) error {
315 var err error
316 if len(data) > 255 {
317 if err = b.WriteHead(STRING4, tag); err != nil {
318 return err
319 }
320
321 if err = bWriteU32(b.buf, uint32(len(data))); err != nil {
322 return err
323 }
324 } else {
325 if err = b.WriteHead(STRING1, tag); err != nil {
326 return err
327 }
328
329 if err = bWriteU8(b.buf, byte(len(data))); err != nil {
330 return err
331 }
332 }
333
334 if _, err = b.buf.WriteString(data); err != nil {
335 return err
336 }
337 return nil
338}
339
340// ToBytes make the buffer to []byte
341func (b *Buffer) ToBytes() []byte {

Callers 15

writeLineMethod · 0.95
TestSkipStringFunction · 0.95
BenchmarkStringFunction · 0.95
TestReader_unreadHeadFunction · 0.95
TestReader_SkipToNoCheckFunction · 0.95
LoggerWithContextMethod · 0.95
ListConfigWithContextMethod · 0.95
LoadConfigWithContextMethod · 0.95

Calls 3

WriteHeadMethod · 0.95
bWriteU32Function · 0.85
bWriteU8Function · 0.85

Tested by 4

TestSkipStringFunction · 0.76
BenchmarkStringFunction · 0.76
TestReader_unreadHeadFunction · 0.76
TestReader_SkipToNoCheckFunction · 0.76