From 30ed0180ceba1573143430e859401060b3738bf5 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 29 Jun 2024 12:36:54 -0400 Subject: [PATCH] Implement write_string, add get_string_len helper function --- src/common_file_operations.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/common_file_operations.rs b/src/common_file_operations.rs index b5417fc..2295426 100644 --- a/src/common_file_operations.rs +++ b/src/common_file_operations.rs @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: 2024 Joshua Goins // SPDX-License-Identifier: GPL-3.0-or-later +use std::ffi::CString; use binrw::{binread, BinReaderExt, BinResult}; use half::f16; use std::io::SeekFrom; @@ -22,7 +23,13 @@ pub(crate) fn read_string(byte_stream: Vec) -> String { } pub(crate) fn write_string(str: &String) -> Vec { - vec![] + let c_string = CString::new(&**str).unwrap(); + c_string.as_bytes().to_vec() +} + +pub(crate) fn get_string_len(str: &String) -> usize { + let c_string = CString::new(&**str).unwrap(); + c_string.count_bytes() } #[binrw::parser(reader)]