MCPcopy
hub / github.com/go-sql-driver/mysql / appendLengthEncodedInteger

Function appendLengthEncodedInteger

utils.go:594–608  ·  view source on GitHub ↗

encodes a uint64 value and appends it to the given bytes slice

(b []byte, n uint64)

Source from the content-addressed store, hash-verified

592
593// encodes a uint64 value and appends it to the given bytes slice
594func appendLengthEncodedInteger(b []byte, n uint64) []byte {
595 switch {
596 case n <= 250:
597 return append(b, byte(n))
598
599 case n <= 0xffff:
600 b = append(b, 0xfc)
601 return binary.LittleEndian.AppendUint16(b, uint16(n))
602
603 case n <= 0xffffff:
604 return append(b, 0xfd, byte(n), byte(n>>8), byte(n>>16))
605 }
606 b = append(b, 0xfe)
607 return binary.LittleEndian.AppendUint64(b, n)
608}
609
610func appendLengthEncodedString(b []byte, s string) []byte {
611 b = appendLengthEncodedInteger(b, uint64(len(s)))

Callers 4

TestLengthEncodedIntegerFunction · 0.85
writeExecutePacketMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestLengthEncodedIntegerFunction · 0.68