Skip to content

Commit

Permalink
[update] naming and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
amerelo authored and frsechet committed Mar 18, 2021
1 parent b393f6d commit e4a0e23
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
22 changes: 18 additions & 4 deletions csml_engine/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,15 @@ pub struct SerializeCsmlBot {
pub env: Option<String>,
}

/**
* Before CSML v1.5, the Bot struct was encoded with bincode. This does not
* allow to easily change the contents of a bot, and would not allow to add
* the bot env feature.
* We need to keep this for backwards compatibility until CSML v2.
* TO BE REMOVED in CSML v2
*/
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TMPSerializeCsmlBot {
pub struct CsmlBotBincode {
pub id: String,
pub name: String,
pub flows: Vec<CsmlFlow>,
Expand All @@ -114,7 +121,7 @@ pub struct TMPSerializeCsmlBot {
pub default_flow: String,
}

impl TMPSerializeCsmlBot {
impl CsmlBotBincode {
pub fn to_bot(self) -> SerializeCsmlBot {
SerializeCsmlBot {
id: self.id,
Expand Down Expand Up @@ -197,15 +204,22 @@ pub struct DynamoBot {
pub env: Option<String>
}

/**
* Before CSML v1.5, the Bot struct was encoded with bincode. This does not
* allow to easily change the contents of a bot, and would not allow to add
* the bot env feature.
* We need to keep this for backwards compatibility until CSML v2.
* TO BE REMOVED in CSML v2
*/
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TMPDynamoBot {
pub struct DynamoBotBincode {
pub id: String,
pub name: String,
pub custom_components: Option<String>,
pub default_flow: String,
}

impl TMPDynamoBot {
impl DynamoBotBincode {
pub fn to_bot(self) -> DynamoBot {
DynamoBot {
id: self.id,
Expand Down
8 changes: 4 additions & 4 deletions csml_engine/src/db_connectors/dynamodb/bot.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::data::{DynamoDbClient, DynamoBot, TMPDynamoBot};
use crate::data::{DynamoDbClient, DynamoBot, DynamoBotBincode};
use crate::db_connectors::{
dynamodb::{aws_s3, Bot, DynamoDbKey},
BotVersion,
Expand Down Expand Up @@ -140,7 +140,7 @@ pub fn get_bot_versions(

let csml_bot: DynamoBot = match base64::decode(&data.bot) {
Ok(base64decoded) => {
match bincode::deserialize::<TMPDynamoBot>(&base64decoded[..]) {
match bincode::deserialize::<DynamoBotBincode>(&base64decoded[..]) {
Ok(bot) => bot.to_bot(),
Err(_) => serde_json::from_str(&data.bot).unwrap()
}
Expand Down Expand Up @@ -199,7 +199,7 @@ pub fn get_bot_by_version_id(

let csml_bot: DynamoBot = match base64::decode(&bot.bot) {
Ok(base64decoded) => {
match bincode::deserialize::<TMPDynamoBot>(&base64decoded[..]) {
match bincode::deserialize::<DynamoBotBincode>(&base64decoded[..]) {
Ok(bot) => bot.to_bot(),
Err(_) => serde_json::from_str(&bot.bot).unwrap()
}
Expand Down Expand Up @@ -281,7 +281,7 @@ pub fn get_last_bot_version(
let bot: Bot = serde_dynamodb::from_hashmap(item)?;
let csml_bot: DynamoBot = match base64::decode(&bot.bot) {
Ok(base64decoded) => {
match bincode::deserialize::<TMPDynamoBot>(&base64decoded[..]) {
match bincode::deserialize::<DynamoBotBincode>(&base64decoded[..]) {
Ok(bot) => bot.to_bot(),
Err(_) => serde_json::from_str(&bot.bot).unwrap()
}
Expand Down
8 changes: 4 additions & 4 deletions csml_engine/src/db_connectors/mongodb/bot.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
db_connectors::{BotVersion, DbBot},
data::{SerializeCsmlBot, TMPSerializeCsmlBot},
data::{SerializeCsmlBot, CsmlBotBincode},
EngineError,
};
use bson::{doc, Bson};
Expand Down Expand Up @@ -91,7 +91,7 @@ pub fn get_bot_versions(

let csml_bot: SerializeCsmlBot = match base64::decode(&bot_version.bot) {
Ok(base64decoded) => {
match bincode::deserialize::<TMPSerializeCsmlBot>(&base64decoded[..]) {
match bincode::deserialize::<CsmlBotBincode>(&base64decoded[..]) {
Ok(bot) => bot.to_bot(),
Err(_) => serde_json::from_str(&bot_version.bot).unwrap()
}
Expand Down Expand Up @@ -156,7 +156,7 @@ pub fn get_bot_by_version_id(

let csml_bot: SerializeCsmlBot = match base64::decode(&bot.bot) {
Ok(base64decoded) => {
match bincode::deserialize::<TMPSerializeCsmlBot>(&base64decoded[..]) {
match bincode::deserialize::<CsmlBotBincode>(&base64decoded[..]) {
Ok(bot) => bot.to_bot(),
Err(_) => serde_json::from_str(&bot.bot).unwrap()
}
Expand Down Expand Up @@ -196,7 +196,7 @@ pub fn get_last_bot_version(

let csml_bot: SerializeCsmlBot = match base64::decode(&bot.bot) {
Ok(base64decoded) => {
match bincode::deserialize::<TMPSerializeCsmlBot>(&base64decoded[..]) {
match bincode::deserialize::<CsmlBotBincode>(&base64decoded[..]) {
Ok(bot) => bot.to_bot(),
Err(_) => serde_json::from_str(&bot.bot).unwrap()
}
Expand Down

0 comments on commit e4a0e23

Please sign in to comment.