@@ -292,15 +292,14 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
292292 pktLen += n + 1
293293 }
294294
295- // 1 byte to store length of all key-values
296- // NOTE: Actually, this is length encoded integer.
297- // But we support only len(connAttrBuf) < 251 for now because takeSmallBuffer
298- // doesn't support buffer size more than 4096 bytes.
299- // TODO(methane): Rewrite buffer management.
300- pktLen += 1 + len (mc .connector .encodedAttributes )
295+ // encode length of the connection attributes
296+ var connAttrsLEIBuf [9 ]byte
297+ connAttrsLen := len (mc .connector .encodedAttributes )
298+ connAttrsLEI := appendLengthEncodedInteger (connAttrsLEIBuf [:0 ], uint64 (connAttrsLen ))
299+ pktLen += len (connAttrsLEI ) + len (mc .connector .encodedAttributes )
301300
302301 // Calculate packet length and get buffer with that size
303- data , err := mc .buf .takeSmallBuffer (pktLen + 4 )
302+ data , err := mc .buf .takeBuffer (pktLen + 4 )
304303 if err != nil {
305304 // cannot take the buffer. Something must be wrong with the connection
306305 mc .cfg .Logger .Print (err )
@@ -380,8 +379,7 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
380379 pos ++
381380
382381 // Connection Attributes
383- data [pos ] = byte (len (mc .connector .encodedAttributes ))
384- pos ++
382+ pos += copy (data [pos :], connAttrsLEI )
385383 pos += copy (data [pos :], []byte (mc .connector .encodedAttributes ))
386384
387385 // Send Auth packet
0 commit comments