| 239 | } |
| 240 | |
| 241 | func (e encoder) encodeBytes(b []byte, p unsafe.Pointer) ([]byte, error) { |
| 242 | v := *(*[]byte)(p) |
| 243 | if v == nil { |
| 244 | return append(b, "null"...), nil |
| 245 | } |
| 246 | |
| 247 | n := base64.StdEncoding.EncodedLen(len(v)) + 2 |
| 248 | |
| 249 | if avail := cap(b) - len(b); avail < n { |
| 250 | newB := make([]byte, cap(b)+(n-avail)) |
| 251 | copy(newB, b) |
| 252 | b = newB[:len(b)] |
| 253 | } |
| 254 | |
| 255 | i := len(b) |
| 256 | j := len(b) + n |
| 257 | |
| 258 | b = b[:j] |
| 259 | b[i] = '"' |
| 260 | base64.StdEncoding.Encode(b[i+1:j-1], v) |
| 261 | b[j-1] = '"' |
| 262 | return b, nil |
| 263 | } |
| 264 | |
| 265 | func (e encoder) encodeDuration(b []byte, p unsafe.Pointer) ([]byte, error) { |
| 266 | b = append(b, '"') |