1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//!
//! # API Versions
//!
//! Public API to retrive a list of APIs and their version numbers from the SC.
//! SC supports Kafka as well as Fluvio specific APIs.
//!

use kf_protocol::api::Request;
use kf_protocol::derive::{Decode, Encode};
use kf_protocol::api::FlvErrorCode;

use crate::ScApiKey;

pub type ApiVersions = Vec<ApiVersionKey>;

/// Given an API key, it returns max_version. None if not found
pub fn lookup_version(api_key: ScApiKey, versions: &ApiVersions) -> Option<i16> {
    for version in versions {
        if version.api_key == api_key as i16 {
            return Some(version.max_version);
        }
    }
    None
}

// -----------------------------------
// ApiVersionsRequest
// -----------------------------------

#[derive(Decode, Encode, Default, Debug)]
pub struct ApiVersionsRequest {}

// -----------------------------------
// ApiVersionsResponse
// -----------------------------------

#[derive(Decode, Encode, Default, Debug)]
pub struct ApiVersionsResponse {
    pub error_code: FlvErrorCode,
    pub api_keys: Vec<ApiVersionKey>,
}

#[derive(Decode, Encode, Default, Debug)]
pub struct ApiVersionKey {
    pub api_key: i16,
    pub min_version: i16,
    pub max_version: i16,
}

// -----------------------------------
// Implementation - ApiVersionsRequest
// -----------------------------------

impl Request for ApiVersionsRequest {
    const API_KEY: u16 = ScApiKey::ApiVersion as u16;
    type Response = ApiVersionsResponse;
}