class Msgpack < Formula desc "Library for a binary-based efficient data interchange format" homepage "https://msgpack.org/" url "https://github.com/msgpack/msgpack-c/releases/download/cpp-2.1.0/msgpack-2.1.0.tar.gz" sha256 "2a748905eabb1320842a405bbf755c3503c504eaa32cfa807d823ec0ab5c52ad" head "https://github.com/msgpack/msgpack-c.git" bottle do sha256 "d1e4c186dcd89239f2665da4676abdda94e366b48aa9d28a308065cf8771caf2" => :sierra sha256 "283edc57844591ef0393a9d4ab1af37b43d373f5c204d1a3ea6bd22c1e7f6221" => :el_capitan sha256 "aefdc024a92c7faa25e08f3756f61cac07527aa40646f63444be35df8486fe03" => :yosemite end depends_on "cmake" => :build def install system "cmake", ".", *std_cmake_args system "make", "install" end test do # Reference: http://wiki.msgpack.org/display/MSGPACK/QuickStart+for+C+Language (testpath/"test.c").write <<-EOS.undent #include #include int main(void) { msgpack_sbuffer* buffer = msgpack_sbuffer_new(); msgpack_packer* pk = msgpack_packer_new(buffer, msgpack_sbuffer_write); msgpack_pack_int(pk, 1); msgpack_pack_int(pk, 2); msgpack_pack_int(pk, 3); /* deserializes these objects using msgpack_unpacker. */ msgpack_unpacker pac; msgpack_unpacker_init(&pac, MSGPACK_UNPACKER_INIT_BUFFER_SIZE); /* feeds the buffer. */ msgpack_unpacker_reserve_buffer(&pac, buffer->size); memcpy(msgpack_unpacker_buffer(&pac), buffer->data, buffer->size); msgpack_unpacker_buffer_consumed(&pac, buffer->size); /* now starts streaming deserialization. */ msgpack_unpacked result; msgpack_unpacked_init(&result); while(msgpack_unpacker_next(&pac, &result)) { msgpack_object_print(stdout, result.data); puts(""); } } EOS system ENV.cc, "-o", "test", "test.c", "-lmsgpackc" assert_equal "1\n2\n3\n", `./test` end end