59 lines
2.0 KiB
Ruby
59 lines
2.0 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.1/msgpack-2.1.1.tar.gz"
|
|
sha256 "fce702408f0d228a1b9dcab69590d6a94d3938f694b95c9e5e6249617e98d83f"
|
|
head "https://github.com/msgpack/msgpack-c.git"
|
|
|
|
bottle do
|
|
sha256 "432e9e555988a235985920c29bc83120c51dc21e8d4b8ced23733ddf75a36167" => :sierra
|
|
sha256 "566c6a890a685e8ff003d0587dac3fa0f96b529ef1b1a2866cc4b925ae8c4363" => :el_capitan
|
|
sha256 "aaf2e98f329731911441142a79e29d09168761689bd2a7e1058177a878e63bad" => :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
|