vfx-rs / ptex-bind

High-level cxx-based bindings for Ptex https://github.com/wdas/ptex https://crates.io/crates/ptex https://crates.io/crates/ptex-sys
https://crates.io/crates/ptex
Apache License 2.0
5 stars 2 forks source link

PtexMetaData reading/writing #10

Closed ratmice closed 6 months ago

ratmice commented 7 months ago

Before jumping in to trying to write a patch for writing of metadata, I wanted to make an issue for discussing the api design surrounding it. Because the metadata functions are all overloaded, it seems there are a few paths that could be taken.

from just having a bunch of functions

fn write_meta_string(writer, s: String);
fn write_meta_i8_slice(writer, i: &[i8]);

Alternately we could consider including a type and avoid overloading the write function, then marshall everything through a write_meta function which behaves like the version of writeMeta that takes a PtexMetaData.

#[derive(Clone)]
enum MetaDataValue<'a> {
   StringValue(String),
   I8Slice(&'a [i8])
   ...
}
fn write_meta<'a>(writer, val: MetaDataValue<'a>);

I haven't thought about it too terribly much, but those seemed to be the major forks in the path regarding how we could go forward.

davvid commented 7 months ago

This has analogs to what had to be done in the writer API to unify the older write_face_u32 / write_face_f32 and write_face_u8 functions into a single interface when f16 support was added.

849375fab058d1584ece82856fe1a5f791c74ae2 handled it by introducing a trait. That commit eliminated the various type-specific functions and then that trait was leveraged in 7b7861be62cbc96e7157f3682ade638962512a50 when adding f16 support.

That approach might work here too.