encodeByteSlice is modified copy of json encoder's encodeByteSlice. It is used to base64 encode a byte slice.
(w writer, scratch []byte, v []byte)
| 265 | // encodeByteSlice is modified copy of json encoder's encodeByteSlice. |
| 266 | // It is used to base64 encode a byte slice. |
| 267 | func 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. |
| 295 | func (xv Value) IsFlattened() bool { |
no test coverage detected