| 280 | } |
| 281 | |
| 282 | func compressPayload(tmpbuf *[]byte, enc Compression, inp []byte) (compressed []byte, _ error) { |
| 283 | switch enc { |
| 284 | case SnappyBlockCompression: |
| 285 | if cap(*tmpbuf) < snappy.MaxEncodedLen(len(inp)) { |
| 286 | *tmpbuf = make([]byte, snappy.MaxEncodedLen(len(inp))) |
| 287 | } else { |
| 288 | *tmpbuf = (*tmpbuf)[:snappy.MaxEncodedLen(len(inp))] |
| 289 | } |
| 290 | |
| 291 | compressed = snappy.Encode(*tmpbuf, inp) |
| 292 | return compressed, nil |
| 293 | default: |
| 294 | return compressed, fmt.Errorf("unknown compression scheme [%v]", enc) |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | func (r *API) attemptWrite(ctx context.Context, compr Compression, msgType WriteMessageType, payload []byte, attempt int) (WriteResponseStats, error) { |
| 299 | req, err := http.NewRequest(http.MethodPost, r.baseURL.String(), bytes.NewReader(payload)) |