@@ -20,7 +20,6 @@ package transport
20
20
21
21
import (
22
22
"bufio"
23
- "bytes"
24
23
"encoding/base64"
25
24
"fmt"
26
25
"io"
@@ -251,13 +250,13 @@ func encodeGrpcMessage(msg string) string {
251
250
}
252
251
253
252
func encodeGrpcMessageUnchecked (msg string ) string {
254
- var buf bytes. Buffer
253
+ var sb strings. Builder
255
254
for len (msg ) > 0 {
256
255
r , size := utf8 .DecodeRuneInString (msg )
257
256
for _ , b := range []byte (string (r )) {
258
257
if size > 1 {
259
258
// If size > 1, r is not ascii. Always do percent encoding.
260
- buf . WriteString ( fmt .Sprintf ( "%%%02X" , b ) )
259
+ fmt .Fprintf ( & sb , "%%%02X" , b )
261
260
continue
262
261
}
263
262
@@ -266,14 +265,14 @@ func encodeGrpcMessageUnchecked(msg string) string {
266
265
//
267
266
// fmt.Sprintf("%%%02X", utf8.RuneError) gives "%FFFD".
268
267
if b >= spaceByte && b <= tildeByte && b != percentByte {
269
- buf .WriteByte (b )
268
+ sb .WriteByte (b )
270
269
} else {
271
- buf . WriteString ( fmt .Sprintf ( "%%%02X" , b ) )
270
+ fmt .Fprintf ( & sb , "%%%02X" , b )
272
271
}
273
272
}
274
273
msg = msg [size :]
275
274
}
276
- return buf .String ()
275
+ return sb .String ()
277
276
}
278
277
279
278
// decodeGrpcMessage decodes the msg encoded by encodeGrpcMessage.
@@ -291,23 +290,23 @@ func decodeGrpcMessage(msg string) string {
291
290
}
292
291
293
292
func decodeGrpcMessageUnchecked (msg string ) string {
294
- var buf bytes. Buffer
293
+ var sb strings. Builder
295
294
lenMsg := len (msg )
296
295
for i := 0 ; i < lenMsg ; i ++ {
297
296
c := msg [i ]
298
297
if c == percentByte && i + 2 < lenMsg {
299
298
parsed , err := strconv .ParseUint (msg [i + 1 :i + 3 ], 16 , 8 )
300
299
if err != nil {
301
- buf .WriteByte (c )
300
+ sb .WriteByte (c )
302
301
} else {
303
- buf .WriteByte (byte (parsed ))
302
+ sb .WriteByte (byte (parsed ))
304
303
i += 2
305
304
}
306
305
} else {
307
- buf .WriteByte (c )
306
+ sb .WriteByte (c )
308
307
}
309
308
}
310
- return buf .String ()
309
+ return sb .String ()
311
310
}
312
311
313
312
type bufWriter struct {
0 commit comments