Change mj_encode return type to 64-bit (mjtSize)

This supports encoding files larger than 2GB.

PiperOrigin-RevId: 939828697
Change-Id: If60d36c61475ced20b4eb58408ffb37e25bf3db7
This commit is contained in:
Sam Haves
2026-06-29 07:41:23 -07:00
committed by Copybara-Service
parent 1e04c568e8
commit d83ef0b6b9
11 changed files with 32 additions and 27 deletions
+6 -6
View File
@@ -146,9 +146,9 @@ mjSpec* mj_parse(const char* filename, const char* content_type,
}
// encode spec/model to file
int mj_encode(const mjSpec* s, const mjModel* m, const char* filename,
const char* content_type, const mjVFS* vfs, char* error,
int error_sz) {
mjtSize mj_encode(const mjSpec* s, const mjModel* m, const char* filename,
const char* content_type, const mjVFS* vfs, char* error,
int error_sz) {
// TODO(shaves) Move MJCF and URDF to encoders/decoders.
auto filepath = mujoco::user::FilePath(filename);
if (filepath.Ext() == ".xml" ||
@@ -158,7 +158,7 @@ int mj_encode(const mjSpec* s, const mjModel* m, const char* filename,
return -1;
}
return std::filesystem::file_size(filename);
return static_cast<mjtSize>(std::filesystem::file_size(filename));
}
const mjpEncoder* encoder = mjp_findEncoder(filename, content_type);
@@ -174,7 +174,7 @@ int mj_encode(const mjSpec* s, const mjModel* m, const char* filename,
memset(&resource, 0, sizeof(resource));
resource.name = const_cast<char*>(filename);
const int nbytes = encoder->encode(s, m, vfs, &resource);
const mjtSize nbytes = encoder->encode(s, m, vfs, &resource);
if (nbytes < 0 || !resource.data) {
if (error) {
strncpy(error, "encoder failed", error_sz);
@@ -197,7 +197,7 @@ int mj_encode(const mjSpec* s, const mjModel* m, const char* filename,
fclose(fp);
encoder->close_resource(&resource);
if (static_cast<int>(written) != nbytes) {
if (static_cast<mjtSize>(written) != nbytes) {
if (error) {
strncpy(error, "failed to write all bytes to file", error_sz);
error[error_sz - 1] = '\0';
+3 -3
View File
@@ -306,8 +306,8 @@ std::unordered_map<std::string, AssetEntry> CollectAssets(
return archive_entries;
}
int MjzEncode(const mjSpec* spec, const mjModel* model, const mjVFS* vfs,
mjResource* resource) {
mjtSize MjzEncode(const mjSpec* spec, const mjModel* model, const mjVFS* vfs,
mjResource* resource) {
if (!spec || !resource) {
return -1;
}
@@ -399,7 +399,7 @@ int MjzEncode(const mjSpec* spec, const mjModel* model, const mjVFS* vfs,
resource->data = archive_buf;
return static_cast<int>(archive_size);
return static_cast<mjtSize>(archive_size);
}
void MjzCloseResource(mjResource* resource) {