gestalt-sdk 0.0.1-alpha.19

Rust SDK scaffolding and generated protocol bindings for Gestalt executable providers
Documentation
// Code generated by sdkgen. DO NOT EDIT.

//! Generated wire conversions for cache.proto.

use crate::cache::{
    CacheDeleteManyRequest, CacheDeleteManyResponse, CacheDeleteRequest, CacheDeleteResponse,
    CacheGetManyRequest, CacheGetManyResponse, CacheGetRequest, CacheGetResponse, CacheResult,
    CacheSetEntry, CacheSetManyRequest, CacheSetRequest, CacheTouchRequest, CacheTouchResponse,
};
use crate::codec::support::to_wire_duration;
use crate::generated::v1;

/// Converts a native `CacheDeleteManyRequest` to its wire message.
pub(crate) fn to_wire_cache_delete_many_request(
    value: CacheDeleteManyRequest,
) -> v1::CacheDeleteManyRequest {
    v1::CacheDeleteManyRequest { keys: value.keys }
}

/// Converts a wire `CacheDeleteManyResponse` to its native message.
pub(crate) fn from_wire_cache_delete_many_response(
    value: v1::CacheDeleteManyResponse,
) -> CacheDeleteManyResponse {
    CacheDeleteManyResponse {
        deleted: value.deleted,
    }
}

/// Converts a native `CacheDeleteRequest` to its wire message.
pub(crate) fn to_wire_cache_delete_request(value: CacheDeleteRequest) -> v1::CacheDeleteRequest {
    v1::CacheDeleteRequest { key: value.key }
}

/// Converts a wire `CacheDeleteResponse` to its native message.
pub(crate) fn from_wire_cache_delete_response(
    value: v1::CacheDeleteResponse,
) -> CacheDeleteResponse {
    CacheDeleteResponse {
        deleted: value.deleted,
    }
}

/// Converts a native `CacheGetManyRequest` to its wire message.
pub(crate) fn to_wire_cache_get_many_request(
    value: CacheGetManyRequest,
) -> v1::CacheGetManyRequest {
    v1::CacheGetManyRequest { keys: value.keys }
}

/// Converts a wire `CacheGetManyResponse` to its native message.
pub(crate) fn from_wire_cache_get_many_response(
    value: v1::CacheGetManyResponse,
) -> CacheGetManyResponse {
    CacheGetManyResponse {
        entries: value
            .entries
            .into_iter()
            .map(from_wire_cache_result)
            .collect(),
    }
}

/// Converts a native `CacheGetRequest` to its wire message.
pub(crate) fn to_wire_cache_get_request(value: CacheGetRequest) -> v1::CacheGetRequest {
    v1::CacheGetRequest { key: value.key }
}

/// Converts a wire `CacheGetResponse` to its native message.
pub(crate) fn from_wire_cache_get_response(value: v1::CacheGetResponse) -> CacheGetResponse {
    CacheGetResponse {
        found: value.found,
        value: value.value,
    }
}

/// Converts a wire `CacheResult` to its native message.
pub(crate) fn from_wire_cache_result(value: v1::CacheResult) -> CacheResult {
    CacheResult {
        key: value.key,
        found: value.found,
        value: value.value,
    }
}

/// Converts a native `CacheSetEntry` to its wire message.
pub(crate) fn to_wire_cache_set_entry(value: CacheSetEntry) -> v1::CacheSetEntry {
    v1::CacheSetEntry {
        key: value.key,
        value: value.value,
    }
}

/// Converts a native `CacheSetManyRequest` to its wire message.
pub(crate) fn to_wire_cache_set_many_request(
    value: CacheSetManyRequest,
) -> v1::CacheSetManyRequest {
    v1::CacheSetManyRequest {
        entries: value
            .entries
            .into_iter()
            .map(to_wire_cache_set_entry)
            .collect(),
        ttl: value.ttl.map(to_wire_duration),
    }
}

/// Converts a native `CacheSetRequest` to its wire message.
pub(crate) fn to_wire_cache_set_request(value: CacheSetRequest) -> v1::CacheSetRequest {
    v1::CacheSetRequest {
        key: value.key,
        value: value.value,
        ttl: value.ttl.map(to_wire_duration),
    }
}

/// Converts a native `CacheTouchRequest` to its wire message.
pub(crate) fn to_wire_cache_touch_request(value: CacheTouchRequest) -> v1::CacheTouchRequest {
    v1::CacheTouchRequest {
        key: value.key,
        ttl: value.ttl.map(to_wire_duration),
    }
}

/// Converts a wire `CacheTouchResponse` to its native message.
pub(crate) fn from_wire_cache_touch_response(value: v1::CacheTouchResponse) -> CacheTouchResponse {
    CacheTouchResponse {
        touched: value.touched,
    }
}