Thread: Messagepack-c library, c++ seeing error

  1. #1
    Registered User
    Join Date
    Sep 2020
    Posts
    5

    Messagepack-c library, c++ seeing error

    #include<msgpack.hpp>


    int main(){


    struct item {
    std::time_t currentTime;
    std::map<std::string, std::string> base;
    };




    struct obj {
    std::string eventName;
    item item1;
    std::map<std::string, std::string> dateTime;
    };


    obj obj1[1];
    obj1[0].eventName = "TEMP_EVENT";
    obj1[0].item1.base["Id"] = "6ba1ce80";
    obj1[0].dateTime["TimeFormat"] = "DateTime";
    std::stringstream buffer;
    msgpack: pack(buffer, obj1);// this line is throwing the error
    return 0;

    }

    I am seeing the following error.. doesn't the message pack library support array of struct?..should i use a vector here instead? I am referring to this...

    msgpack/spec.md at master * msgpack/msgpack * GitHub

    left of '.msgpack_pack' must have class/struct/union
    ~\packages\msgpack-c.0.5.9.1\build\native\include\msgpack\object.hpp( 192):
    note: type is 'const obj [1]'
    ~\packages\msgpack-c.0.5.9.1\build\native\include\msgpack\object.hpp( 155):
    note: while compiling class template member function
    'msgpack::v1:acker<Stream>
    &msgpack::v1::detail:acker_serializer<Stream,T>:ack(msgpack::v1:acker<Stream>
    &,const T (&))'
    with
    [
    Stream=std::stringstream,
    T=obj [1]
    ]
    Last edited by Shiv94; 09-27-2020 at 12:03 PM. Reason: incorrect code format

  2. #2
    Registered User
    Join Date
    Aug 2019
    Location
    inside a singularity
    Posts
    309
    Please format your code and add it through "[CODE]" tags. Read the FAQ to understand what I mean.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,082
    Formatting your code properly and posting it within forum bbcode code tags as Zeus_ suggested is really important. It looks like your code attracted the attention of the forum software that does things like replace a colon followed by a "p" with an emoji, then you tried removing the emoji and left your code in a mangled state:
    Code:
    msgpack: pack(buffer, obj1);// this line is throwing the error
    The "msgpack" followed by a colon is what we call a label, typically used with goto, but since we rarely use goto in C++, this rarely gets used. Consequently, I would expect an error message telling you that the name "pack" is unknown, or something along those lines, but we get a different error message, so I'm guessing that you did in fact originally write:
    Code:
    msgpack::pack(buffer, obj1);
    Looking at the README for msgpack for C++, this appears to be correct.

    Quote Originally Posted by Shiv94
    doesn't the message pack library support array of struct?..should i use a vector here instead?
    You're talking about a custom library, not part of the standard library. It is possible that some people here have used it and might know the answer to this immediately, but for the rest of us, we have to do the same thing that you should have done: read the documentation and write test code to check for ourselves.

    I would start by using an int, then an array of int, then a vector int. After I'm confident that I can use msgpack's pack with these three, I would go on to use a struct object of my own: it's possible that you might encounter an error at this point, in which case you'll have to check the msgpack docs on how to fix it. If you don't get an error at this point, then try with an array of the same struct objects, and then a vector of the same struct objects.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ and oracle library runtime error
    By EverydayDiesel in forum C++ Programming
    Replies: 8
    Last Post: 01-16-2014, 10:55 AM
  2. Runtime library error
    By mantracker in forum C++ Programming
    Replies: 2
    Last Post: 11-12-2012, 12:48 PM
  3. Compile error by shlwapi library
    By gretty in forum C++ Programming
    Replies: 1
    Last Post: 03-16-2010, 10:56 AM
  4. error on using shared library
    By -EquinoX- in forum Tech Board
    Replies: 2
    Last Post: 05-06-2008, 04:42 PM
  5. COM library and linking error
    By xhi in forum Windows Programming
    Replies: 1
    Last Post: 08-05-2007, 07:38 PM

Tags for this Thread