Skip to content

Commit 264df36

Browse files
authored
Merge pull request #37 from AvivNaaman/32-support-more-file-create-contexts
32 support more file create contexts
2 parents 9571806 + f931eec commit 264df36

File tree

4 files changed

+495
-147
lines changed

4 files changed

+495
-147
lines changed

smb/src/packets/binrw_util/pos_marker.rs

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{fmt::Debug, io::SeekFrom};
55
/**
66
* Source: https://github.com/jam1garner/binrw/discussions/229
77
*/
8-
#[derive(Default)]
8+
#[derive(Default, PartialEq, Eq)]
99
pub struct PosMarker<T> {
1010
pub pos: OnceCell<u64>,
1111
pub value: T,
@@ -96,7 +96,7 @@ where
9696
/// * endian: The endian to write with ([binrw::Endian])
9797
pub fn write_back<V, W>(&self, value: V, writer: &mut W, endian: Endian) -> BinResult<()>
9898
where
99-
V: TryInto<T>,
99+
V: TryInto<T> + std::fmt::Debug,
100100
W: binrw::io::Write + binrw::io::Seek,
101101
{
102102
let return_to = writer.stream_position()?;
@@ -212,6 +212,34 @@ where
212212
)
213213
}
214214

215+
/// Writer for value
216+
/// * fill relative offset to offset location.
217+
/// * fill written size to size location.
218+
#[binrw::writer(writer, endian)]
219+
pub fn write_roff_size_b<U, S, B>(
220+
value: &U,
221+
write_offset_to: &PosMarker<S>,
222+
write_size_to: &Self,
223+
offset_relative_to: &PosMarker<B>,
224+
) -> BinResult<()>
225+
where
226+
U: BinWrite<Args<'static> = ()>,
227+
S: BinWrite<Args<'static> = ()> + TryFrom<u64>,
228+
S::Error: binrw::error::CustomError + 'static,
229+
{
230+
Self::write_hero(
231+
value,
232+
writer,
233+
endian,
234+
(
235+
Some(write_size_to),
236+
Some(write_offset_to),
237+
Some(offset_relative_to),
238+
(),
239+
),
240+
)
241+
}
242+
215243
/// Writer for value,
216244
/// * fill relative offset to offset location relative to base.
217245
/// * fill written size to size location.
@@ -259,6 +287,52 @@ where
259287
)
260288
}
261289

290+
#[binrw::writer(writer, endian)]
291+
pub fn write_roff_size<U, S>(
292+
value: &U,
293+
write_offset_to: &PosMarker<S>,
294+
write_size_to: &Self,
295+
) -> BinResult<()>
296+
where
297+
U: BinWrite<Args<'static> = ()>,
298+
S: BinWrite<Args<'static> = ()> + TryFrom<u64>,
299+
S::Error: binrw::error::CustomError + 'static,
300+
{
301+
let no_base: Option<&PosMarker<T>> = None;
302+
Self::write_hero(
303+
value,
304+
writer,
305+
endian,
306+
(Some(write_size_to), Some(write_offset_to), no_base, ()),
307+
)
308+
}
309+
310+
#[binrw::writer(writer, endian)]
311+
pub fn write_roff_size_a<U, S>(
312+
value: &U,
313+
write_offset_to: &PosMarker<S>,
314+
write_size_to: &Self,
315+
value_args: U::Args<'_>,
316+
) -> BinResult<()>
317+
where
318+
U: BinWrite,
319+
S: BinWrite<Args<'static> = ()> + TryFrom<u64>,
320+
S::Error: binrw::error::CustomError + 'static,
321+
{
322+
let no_base: Option<&PosMarker<T>> = None;
323+
Self::write_hero(
324+
value,
325+
writer,
326+
endian,
327+
(
328+
Some(write_size_to),
329+
Some(write_offset_to),
330+
no_base,
331+
value_args,
332+
),
333+
)
334+
}
335+
262336
/// Writer for value
263337
/// * fill absolute offset to offset location.
264338
/// * fill written size to size location.

0 commit comments

Comments
 (0)