| 1439 | } |
| 1440 | |
| 1441 | func (c *Conn) ApiVersions() ([]ApiVersion, error) { |
| 1442 | deadline := &c.rdeadline |
| 1443 | |
| 1444 | if deadline.deadline().IsZero() { |
| 1445 | // ApiVersions is called automatically when API version negotiation |
| 1446 | // needs to happen, so we are not guaranteed that a read deadline has |
| 1447 | // been set yet. Fallback to use the write deadline in case it was |
| 1448 | // set, for example when version negotiation is initiated during a |
| 1449 | // produce request. |
| 1450 | deadline = &c.wdeadline |
| 1451 | } |
| 1452 | |
| 1453 | id, err := c.doRequest(deadline, func(_ time.Time, id int32) error { |
| 1454 | h := requestHeader{ |
| 1455 | ApiKey: int16(apiVersions), |
| 1456 | ApiVersion: int16(v0), |
| 1457 | CorrelationID: id, |
| 1458 | ClientID: c.clientID, |
| 1459 | } |
| 1460 | h.Size = (h.size() - 4) |
| 1461 | h.writeTo(&c.wb) |
| 1462 | return c.wbuf.Flush() |
| 1463 | }) |
| 1464 | if err != nil { |
| 1465 | return nil, err |
| 1466 | } |
| 1467 | |
| 1468 | _, size, lock, err := c.waitResponse(deadline, id) |
| 1469 | if err != nil { |
| 1470 | return nil, err |
| 1471 | } |
| 1472 | defer lock.Unlock() |
| 1473 | |
| 1474 | var errorCode int16 |
| 1475 | if size, err = readInt16(&c.rbuf, size, &errorCode); err != nil { |
| 1476 | return nil, err |
| 1477 | } |
| 1478 | var arrSize int32 |
| 1479 | if size, err = readInt32(&c.rbuf, size, &arrSize); err != nil { |
| 1480 | return nil, err |
| 1481 | } |
| 1482 | r := make([]ApiVersion, arrSize) |
| 1483 | for i := 0; i < int(arrSize); i++ { |
| 1484 | if size, err = readInt16(&c.rbuf, size, &r[i].ApiKey); err != nil { |
| 1485 | return nil, err |
| 1486 | } |
| 1487 | if size, err = readInt16(&c.rbuf, size, &r[i].MinVersion); err != nil { |
| 1488 | return nil, err |
| 1489 | } |
| 1490 | if size, err = readInt16(&c.rbuf, size, &r[i].MaxVersion); err != nil { |
| 1491 | return nil, err |
| 1492 | } |
| 1493 | } |
| 1494 | |
| 1495 | if errorCode != 0 { |
| 1496 | return r, Error(errorCode) |
| 1497 | } |
| 1498 | |