homebrew-core/Formula/msgpack.rb
2017-06-07 01:14:48 -07:00

58 lines
2 KiB
Ruby

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.2/msgpack-2.1.2.tar.gz"
sha256 "4f855ac251e927a478aa69e4d3087ec2d5eb62e034e3a7897c1d5d2df97b7863"
head "https://github.com/msgpack/msgpack-c.git"
bottle do
sha256 "064d3c8ba328543bd318981865f7122425e24b059e8c2afedf6c6bac4b26c4d4" => :sierra
sha256 "f566a320cdbff585778035131c541c37446ed906f4f9a0576f82e2b6311b1566" => :el_capitan
sha256 "cb8bd1b6fb71c3d33662746bbc4b45a0ccb5f269433286b30b56b4720591aa03" => :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 <msgpack.h>
#include <stdio.h>
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