3

Is there an implementation of the MessagePack protocol for Objective-C?

If not, are there examples for bridging the C implementation to Objective-C types?

Kazuki Ohta
  • 1,441
  • 17
  • 17
Bradley Dwyer
  • 8,102
  • 5
  • 32
  • 28

3 Answers3

4

If by bridge you mean the possibility of accessing one language feature from another language, then there is no need of bridging between Objective-C and C. You can call C code directly from Objective-C, so you can use C-MessagePack types directly.

I suppose you already know this, so what you are looking for is a bridge (or adapter, or facade, or bindings, or any of many other names) between Objective-C and MessagePack, allowing you to use MessagePack in a more "Objective-C"-like way.

So I assume that you problem is that the C-API to MessagePack is really "low-level" and that you are looking for an "higher-level" API to MessagePack from Objective-C.

A few proposals:

  1. instead of using the C-API, use the C++ API for MessagePack. This is straightforward and could easily do the job for you. Indeed, the MessagePack C++-API is pretty good, in my opinion, and if you name your Objective-C file with an ".mm" extension, you can mix Objective-C and C++ code in it (this is called Objective-C++).

  2. if you are looking for an even higher-level API to MessagePack, you could use the Python-API and then the Python-Objective-C bridge to allow for mixing Objective-C and Python code. Your performance may vary.

  3. if you are really after the implementation of some kind of intermediate layer (call it as you like) between Objective-C and MessagePack C API, I would suggest using the C++ or Python API to MessagePack as example of design, depending on which language you are most familiar with. So, e.g., you would use an NSArray where a std:vector (or a Python vector) is used, and so on. This should provide a straight way into design of this intermediate layer.

sergio
  • 68,819
  • 11
  • 102
  • 123
  • The second/third paragraphs capture what the intent of the question was. I have no problem working with the C-API with Objective-C and that's probably what I'll end up doing - should I use MessagePack. Thanks for the detailed answer. – Bradley Dwyer Jul 02 '11 at 06:26
3

There is now an official implementation under the MessagePack project.

https://github.com/msgpack/msgpack-objectivec

Bradley Dwyer
  • 8,102
  • 5
  • 32
  • 28
2

https://github.com/chrishulbert/msgpack

Chris Hulbert just implemented and released one.

See his blog for more info:

http://splinter.com.au/messagepack-parser-for-objective-c-iphone

amattn
  • 10,045
  • 1
  • 36
  • 33