Skip to content

Question: parsing void * #655

Description

@urban-1

Hi all,

Quick question: I am using librdkafka to receive messages whose payload is JSON string. The library returns the payload in a non-null terminated void* and provides a message->len() to indicate how many characters/bytes are valid. Is it possible to call something like: json::parse(void*, const size_t&)?

I see that the parser supports char* type but it overruns the string's length causing an overflow ...

The solutions I see are:

  1. Provide a json::parse(void*, const size_t&) signature maybe by extending/overloading parse(T(&) array[N] ...)
  2. Enable the parser to detect the closing } character and stop

At the moment I am using strncpy to populate a pre-allocated buffer and terminate it properly before passing it to parse. This is an extra copy operation which could be avoided...

Many thanks for this awesome library - let me know what you think,

Andreas

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions