Skip to content

Commit

Permalink
fix hex
Browse files Browse the repository at this point in the history
  • Loading branch information
shikhar committed Dec 6, 2024
1 parent b21d91c commit e77dc4d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
11 changes: 9 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ license = "Apache-2.0"

[dependencies]
async-stream = "0.3.6"
base16ct = { version = "0.2.0", features = ["alloc"] }
clap = { version = "4.5.20", features = ["derive"] }
color-print = "0.3.6"
colored = "2.1.0"
Expand Down
17 changes: 12 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use stream::{RecordStream, StreamService};
use streamstore::{
client::{BasinClient, Client, ClientConfig, S2Endpoints, StreamClient},
types::{
BasinInfo, BasinName, CommandRecord, FencingToken, MeteredBytes as _, ReadOutput,
StreamInfo,
BasinInfo, BasinName, CommandRecord, ConvertError, FencingToken, MeteredBytes as _,
ReadOutput, StreamInfo,
},
HeaderValue,
};
Expand Down Expand Up @@ -200,7 +200,7 @@ enum Commands {
trim_point: u64,

/// Enforce fencing token specified in hex.
#[arg(short = 'f', long)]
#[arg(short = 'f', long, value_parser = parse_fencing_token)]
fencing_token: Option<FencingToken>,

/// Enforce that the sequence number issued to the first record matches.
Expand All @@ -224,10 +224,11 @@ enum Commands {

/// New fencing token specified in hex.
/// It may be upto 16 bytes, and can be empty.
#[arg(value_parser = parse_fencing_token)]
new_fencing_token: FencingToken,

/// Enforce existing fencing token, specified in hex.
#[arg(short = 'f', long)]
#[arg(short = 'f', long, value_parser = parse_fencing_token)]
fencing_token: Option<FencingToken>,

/// Enforce that the sequence number issued to this command matches.
Expand All @@ -246,7 +247,7 @@ enum Commands {
stream: String,

/// Enforce fencing token specified in hex.
#[arg(short = 'f', long)]
#[arg(short = 'f', long, value_parser = parse_fencing_token)]
fencing_token: Option<FencingToken>,

/// Enforce that the sequence number issued to the first record matches.
Expand Down Expand Up @@ -358,6 +359,12 @@ fn parse_records_output_source(s: &str) -> Result<RecordsOut, std::io::Error> {
}
}

fn parse_fencing_token(s: &str) -> Result<FencingToken, ConvertError> {
base16ct::mixed::decode_vec(s)
.map_err(|_| "invalid hex")?
.try_into()
}

fn client_config(auth_token: String) -> Result<ClientConfig, S2CliError> {
let endpoints = S2Endpoints::from_env().map_err(S2CliError::EndpointsFromEnv)?;
let client_config = ClientConfig::new(auth_token.to_string())
Expand Down

0 comments on commit e77dc4d

Please sign in to comment.