base64_amd64.go raw
1 // +build amd64,go1.17,!go1.25
2
3 package rt
4
5 import (
6 _ "unsafe"
7 "github.com/cloudwego/base64x"
8 )
9
10 func DecodeBase64(raw []byte) ([]byte, error) {
11 ret := make([]byte, base64x.StdEncoding.DecodedLen(len(raw)))
12 n, err := base64x.StdEncoding.Decode(ret, raw)
13 if err != nil {
14 return nil, err
15 }
16 return ret[:n], nil
17 }
18
19 func EncodeBase64ToString(src []byte) string {
20 return base64x.StdEncoding.EncodeToString(src)
21 }
22
23 func EncodeBase64(buf []byte, src []byte) []byte {
24 if len(src) == 0 {
25 return append(buf, '"', '"')
26 }
27 buf = append(buf, '"')
28 need := base64x.StdEncoding.EncodedLen(len(src))
29 if cap(buf) - len(buf) < need {
30 tmp := make([]byte, len(buf), len(buf) + need*2)
31 copy(tmp, buf)
32 buf = tmp
33 }
34 base64x.StdEncoding.Encode(buf[len(buf):cap(buf)], src)
35 buf = buf[:len(buf) + need]
36 buf = append(buf, '"')
37 return buf
38 }
39
40 //go:linkname SubrB64Decode github.com/cloudwego/base64x._subr__b64decode
41 var SubrB64Decode uintptr
42
43 //go:linkname SubrB64Encode github.com/cloudwego/base64x._subr__b64encode
44 var SubrB64Encode uintptr
45