Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8581721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:07:14+00:00 2026-06-11T21:07:14+00:00

In looking at the C API for MessagePack, there are a number of functions

  • 0

In looking at the C API for MessagePack, there are a number of functions to appropriately serialize (pack) the data according to type: msgpack_pack_uint8, msgpack_pack_int32, …

There doesn’t seem to be the equivalent call in the API to unpack the data. msgpack_unpack_next returns a msgpack_object. These objects only have coarse granularity of types (the largest of the type: int64, double, …), based on the enums included.

Am I missing something here? Is the expectation that the coarse object be used and then cast?

How should unpacking be done properly?

Furthermore, is there any good documentation or usage examples? The ones on the website are trivial.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:07:15+00:00Added an answer on June 11, 2026 at 9:07 pm

    At unpack time, any integer value is always stored within a msgpack_object as a fixed-width 64-bit integer (int64_t if negative, uint64_t otherwise).

    See cpp/src/msgpack/object.h for more details on msgpack_object et al., and cpp/src/msgpack/unpack.c to see how msgpack handles the unpacking logic, e.g.:

    static inline int template_callback_int8(unpack_user* u,
                                             int8_t d,
                                             msgpack_object* o) {
        if(d >= 0) {
            o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = d;
            return 0;
        }
        else {
            o->type = MSGPACK_OBJECT_NEGATIVE_INTEGER; o->via.i64 = d;
            return 0;
        }
    }
    

    This is because at pack time, msgpack chooses dynamically the most optimal way to encode an integer according to its value, e.g. if you use msgpack_pack_uint16 to pack your integer then:

    • it will be saved in 1 byte if the value is in [0, 127],
    • 2 bytes with 0xcc as first byte if the value is in [128, 255],
    • 3 bytes with 0xcd as first byte otherwise.

    See msgpack_pack_real_uint16 from cpp/src/msgpack/pack_template.h for more details.


    In other words at unpack time, msgpack uses a large enough positive or negative (test if obj.type is MSGPACK_OBJECT_POSITIVE_INTEGER or MSGPACK_OBJECT_NEGATIVE_INTEGER) to hold any integer value. So it’s up to you to:

    • cast if you can always assume that values will never overflow your cast type,
    • or, check dynamically (with a mask) if the value is not large enough for your receiver type,
    • or, always use an int64_t or uint64_t.

    At last, the C test suite (msgpack/cpp/test/msgpackc_test.cpp) might be helpful to browse code samples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking at the API there doesn't seem to be a way to center a
Whenever looking at API libraries for Python, there seems to be about half of
Looking for Win32 API functions, C++ or Delphi sample code that tells me the
I'm looking for an API that will provide real-time lightning strike data in a
On iOS, I am looking for an API equivalent to the encrypt/decrpyt DPAPI functions
Is there any API to get all the files of particular content type in
I was looking at the API documentation for stl vector, and noticed there was
We're looking for graph API access to the data represented here: http://www.facebook.com/{user}/allactivity
I've been looking over the API's and searching there forums, but I can't find
Im looking for online API documentation for the Prism framework (prism 4). Does it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.