Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
amigin committed Dec 24, 2024
1 parent b1a18fd commit 938b36c
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 39 deletions.
34 changes: 7 additions & 27 deletions src/data_readers/http_connection/into_http_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,12 @@ fn write_init_table_result(table_name: &str, content: JsonArrayWriter) -> Vec<u8
let mut header_json = JsonObjectWriter::new();
header_json.write("tableName", table_name);

let header = unsafe {
format!(
"initTable:{}",
std::str::from_utf8_unchecked(header_json.build().as_slice())
)
};
let header = format!("initTable:{}", header_json.build());

write_pascal_string(header.as_str(), &mut result);

let content = content.build();
write_byte_array(content.as_slice(), &mut result);
write_byte_array(content.as_bytes(), &mut result);
result
}

Expand All @@ -53,17 +48,12 @@ fn write_init_partitions_result(sync_data: &InitPartitionsSyncEventData) -> Vec<
let mut header_json = JsonObjectWriter::new();
header_json.write("tableName", sync_data.table_data.table_name.as_str());

let header = unsafe {
format!(
"initPartitions:{}",
std::str::from_utf8_unchecked(header_json.build().as_slice())
)
};
let header = format!("initPartitions:{}", header_json.build());

write_pascal_string(header.as_str(), &mut result);

let content = sync_data.as_json().build();
write_byte_array(content.as_slice(), &mut result);
write_byte_array(content.as_bytes(), &mut result);
result
}

Expand All @@ -72,17 +62,12 @@ pub fn compile_update_rows_result(sync_data: &UpdateRowsSyncData) -> Vec<u8> {
let mut header_json = JsonObjectWriter::new();
header_json.write("tableName", sync_data.table_data.table_name.as_str());

let header = unsafe {
format!(
"updateRows:{}",
std::str::from_utf8_unchecked(header_json.build().as_slice())
)
};
let header = format!("updateRows:{}", header_json.build());

write_pascal_string(header.as_str(), &mut result);

let content = sync_data.rows_by_partition.as_json_array().build();
write_byte_array(content.as_slice(), &mut result);
write_byte_array(content.as_bytes(), &mut result);
result
}

Expand All @@ -92,12 +77,7 @@ pub fn compile_delete_rows_result(sync_data: &DeleteRowsEventSyncData) -> Vec<u8

header_json.write("tableName", sync_data.table_data.table_name.as_str());

let header = unsafe {
format!(
"deleteRows:{}",
std::str::from_utf8_unchecked(header_json.build().as_slice())
)
};
let header = format!("deleteRows:{}", header_json.build());

write_pascal_string(header.as_str(), &mut result);

Expand Down
7 changes: 4 additions & 3 deletions src/data_readers/tcp_connection/tcp_payload_to_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub async fn serialize(sync_event: &SyncEvent, compress: bool) -> Vec<MyNoSqlTcp

let tcp_contract = MyNoSqlTcpContract::InitTable {
table_name: sync_data.db_table.name.to_string(),
data,
data: data.into_bytes(),
};

if compress {
Expand All @@ -27,7 +27,7 @@ pub async fn serialize(sync_event: &SyncEvent, compress: bool) -> Vec<MyNoSqlTcp

let tcp_contract = MyNoSqlTcpContract::InitTable {
table_name: sync_data.table_data.table_name.to_string(),
data,
data: data.into_bytes(),
};

if compress {
Expand All @@ -47,6 +47,7 @@ pub async fn serialize(sync_event: &SyncEvent, compress: bool) -> Vec<MyNoSqlTcp
.db_rows_snapshot
.as_json_array()
.build()
.into_bytes()
} else {
EMPTY_ARRAY.to_vec()
},
Expand All @@ -64,7 +65,7 @@ pub async fn serialize(sync_event: &SyncEvent, compress: bool) -> Vec<MyNoSqlTcp
SyncEvent::UpdateRows(data) => {
let tcp_contract = MyNoSqlTcpContract::UpdateRows {
table_name: data.table_data.table_name.to_string(),
data: data.rows_by_partition.as_json_array().build(),
data: data.rows_by_partition.as_json_array().build().into_bytes(),
};

if compress {
Expand Down
4 changes: 3 additions & 1 deletion src/db_operations/read/get_highest_row_and_below.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ pub async fn get_highest_row_and_below(
count += 1;
}

return Ok(ReadOperationResult::RowsArray(json_array_writer.build()));
return Ok(ReadOperationResult::RowsArray(
json_array_writer.build().into_bytes(),
));
/*
let mut json_array_writer = JsonArrayWriter::new();
Expand Down
2 changes: 1 addition & 1 deletion src/db_operations/read/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ pub async fn get_next(
) -> Option<ReadOperationResult> {
let db_rows = app.multipart_list.get(multipart_id, amount).await?;

ReadOperationResult::RowsArray(db_rows.as_json_array().build()).into()
ReadOperationResult::RowsArray(db_rows.as_json_array().build().into_bytes()).into()
}
4 changes: 3 additions & 1 deletion src/db_operations/read/rows/get_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ pub async fn get_all(
json_array_writer.write(db_row.as_ref());
}

return Ok(ReadOperationResult::RowsArray(json_array_writer.build()));
return Ok(ReadOperationResult::RowsArray(
json_array_writer.build().into_bytes(),
));
}

/*
Expand Down
4 changes: 3 additions & 1 deletion src/db_operations/read/rows/get_all_by_partition_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ pub async fn get_all_by_partition_key(
},
);

return Ok(ReadOperationResult::RowsArray(json_array_writer.build()));
return Ok(ReadOperationResult::RowsArray(
json_array_writer.build().into_bytes(),
));
}
4 changes: 3 additions & 1 deletion src/db_operations/read/rows/get_all_by_row_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ pub async fn get_all_by_row_key(
json_array_writer.write(db_row.as_ref());
}

return Ok(ReadOperationResult::RowsArray(json_array_writer.build()));
return Ok(ReadOperationResult::RowsArray(
json_array_writer.build().into_bytes(),
));
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ pub async fn get_single_partition_multiple_rows(
json_array_writer.write(db_row.as_ref());
}
}
return Ok(ReadOperationResult::RowsArray(json_array_writer.build()));
return Ok(ReadOperationResult::RowsArray(
json_array_writer.build().into_bytes(),
));
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/db_sync/states/delete_rows_event_sync_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ impl DeleteRowsEventSyncData {
}
}

json_object_writer.build()
json_object_writer.build().into_bytes()
}
}
2 changes: 1 addition & 1 deletion src/settings_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl SettingsModel {
my_no_sql_sdk::core::rust_extensions::file_utils::format_path(self.backup_folder.as_str())
}

pub fn get_init_from_other_server_url<'s>(&'s self) -> Option<&str> {
pub fn get_init_from_other_server_url(&self) -> Option<&str> {
if let Some(url) = &self.init_from_other_server_url {
return Some(url.as_str());
}
Expand Down
2 changes: 1 addition & 1 deletion src/zip/db_zip_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl DbZipBuilder {

let payload = json.build();

write_to_zip_file(&mut self.zip_writer, &payload)?;
write_to_zip_file(&mut self.zip_writer, payload.as_bytes())?;
}

Ok(())
Expand Down

0 comments on commit 938b36c

Please sign in to comment.