MCPcopy Create free account
hub / github.com/aws/smithy-go / encodeByteSlice

Function encodeByteSlice

encoding/xml/value.go:267–292  ·  view source on GitHub ↗

encodeByteSlice is modified copy of json encoder's encodeByteSlice. It is used to base64 encode a byte slice.

(w writer, scratch []byte, v []byte)

Source from the content-addressed store, hash-verified

265// encodeByteSlice is modified copy of json encoder's encodeByteSlice.
266// It is used to base64 encode a byte slice.
267func encodeByteSlice(w writer, scratch []byte, v []byte) {
268 if v == nil {
269 return
270 }
271
272 encodedLen := base64.StdEncoding.EncodedLen(len(v))
273 if encodedLen <= len(scratch) {
274 // If the encoded bytes fit in e.scratch, avoid an extra
275 // allocation and use the cheaper Encoding.Encode.
276 dst := scratch[:encodedLen]
277 base64.StdEncoding.Encode(dst, v)
278 w.Write(dst)
279 } else if encodedLen <= 1024 {
280 // The encoded bytes are short enough to allocate for, and
281 // Encoding.Encode is still cheaper.
282 dst := make([]byte, encodedLen)
283 base64.StdEncoding.Encode(dst, v)
284 w.Write(dst)
285 } else {
286 // The encoded bytes are too long to cheaply allocate, and
287 // Encoding.Encode is no longer noticeably cheaper.
288 enc := base64.NewEncoder(base64.StdEncoding, w)
289 enc.Write(v)
290 enc.Close()
291 }
292}
293
294// IsFlattened returns true if value is for flattened shape.
295func (xv Value) IsFlattened() bool {

Callers 1

Base64EncodeBytesMethod · 0.70

Calls 3

WriteMethod · 0.65
EncodeMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected