59 lines
2.1 KiB
Ruby
59 lines
2.1 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-3.1.0/msgpack-3.1.0.tar.gz"
|
|
sha256 "2ca2d36672927d7d353927c50be0a06434c0f0fcb9d96ffa0165d9ce40665a6a"
|
|
head "https://github.com/msgpack/msgpack-c.git"
|
|
|
|
bottle do
|
|
sha256 "578e8f0e351ff9f8f2e3ce05b825f34b87f06826b21bcead9e0f790e1c093bdc" => :mojave
|
|
sha256 "43da802c250658942499e836eeb580b6f59f3b5365755f514c39abef0ec5eb93" => :high_sierra
|
|
sha256 "8099aa9ad0d10d793d9446b761ade56d32a636fc0aa5b76a74a4b99ff0d137ba" => :sierra
|
|
sha256 "cca40422bfd47697d395f258a77e4df25bdb81ee1c1db991460e495fb7bc92a9" => :el_capitan
|
|
end
|
|
|
|
depends_on "cmake" => :build
|
|
|
|
def install
|
|
system "cmake", ".", *std_cmake_args
|
|
system "make", "install"
|
|
end
|
|
|
|
test do
|
|
# Reference: https://github.com/msgpack/msgpack-c/blob/master/QUICKSTART-C.md
|
|
(testpath/"test.c").write <<~EOS
|
|
#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", "-L#{lib}", "-lmsgpackc"
|
|
assert_equal "1\n2\n3\n", `./test`
|
|
end
|
|
end
|