proposal: add vsCast method
via: https://github.com/vivisect/dissect/pull/1
i had used the following function to cast the bytes from one vstruct to another:
def cast_vstruct(src_instance, dst_instance):
'''
load the bytes that back `src_instance` into `dst_instance`.
note that subsequent changes made to `dst_instance` are not reflected in `src_instance`.
so this is useful in 'by-value' situations, but not for situations expecting writeback support.
modifies `dst_instance`. does not modify src_instance.
type src_instance: v_types.VStruct
type dst_instance: v_types.VStruct
'''
d = src_instance.vsEmit()
dst_instance.vsParse(d)
a vsCast method on vstruct might enable the passing of the fd/bytes and offset to the destination object, and therefore:
- be higher performant, since the serialization/deserialization is avoided.
- support writeback on the destination instance (though this may result in sync issues)
Hadn't even thought of having it use a "shared backing". Really dig it. Maybe we also need the equiv of a vsMemCopy(dest), but named something better ( so there's a syntax that does the exact thing that sparked the conversation :) )
For the "shared backing" vsCast syntax, i think of the "cast" operation as applying to the old object so maybe something like
src.vsCast( dst )
or the longer...
dst.vsCastFrom( src )
or naming it something that makes the second use case the implied direction?
dst.vsPointTo()