AppendInt64 appends an int64 to the slice
(b []byte, i int64)
| 93 | |
| 94 | // AppendInt64 appends an int64 to the slice |
| 95 | func AppendInt64(b []byte, i int64) []byte { |
| 96 | if i >= 0 { |
| 97 | switch { |
| 98 | case i <= math.MaxInt8: |
| 99 | return append(b, wfixint(uint8(i))) |
| 100 | case i <= math.MaxInt16: |
| 101 | o, n := ensure(b, 3) |
| 102 | putMint16(o[n:], int16(i)) |
| 103 | return o |
| 104 | case i <= math.MaxInt32: |
| 105 | o, n := ensure(b, 5) |
| 106 | putMint32(o[n:], int32(i)) |
| 107 | return o |
| 108 | default: |
| 109 | o, n := ensure(b, 9) |
| 110 | putMint64(o[n:], i) |
| 111 | return o |
| 112 | } |
| 113 | } |
| 114 | switch { |
| 115 | case i >= -32: |
| 116 | return append(b, wnfixint(int8(i))) |
| 117 | case i >= math.MinInt8: |
| 118 | o, n := ensure(b, 2) |
| 119 | putMint8(o[n:], int8(i)) |
| 120 | return o |
| 121 | case i >= math.MinInt16: |
| 122 | o, n := ensure(b, 3) |
| 123 | putMint16(o[n:], int16(i)) |
| 124 | return o |
| 125 | case i >= math.MinInt32: |
| 126 | o, n := ensure(b, 5) |
| 127 | putMint32(o[n:], int32(i)) |
| 128 | return o |
| 129 | default: |
| 130 | o, n := ensure(b, 9) |
| 131 | putMint64(o[n:], i) |
| 132 | return o |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | // AppendInt appends an int to the slice |
| 137 | func AppendInt(b []byte, i int) []byte { return AppendInt64(b, int64(i)) } |
searching dependent graphs…