pub struct ClientOrderIdEncoder { /* private fields */ }Expand description
Manages bidirectional mapping of ClientOrderId ↔ (client_id, client_metadata) for dYdX.
§Encoding Strategy
- Numeric IDs (e.g., “12345”): Encoded as
(12345, 4)for backward compatibility - O-format IDs (e.g., “O-20260131-174827-001-001-1”): Deterministically encoded
- Other formats: Sequential allocation with in-memory mapping
§Thread Safety
All operations are thread-safe using DashMap and AtomicU32.
Implementations§
Source§impl ClientOrderIdEncoder
impl ClientOrderIdEncoder
Sourcepub fn encode(
&self,
id: ClientOrderId,
) -> Result<EncodedClientOrderId, EncoderError>
pub fn encode( &self, id: ClientOrderId, ) -> Result<EncodedClientOrderId, EncoderError>
Encodes a ClientOrderId to (client_id, client_metadata) pair.
§Encoding Rules
- If already mapped in cache, returns existing encoded pair
- If numeric (e.g., “12345”), returns
(12345, DEFAULT_RUST_CLIENT_METADATA) - If O-format, deterministically encodes timestamp + identity bits
- Otherwise, allocates sequential ID for fallback
§Errors
Returns EncoderError::CounterOverflow if sequential counter exceeds safe limit.
Returns EncoderError::ValueOverflow if O-format values exceed bit limits.
Sourcepub fn decode(
&self,
client_id: u32,
client_metadata: u32,
) -> Option<ClientOrderId>
pub fn decode( &self, client_id: u32, client_metadata: u32, ) -> Option<ClientOrderId>
Decodes (client_id, client_metadata) back to the original ClientOrderId.
§Decoding Rules
- If
client_metadata == DEFAULT_RUST_CLIENT_METADATA (4): Return numeric string - If
client_metadata == SEQUENTIAL_METADATA_MARKER: Look up in sequential reverse mapping - Otherwise: Decode as O-format using timestamp + identity bits
Returns None if decoding fails (e.g., sequential ID not in cache).
Sourcepub fn get(&self, id: &ClientOrderId) -> Option<EncodedClientOrderId>
pub fn get(&self, id: &ClientOrderId) -> Option<EncodedClientOrderId>
Gets the existing encoded pair without allocating a new one.
First checks the forward mapping (for updated/modified orders), then falls back to deterministic computation for O-format and numeric IDs.
Sourcepub fn remove(
&self,
client_id: u32,
client_metadata: u32,
) -> Option<ClientOrderId>
pub fn remove( &self, client_id: u32, client_metadata: u32, ) -> Option<ClientOrderId>
Removes the mapping for a given encoded pair.
Returns the original ClientOrderId if it was mapped. For deterministic formats, this is a no-op.
Sourcepub fn remove_by_client_id(&self, client_id: u32) -> Option<ClientOrderId>
pub fn remove_by_client_id(&self, client_id: u32) -> Option<ClientOrderId>
Legacy remove method for backward compatibility. Removes by client_id only, assumes DEFAULT_RUST_CLIENT_METADATA.
Sourcepub fn current_counter(&self) -> u32
pub fn current_counter(&self) -> u32
Returns the current counter value (for debugging/monitoring).
Trait Implementations§
Source§impl Debug for ClientOrderIdEncoder
impl Debug for ClientOrderIdEncoder
Auto Trait Implementations§
impl !Freeze for ClientOrderIdEncoder
impl !RefUnwindSafe for ClientOrderIdEncoder
impl Send for ClientOrderIdEncoder
impl Sync for ClientOrderIdEncoder
impl Unpin for ClientOrderIdEncoder
impl UnsafeUnpin for ClientOrderIdEncoder
impl UnwindSafe for ClientOrderIdEncoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].