MCPcopy
hub / github.com/kovidgoyal/kitty / encodeChunk

Function encodeChunk

tools/utils/base85/base85.go:58–90  ·  view source on GitHub ↗

encodeChunk encodes 4 byte-chunk to 5 byte if chunk size is less then 4, then it is padded before encoding. return written bytes

(dst, src []byte)

Source from the content-addressed store, hash-verified

56// if chunk size is less then 4, then it is padded before encoding.
57// return written bytes
58func encodeChunk(dst, src []byte) int {
59 if len(src) == 0 {
60 return 0
61 }
62
63 //read 4 byte as big-endian uint32 into small endian uint32
64 var val uint32
65 switch len(src) {
66 default:
67 val |= uint32(src[3])
68 fallthrough
69 case 3:
70 val |= uint32(src[2]) << 8
71 fallthrough
72 case 2:
73 val |= uint32(src[1]) << 16
74 fallthrough
75 case 1:
76 val |= uint32(src[0]) << 24
77 }
78
79 buf := [5]byte{0, 0, 0, 0, 0}
80
81 for i := 4; i >= 0; i-- {
82 r := val % 85
83 val /= 85
84 buf[i] = encode[r]
85 }
86
87 m := EncodedLen(len(src))
88 copy(dst[:], buf[:m])
89 return m
90}
91
92var decode_base = [5]uint32{85 * 85 * 85 * 85, 85 * 85 * 85, 85 * 85, 85, 1}
93

Callers 4

EncodeFunction · 0.85
WriteMethod · 0.85
CloseMethod · 0.85
TestBase85Function · 0.85

Calls 1

EncodedLenFunction · 0.85

Tested by 1

TestBase85Function · 0.68