Add VFS parameter to mjpDecoder decoding function.

PiperOrigin-RevId: 846242734
Change-Id: I317e11e6fcd965f66416abcf690a3a65d043e9ee
This commit is contained in:
Sam Haves
2025-12-18 06:37:36 -08:00
committed by Copybara-Service
parent bebdd62943
commit 05e1c452c7
5 changed files with 11 additions and 10 deletions
+1 -1
View File
@@ -69,7 +69,7 @@ typedef struct mjpResourceProvider mjpResourceProvider;
// function pointer types
// return an mjSpec representing the decoded resource.
typedef mjSpec* (*mjfDecode)(mjResource* resource);
typedef mjSpec* (*mjfDecode)(mjResource* resource, const mjVFS* vfs);
// return true if the given resource can be decoded.
typedef int (*mjfCanDecode)(const mjResource* resource);
+1 -1
View File
@@ -107,7 +107,7 @@ mjSpec* mj_parse(const char* filename, const char* content_type,
memcpy(resource->name, fullname.c_str(), sizeof(char) * (n + 1));
}
mjSpec* spec = mju_decodeResource(resource, content_type);
mjSpec* spec = mju_decodeResource(resource, content_type, vfs);
mju_closeResource(resource);
return spec;
}
+2 -2
View File
@@ -265,7 +265,7 @@ int mju_isModifiedResource(const mjResource* resource, const char* timestamp) {
return FileModified(resource, timestamp);
}
mjSpec* mju_decodeResource(mjResource* resource, const char* content_type) {
mjSpec* mju_decodeResource(mjResource* resource, const char* content_type, const mjVFS* vfs) {
const mjpDecoder* decoder = nullptr;
if (content_type) {
decoder = mjp_findDecoder(resource, content_type);
@@ -276,6 +276,6 @@ mjSpec* mju_decodeResource(mjResource* resource, const char* content_type) {
mju_error("Could not find decoder for resource '%s'", resource->name);
}
return decoder->decode(resource);
return decoder->decode(resource, vfs);
}
+2 -1
View File
@@ -48,7 +48,8 @@ MJAPI int mju_isModifiedResource(const mjResource* resource, const char* timesta
// given a resource, find its decoder and return the decoded spec
// the caller takes ownership of the spec and is responsible for cleaning it up
MJAPI mjSpec* mju_decodeResource(mjResource* resource, const char* content_type);
MJAPI mjSpec* mju_decodeResource(mjResource* resource, const char* content_type,
const mjVFS* vfs);
#ifdef __cplusplus
}
+5 -5
View File
@@ -39,7 +39,9 @@ static mjSpec* MakeSimpleSpec() {
}
// Always returns a simple mjSpec, ignoring the resource.
mjSpec* FakeDecode(mjResource* resource) { return MakeSimpleSpec(); }
mjSpec* FakeDecode(mjResource* resource, const mjVFS* vfs) {
return MakeSimpleSpec();
}
// Can decode any resource that has a .fakeformat extension.
int FakeCanDecode(const mjResource* resource) {
@@ -81,8 +83,7 @@ TEST_F(DecoderPluginTest, CanDecode) {
// Check referencing a resource via XML invokes the decoder.
char error[1024];
mjSpec* spec =
mj_parseXMLString(xml, nullptr, error, sizeof(error));
mjSpec* spec = mj_parseXMLString(xml, nullptr, error, sizeof(error));
mjModel* model = mj_compile(spec, nullptr);
ASSERT_THAT(model, testing::NotNull()) << error;
EXPECT_EQ(model->nbody, 2); // world + included body
@@ -91,8 +92,7 @@ TEST_F(DecoderPluginTest, CanDecode) {
mj_deleteSpec(spec);
// Check mj_parse with extension .fakeformat
spec =
mj_parse("dummy.fakeformat", nullptr, nullptr, error, sizeof(error));
spec = mj_parse("dummy.fakeformat", nullptr, nullptr, error, sizeof(error));
model = mj_compile(spec, nullptr);
EXPECT_EQ(model->nbody, 2); // world + included body
EXPECT_EQ(model->ngeom, 1);