Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

核心功能,to_pb 序列化bug #332

Closed
pimatrix opened this issue Nov 27, 2024 · 2 comments · Fixed by #333
Closed

核心功能,to_pb 序列化bug #332

pimatrix opened this issue Nov 27, 2024 · 2 comments · Fixed by #333

Comments

@pimatrix
Copy link

问题:当struct的第一个字段int32_t test;被注释的情况下,才可以编译通过,否则报错

/usr/bin/gcc -c -m64 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -std=c++20 -DNDEBUG -o build/.objs/hello/linux/x86_64/release/src/main.cpp.o src/main.cpp
error: In file included from /usr/local/include/iguana/pb_reader.hpp:3,
                 from /usr/local/include/ylt/struct_pb/struct_pb_impl.hpp:18,
                 from /usr/local/include/ylt/struct_pb.hpp:17,
                 from src/main.cpp:3:
/usr/local/include/iguana/pb_util.hpp: In instantiation of ‘void iguana::detail::append_varint_u32(Writer&, std::index_sequence<_Idx ...>) [with long unsigned int v = 130; Writer = iguana::memory_writer; long unsigned int ...I = {0}; std::index_sequence<_Idx ...> = std::integer_sequence<long unsigned int, 0>]’:
/usr/local/include/iguana/pb_util.hpp:206:23:   required from ‘void iguana::detail::serialize_varint_u32(Writer&) [with unsigned int v = 130; Writer = iguana::memory_writer]’
/usr/local/include/iguana/pb_writer.hpp:200:30:   required from ‘void iguana::detail::to_pb_impl(Type&&, uint32_t*&, Writer&) [with unsigned int key = 130; bool omit_default_val = true; Type = const std::__cxx11::basic_string<char>&; Writer = iguana::memory_writer; uint32_t = unsigned int]’
/usr/local/include/iguana/pb_writer.hpp:135:32:   required from ‘iguana::detail::to_pb_impl<0>(const input_t&, uint32_t*&, iguana::memory_writer&)::<lambda(auto:318)> [with auto:318 = std::integral_constant<long unsigned int, 15>]’
/usr/local/include/iguana/pb_util.hpp:338:22:   required from ‘constexpr void iguana::detail::for_each_n(F&&, std::index_sequence<__indices ...>) [with F = to_pb_impl<0>(const input_t&, uint32_t*&, iguana::memory_writer&)::<lambda(auto:318)>; long unsigned int ...I = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; std::index_sequence<__indices ...> = std::integer_sequence<long unsigned int, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15>]’
/usr/local/include/iguana/pb_writer.hpp:114:15:   required from ‘void iguana::detail::to_pb_impl(Type&&, uint32_t*&, Writer&) [with unsigned int key = 0; bool omit_default_val = true; Type = const input_t&; Writer = iguana::memory_writer; uint32_t = unsigned int]’
/usr/local/include/iguana/pb_writer.hpp:482:26:   required from ‘void iguana::to_pb(const T&, Stream&) [with T = input_t; Stream = std::__cxx11::basic_string<char>; typename std::enable_if<(ylt_refletable_v<T> || is_custom_reflection_v<T>), int>::type <anonymous> = 0]’
src/main.cpp:32:18:   required from here
/usr/local/include/iguana/pb_util.hpp:200:61: error: invalid conversion from ‘uint8_t*’ {aka ‘unsigned char*’} to ‘const char*’ [-fpermissive]
  200 |   ((temp = static_cast<uint8_t>(v >> (7 * I)), writer.write(&temp, 1)), ...);
      |                                                             ^~~~~
      |                                                             |
      |                                                             uint8_t* {aka unsigned char*}
In file included from /usr/local/include/iguana/common.hpp:4,
                 from /usr/local/include/iguana/dynamic.hpp:2,
                 from /usr/local/include/ylt/struct_pb/struct_pb_impl.hpp:17:
/usr/local/include/iguana/util.hpp:200:26: note:   initializing argument 1 of ‘void iguana::memory_writer::write(const char*, std::size_t)’
  200 |   void write(const char* data, std::size_t len) {
      |              ~~~~~~~~~~~~^~~~

全部demo代码

#include <iostream>
#include <ylt/struct_pb.hpp>

struct input_t {
	int32_t test;
	int32_t test1;
	int32_t test2;
	std::string tf1;
	std::string tf2;
	std::string tf3;
	std::string tf4;
	int32_t tf5;
	int32_t tf6;
	std::string tf7;
	int32_t tf8;
	std::string tf9;
	std::string tf10;
	std::string tf11;
	std::string tf12;
	std::string tf13;
};

int main(int argc, char** argv) {

    // 模拟数据
    input_t data;
    data.tf13 = "test";

    // 序列化
    std::string ss;
    iguana::to_pb(data, ss);

    std::cout << ss << std::endl;
    std::cout << "hello world!" << std::endl;
    return 0;
}
@pimatrix
Copy link
Author

由于缺少tag,我查了一下,对应的代码版本 d07ad5a

@qicosmos qicosmos mentioned this issue Nov 27, 2024
@qicosmos
Copy link
Owner

是一个编译错误,等pr #333 合并之后就可以了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants