ruoruoniao commented on issue #3746:
URL: https://github.com/apache/fory/issues/3746#issuecomment-4677643137
> If the int32 field is fixed int32, it will go to
write_fixed_primitive_fields, otherwise, it wont' go to this function, the
field value will still be writtten as varint32
No... If it works itself, all is OK, but if in `xlang`...
```cpp
//
// Created by MikuSoft on 2026/6/11.
//
#include <fory/serialization/fory.h>
#include <fory/serialization/serializer.h>
#include <fstream>
struct X {
uint32_t a = 0;
uint32_t b = 0;
uint32_t c = 0;
std::vector<uint32_t> d{};
};
FORY_STRUCT(X, a, b, c, d);
int main(const int argc, char **argv) {
fory::serialization::Fory fory =
fory::serialization::ForyBuilder().xlang(true).track_ref(true).build();
fory.register_struct<X>("X");
const auto x = fory.serialize(X{66051, 66051, 66051, {66051, 66051,
66051}});
if (!x.ok()) {
return -1;
}
std::ofstream file("cxx.bin", std::ios::binary);
file.write(reinterpret_cast<const char *>(x.value().data()),
static_cast<uint32_t>(x.value().size()));
file.close();
return 0;
}
```
```python
import pyfory
from pyfory.annotation import *
from dataclasses import dataclass, field
from typing import List
@dataclass
class X:
a: UInt32 = 0
b: UInt32 = 0
c: UInt32 = 0
d: List[UInt32] = field(default_factory=list)
"""
This will cause the same error.
@dataclass
class X:
a: FixedUInt32 = 0
b: FixedUInt32 = 0
c: FixedUInt32 = 0
d: List[FixedUInt32] = field(default_factory=list)
"""
fory = pyfory.Fory(xlang=True, ref=True, strict=True)
fory.register_type(X, typename="X")
with open("cxx.bin", "rb") as f:
data = fory.deserialize(f.read())
print(data)
with open("py.bin", "wb") as f:
f.write(fory.serialize(data))
```
Python will print `X(a=3, b=2, c=1, d=[])`. As you know, `66051` is `0x01
0x02 0x03`. Vector cannot be serialized correct. Also, it cannot convert into
c++ by content in `py.bin`.
You can try yourself.
<img width="460" height="227" alt="Image"
src="https://github.com/user-attachments/assets/77f01c37-8b6a-464a-815d-4918b1a52f55"
/>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]