Skip to content

Commit

Permalink
Exctract proto from socket-layer feature.
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Dec 24, 2024
1 parent fe9f9ed commit a89fbfd
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ utils/TestUtils.js

# java compiled files.
*.class

# generaged files (e.g. protobuf)
generated/
3 changes: 2 additions & 1 deletion glide-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ serde_json = "1"
serde = { version = "1", features = ["derive"] }

[features]
proto = ["protobuf"]
socket-layer = [
"proto",
"directories",
"integer-encoding",
"num_cpus",
"protobuf",
"tokio-util",
]
standalone_heartbeat = []
Expand Down
5 changes: 3 additions & 2 deletions glide-core/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0

#[cfg(feature = "socket-layer")]
#[cfg(feature = "proto")]
fn build_protobuf() {
let customization_options = protobuf_codegen::Customize::default()
.lite_runtime(false)
Expand All @@ -13,10 +13,11 @@ fn build_protobuf() {
.input("src/protobuf/response.proto")
.input("src/protobuf/connection_request.proto")
.customize(customization_options)
.out_dir("src/generated")
.run_from_script();
}

fn main() {
#[cfg(feature = "socket-layer")]
#[cfg(feature = "proto")]
build_protobuf();
}
8 changes: 4 additions & 4 deletions glide-core/src/client/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use logger_core::log_warn;
use std::collections::HashSet;
use std::time::Duration;

#[cfg(feature = "socket-layer")]
#[cfg(feature = "proto")]
use crate::connection_request as protobuf;

#[derive(Default)]
Expand Down Expand Up @@ -73,7 +73,7 @@ pub struct ConnectionRetryStrategy {
pub number_of_retries: u32,
}

#[cfg(feature = "socket-layer")]
#[cfg(feature = "proto")]
fn chars_to_string_option(chars: &::protobuf::Chars) -> Option<String> {
if chars.is_empty() {
None
Expand All @@ -82,7 +82,7 @@ fn chars_to_string_option(chars: &::protobuf::Chars) -> Option<String> {
}
}

#[cfg(feature = "socket-layer")]
#[cfg(feature = "proto")]
fn none_if_zero(value: u32) -> Option<u32> {
if value == 0 {
None
Expand All @@ -91,7 +91,7 @@ fn none_if_zero(value: u32) -> Option<u32> {
}
}

#[cfg(feature = "socket-layer")]
#[cfg(feature = "proto")]
impl From<protobuf::ConnectionRequest> for ConnectionRequest {
fn from(value: protobuf::ConnectionRequest) -> Self {
let read_from = value.read_from.enum_value().ok().map(|val| match val {
Expand Down
4 changes: 2 additions & 2 deletions glide-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0

#[cfg(feature = "socket-layer")]
include!(concat!(env!("OUT_DIR"), "/protobuf/mod.rs"));
#[cfg(feature = "proto")]
include!("generated/mod.rs");
pub mod client;
mod retry_strategies;
#[cfg(feature = "socket-layer")]
Expand Down
4 changes: 2 additions & 2 deletions glide-core/src/request_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use redis::{cmd, Cmd};

#[cfg(feature = "socket-layer")]
#[cfg(feature = "proto")]
use crate::command_request::RequestType as ProtobufRequestType;

#[repr(C)]
Expand Down Expand Up @@ -431,7 +431,7 @@ fn get_two_word_command(first: &str, second: &str) -> Cmd {
cmd
}

#[cfg(feature = "socket-layer")]
#[cfg(feature = "proto")]
impl From<::protobuf::EnumOrUnknown<ProtobufRequestType>> for RequestType {
fn from(value: ::protobuf::EnumOrUnknown<ProtobufRequestType>) -> Self {
match value.enum_value_or(ProtobufRequestType::InvalidRequest) {
Expand Down
2 changes: 1 addition & 1 deletion glide-core/src/retry_strategies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub(crate) fn get_exponential_backoff(
}
}

#[cfg(feature = "socket-layer")]
#[cfg(feature = "proto")]
#[allow(dead_code)]
pub(crate) fn get_fixed_interval_backoff(
fixed_interval: u32,
Expand Down
2 changes: 1 addition & 1 deletion go/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ crate-type = ["cdylib"]

[dependencies]
redis = { path = "../glide-core/redis-rs/redis", features = ["aio", "tokio-comp", "connection-manager", "tokio-rustls-comp"] }
glide-core = { path = "../glide-core", features = ["socket-layer"] }
glide-core = { path = "../glide-core", features = ["proto"] }
tokio = { version = "^1", features = ["rt", "macros", "rt-multi-thread", "time"] }
protobuf = { version = "3.3.0", features = [] }

Expand Down
2 changes: 1 addition & 1 deletion go/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use tokio::runtime::Runtime;
#[derive(Debug)]
pub struct CommandResponse {
response_type: ResponseType,
int_value: c_long,
int_value: i64,
float_value: c_double,
bool_value: bool,

Expand Down

0 comments on commit a89fbfd

Please sign in to comment.