MCPcopy Create free account
hub / github.com/apecloud/myduckserver / appendStringLength

Function appendStringLength

binlogreplication/binlog_json_serialization.go:308–327  ·  view source on GitHub ↗

appendStringLength appends a variable number of bytes to the specified |bytes| to encode |length|, the length of a string. For string lengths, if the length is larger than 127 bytes, we set the high bit of the first byte and use two bytes to encode the length. Similarly, if the high bit of the secon

(bytes []byte, length int)

Source from the content-addressed store, hash-verified

306// length of a string. For string lengths, if the length is larger than 127 bytes, we set the high bit of
307// the first byte and use two bytes to encode the length. Similarly, if the high bit of the second byte is
308// also set, the length is encoded over three bytes.
309func appendStringLength(bytes []byte, length int) ([]byte, error) {
310 switch {
311 case length > 0x1FFFFF:
312 return nil, fmt.Errorf("strings larger than 2,097,151 bytes not supported")
313
314 case length > 0x3FFF: // 16,383
315 return append(bytes,
316 byte(length&0x7F|0x80),
317 byte(length>>7|0x80),
318 byte(length>>14)), nil
319
320 case length > 0x7F: // 127
321 return append(bytes,
322 byte(length&0x7F|0x80),
323 byte(length>>7)), nil
324
325 default:
326 return append(bytes, byte(length)), nil
327 }
328}
329
330// calculateInitialArrayValuesOffset returns the initial offset value for the first array value in the

Callers 1

encodeJsonValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected