emitLiteral writes a literal chunk and returns the number of bytes written. It assumes that: dst is long enough to hold the encoded bytes 0 <= len(lit) && len(lit) <= math.MaxUint32
(dst, lit []byte)
| 78 | // dst is long enough to hold the encoded bytes |
| 79 | // 0 <= len(lit) && len(lit) <= math.MaxUint32 |
| 80 | func emitLiteral(dst, lit []byte) int { |
| 81 | if len(lit) == 0 { |
| 82 | return 0 |
| 83 | } |
| 84 | const num = 63<<2 | tagLiteral |
| 85 | i, n := 0, uint(len(lit)-1) |
| 86 | switch { |
| 87 | case n < 60: |
| 88 | dst[0] = uint8(n)<<2 | tagLiteral |
| 89 | i = 1 |
| 90 | case n < 1<<8: |
| 91 | dst[1] = uint8(n) |
| 92 | dst[0] = 60<<2 | tagLiteral |
| 93 | i = 2 |
| 94 | case n < 1<<16: |
| 95 | dst[2] = uint8(n >> 8) |
| 96 | dst[1] = uint8(n) |
| 97 | dst[0] = 61<<2 | tagLiteral |
| 98 | i = 3 |
| 99 | case n < 1<<24: |
| 100 | dst[3] = uint8(n >> 16) |
| 101 | dst[2] = uint8(n >> 8) |
| 102 | dst[1] = uint8(n) |
| 103 | dst[0] = 62<<2 | tagLiteral |
| 104 | i = 4 |
| 105 | default: |
| 106 | dst[4] = uint8(n >> 24) |
| 107 | dst[3] = uint8(n >> 16) |
| 108 | dst[2] = uint8(n >> 8) |
| 109 | dst[1] = uint8(n) |
| 110 | dst[0] = 63<<2 | tagLiteral |
| 111 | i = 5 |
| 112 | } |
| 113 | return i + copy(dst[i:], lit) |
| 114 | } |
| 115 | |
| 116 | // emitRepeat writes a repeat chunk and returns the number of bytes written. |
| 117 | // Length must be at least 4 and < 1<<24 |
no outgoing calls
searching dependent graphs…