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;
pub(crate) fn to_wire_cache_delete_many_request(
value: CacheDeleteManyRequest,
) -> v1::CacheDeleteManyRequest {
v1::CacheDeleteManyRequest { keys: value.keys }
}
pub(crate) fn from_wire_cache_delete_many_response(
value: v1::CacheDeleteManyResponse,
) -> CacheDeleteManyResponse {
CacheDeleteManyResponse {
deleted: value.deleted,
}
}
pub(crate) fn to_wire_cache_delete_request(value: CacheDeleteRequest) -> v1::CacheDeleteRequest {
v1::CacheDeleteRequest { key: value.key }
}
pub(crate) fn from_wire_cache_delete_response(
value: v1::CacheDeleteResponse,
) -> CacheDeleteResponse {
CacheDeleteResponse {
deleted: value.deleted,
}
}
pub(crate) fn to_wire_cache_get_many_request(
value: CacheGetManyRequest,
) -> v1::CacheGetManyRequest {
v1::CacheGetManyRequest { keys: value.keys }
}
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(),
}
}
pub(crate) fn to_wire_cache_get_request(value: CacheGetRequest) -> v1::CacheGetRequest {
v1::CacheGetRequest { key: value.key }
}
pub(crate) fn from_wire_cache_get_response(value: v1::CacheGetResponse) -> CacheGetResponse {
CacheGetResponse {
found: value.found,
value: value.value,
}
}
pub(crate) fn from_wire_cache_result(value: v1::CacheResult) -> CacheResult {
CacheResult {
key: value.key,
found: value.found,
value: value.value,
}
}
pub(crate) fn to_wire_cache_set_entry(value: CacheSetEntry) -> v1::CacheSetEntry {
v1::CacheSetEntry {
key: value.key,
value: value.value,
}
}
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),
}
}
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),
}
}
pub(crate) fn to_wire_cache_touch_request(value: CacheTouchRequest) -> v1::CacheTouchRequest {
v1::CacheTouchRequest {
key: value.key,
ttl: value.ttl.map(to_wire_duration),
}
}
pub(crate) fn from_wire_cache_touch_response(value: v1::CacheTouchResponse) -> CacheTouchResponse {
CacheTouchResponse {
touched: value.touched,
}
}