Skip to content

[C++] Type is var but data is fixed when write uint32_t/uint64_t. #3746

@ruoruoniao

Description

@ruoruoniao

Search before asking

  • I had searched in the issues and found no similar issues.

Version

Latest

Component(s)

C++

Minimal reproduce step

When use a normal struct with uint32_t, the type id is 0x0C, but write data as 8 bytes like 0x01 0x00 0x00 0x00.

What did you expect to see?

If use 0x0C, the data should be 0x01.

What did you see instead?

I see a comment at Serializer<uint32_t> and Serializer<uint64_t>:

/// uint32_t serializer - uses VAR_UINT32 to match Rust xlang mode
template <> struct Serializer<uint32_t> {

... codes

/// uint64_t serializer - uses VAR_UINT64 to match Rust xlang mode
template <> struct Serializer<uint64_t> {

... codes

But if using a struct, in struct_serializer.h -> write_struct_fields_impl function, it will walk in branch:

  if constexpr (prim_count == total_count) {
    ...codes
  }

So it will use write_primitive_fields_fast function to write data. It will let uint32_t field in fixed_count, so it will walk into branch:

if constexpr (fixed_count > 0 && fixed_bytes > 0) {
    write_fixed_primitive_fields<T>(obj, buffer,
                                    std::make_index_sequence<fixed_count>{});
  }

So maybe let uint32_t as a varint when use FORY_STRUCT?

Anything Else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions