mikeloomisgg/cppack

No Member name pack

Opened this issue · 7 comments

After adding and calling msgpack.h , compiling the code makes an error

/workspaces/call-exchange-service/third_party/msgpack/include/msgpack.h:969:7: error: no member named 'pack' in 'domain::exchange::contracts::registration' [clang-diagnostic-error]
[build]   obj.pack(unpacker);
[build]   ~~~ ^

Is there something that is supposed to be done to fix this ?

I'm getting the same error.

We are getting this error because there are two errors on the home-page source code example (!)

template
void msgpack(T &pack) {
pack(name, age, aliases);
}

should be:
template
void pack(T &pack) {
pack(name, age, aliases);
}

and if that wasn't enough... there's a second bug on the home-page:

auto john = msgpack::unpack(data.data()); // Unpack it

should be:
struct Person john = msgpack::unpack(data); // Unpack it

These errors have probably frustrated many to the point that they skipped passed this project.

I checked through the examples after finding I liked the way this C++ implementation use of structures to serialize and desalinize the data.

I suggest you update your home page to code that works.

Also I had to add the two lines to your msgpack.hpp file:
#include <system_error>
#include <unordered_map>

(had to get the unordered maps to work)

Here's the code that compiles and works for me:

// all of cppack source code is included in this header file
#include "msgpack.hpp"

#include <iostream>
#include <string>
#include <vector>

struct Person {
  std::string name;
  uint16_t age;
  std::vector<std::string> aliases;

  template<class T>
    void pack(T &pack) {
      pack(name, age, aliases);
    }
};

int main()
{  
  struct Person person = Person {"John", 22, {"Ripper", "Silverhand"}};

  auto data = msgpack::pack(person); // Pack your object
  struct Person  john = msgpack::unpack<Person>(data); // Unpack it

  return 0;
}

I'm guessing a PR to correct the demo code might be a good idea.

Will do.

Isuxiz commented

I'm getting the same error.我得到了同样的错误。

We are getting this error because there are two errors on the home-page source code example (!)我们得到这个错误是因为在主页源代码示例中有两个错误(!)

template 模板 void msgpack(T &pack) { public void onDestroyCode(){ pack(name, age, aliases); pack(name,age,aliases); }

should be: 应该是: template  模板 void pack(T &pack) { public void run(T & run){ pack(name, age, aliases); pack(name,age,aliases); }

and if that wasn't enough... there's a second bug on the home-page:如果这还不够的话主页上还有第二个bug:

auto john = msgpack::unpack**(data.data())**; // Unpack itpublic int findDuplicate();//打开它

should be: 应该是: struct Person john = msgpack::unpack(data); // Unpack it struct Person john = msgpack::unpack(data);//打开它

These errors have probably frustrated many to the point that they skipped passed this project.这些错误可能使许多人感到沮丧,以至于他们跳过了这个项目。

I checked through the examples after finding I liked the way this C++ implementation use of structures to serialize and desalinize the data.在发现我喜欢这个C++实现使用结构来序列化和淡化数据的方式之后,我检查了这些示例。

I suggest you update your home page to code that works.我建议你更新你的主页代码工作。

Also I had to add the two lines to your msgpack.hpp file:另外,我必须在msgpack.hpp文件中添加两行: #include <system_error>  #include #include <unordered_map> #include (had to get the unordered maps to work) (had让无序的地图工作)

Here's the code that compiles and works for me:下面是编译并为我工作的代码:

// all of cppack source code is included in this header file
#include "msgpack.hpp"

#include <iostream>
#include <string>
#include <vector>

struct Person {
  std::string name;
  uint16_t age;
  std::vector<std::string> aliases;

  template<class T>
    void pack(T &pack) {
      pack(name, age, aliases);
    }
};

int main()
{  
  struct Person person = Person {"John", 22, {"Ripper", "Silverhand"}};

  auto data = msgpack::pack(person); // Pack your object
  struct Person  john = msgpack::unpack<Person>(data); // Unpack it

  return 0;
}

Thanks for saving my night!

I guess this lib is just broken in C++20?

Actually, there's another issue on unpacking float64 data (function unpack_type)
Double value which contain negative exponent (for example, any double between (0.0, 1.0)) cannot be unpacked succesfully.
This is due to a wrong declartion on line 892 and line 931:

uint8_t exponent = 0;
uint16_t exponent = 0;

This should be int8_t and int16_t, since exponent can be negative, and make it unsigned and then -= 127 or -= 1024 does not make any sense, which leads to double value become infinity.

Since we have errors that have not been attended to in over a year we need to fork this project with someone capable of managing it; So we can keep the issues fixed and maintained (and maybe add some new features requested by the community). Anyone willing to pick up the mantle with a fork of this project?