msgpack-d icon indicating copy to clipboard operation
msgpack-d copied to clipboard

Pack empty arrays as zero-length arrays

Open Groterik opened this issue 10 years ago • 2 comments

It is point at issue, but it seems like it is better in terms of compatibility with other languages. For example, msgpack-c provides default adapters for vectors and strings that throw an exception in case of nil value deserialization. It is ok to send c++ empty std::vectors, std::strings, std::vectors of std::strings, etc, packed by default to the dlang application and get dlang empty strings, arrays[], etc, but not the other way around. That's why communication between dlang-app and cpp-app via msgpack is complicated. Also python implementation of msgpack produces zero-length arrays. In addition, zero-length arrays are serialized into one byte as well as nil value.

Groterik avatar Jan 30 '15 14:01 Groterik

Thanks!

But this breaks backward compatibility. I have a plan to implement new spec and this is a chance to merge this PR. Please wait.

repeatedly avatar Feb 01 '15 04:02 repeatedly

I'm reconsider this issue. In C++, std::vector and other containers are struct so they can't handle nil properly. But In Java, C# or other languages, they can handle nil for container object. So this change is not good for almost languages.

There are several approaches to resolve this issue.

  • msgpack-c supports nil in containers. Maybe returns uninitialized container?
  • msgpack-d provides handleNilAsZeroSizeContainer like parameter to switch behaviours.

repeatedly avatar Mar 01 '16 21:03 repeatedly