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)
| 56 | // if chunk size is less then 4, then it is padded before encoding. |
| 57 | // return written bytes |
| 58 | func 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 | |
| 92 | var decode_base = [5]uint32{85 * 85 * 85 * 85, 85 * 85 * 85, 85 * 85, 85, 1} |
| 93 |