-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
use swbus_actor::prelude::*; | ||
use swss_common::{KeyOpFieldValues, KeyOperation, ProducerStateTable}; | ||
|
||
pub struct ProducerTableBridge { | ||
table: ProducerStateTable, | ||
} | ||
|
||
impl ProducerTableBridge { | ||
pub fn new(table: ProducerStateTable) -> Self { | ||
ProducerTableBridge { table } | ||
} | ||
} | ||
|
||
impl Actor for ProducerTableBridge { | ||
async fn init(&mut self, _outbox: Outbox) {} | ||
|
||
async fn handle_message(&mut self, message: IncomingMessage, outbox: Outbox) { | ||
match &message.body { | ||
MessageBody::Request(DataRequest { payload }) => { | ||
let response = match handle_kfvs(&mut self.table, &payload).await { | ||
Ok(()) => OutgoingMessage::ok_response(message), | ||
Err((code, msg)) => OutgoingMessage::error_response(message, code, msg), | ||
}; | ||
|
||
outbox.send(response).await; | ||
} | ||
MessageBody::Response(_) => { /* ignore responses, we should never get any anyway */ } | ||
} | ||
} | ||
} | ||
|
||
async fn handle_kfvs(table: &mut ProducerStateTable, payload: &[u8]) -> Result<(), (SwbusErrorCode, String)> { | ||
let kfvs = crate::decode_kfvs(payload) | ||
.map_err(|e| (SwbusErrorCode::InvalidPayload, format!("error decoding kfvs: {e}")))?; | ||
|
||
match kfvs.operation { | ||
KeyOperation::Set => { | ||
table.set_async(&kfvs.key, kfvs.field_values).await; | ||
} | ||
KeyOperation::Del => { | ||
table.del_async(&kfvs.key).await; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |