Skip to content

Commit c1847eb

Browse files
committed
Merge branch 'develop' into master, release 0.5
2 parents 586dbab + 6a7bfaf commit c1847eb

18 files changed

+221
-99
lines changed

AUTHORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Nicholas Fraser
2+
Jerry Jacobs

CHANGELOG.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
msgpack-tools v0.5
2+
------------------
3+
4+
Changes:
5+
6+
- Removed top-level array/map requirement (#3)
7+
- Moved dependency downloading and man page generation into CMake build process (#2)
8+
- Added support for build .deb package (#1)
9+
- Fixed incorrect buffer sizes
10+
11+
msgpack-tools v0.4
12+
------------------
13+
14+
Changes:
15+
16+
- Fixed issues with stream parsing (e.g. piping to/from netcat)
17+
- Fixed man page installation directory (`prefix/share/man`)
18+
19+
msgpack-tools v0.3.1
20+
--------------------
21+
22+
Changes:
23+
24+
- Fixed build errors on old compilers that default to C89
25+
26+
msgpack-tools v0.3
27+
------------------
28+
29+
Changes:
30+
31+
- Switched JSON parsing library to RapidJSON
32+
- Updated [`configure`](https://github.com/nemequ/configure-cmake) script to support `LDFLAGS` and non-bash shells
33+
34+
msgpack-tools v0.2
35+
------------------
36+
37+
Changes:
38+
39+
- Renamed project to **msgpack-tools**
40+
- Added `./configure` CMake wrapper from [nemequ/configure-cmake](https://github.com/nemequ/configure-cmake)
41+
- Updated MPack and YAJL versions
42+
43+
msgpack2json v0.1
44+
-----------------
45+
46+
Initial release

CMakeLists.txt

Lines changed: 99 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ include(CheckCXXCompilerFlag)
66

77
project(msgpack2json)
88

9+
# compat with cmake > 3.0, this should be autodetected with the git command (tag) or a released file
10+
set(PROJECT_VERSION_MAJOR 0)
11+
set(PROJECT_VERSION_MINOR 5)
12+
set(PROJECT_VERSION_PATCH 0)
13+
14+
if(PROJECT_VERSION_PATCH STREQUAL "0")
15+
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
16+
else()
17+
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
18+
endif()
19+
920
set(CONTRIB_DIR ${CMAKE_BINARY_DIR}/contrib)
1021
file(MAKE_DIRECTORY ${CONTRIB_DIR})
1122

@@ -33,14 +44,14 @@ else()
3344
endif()
3445

3546
set(MPACK_COMMIT "8c13a0d7f8a1232a189634768b94740861cbaf3e")
36-
set(RAPIDJSON_COMMIT "75d0e4ff652769309052bbbb3745da12a572af9a")
47+
set(RAPIDJSON_COMMIT "369de87e5d7da05786731a712f25ab9b46c4b0ce")
3748
set(LIBB64_VERSION "1.2.1")
3849

3950
if(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv|nmake)")
4051
# Windows support is not implemented yet
4152
add_definitions(/W2)
4253
else()
43-
set(FLAGS "-Wall -Wextra -DLIBB64_VERSION=\\\"${LIBB64_VERSION}\\\"")
54+
set(FLAGS "-Wall -Wextra -DVERSION=\\\"${PROJECT_VERSION}\\\" -DLIBB64_VERSION=\\\"${LIBB64_VERSION}\\\"")
4455
set(CMAKE_C_FLAGS_DEBUG "${C_FLAGS} ${FLAGS} -g -O0 -DDEBUG")
4556
set(CMAKE_C_FLAGS_RELEASE "${C_FLAGS} ${FLAGS} -O3 -DNDEBUG -fPIC -DPIC")
4657
set(CMAKE_CXX_FLAGS_DEBUG "${CXX_FLAGS} ${FLAGS} -g -O0 -DDEBUG")
@@ -53,9 +64,16 @@ endif()
5364

5465
set(MPACK_FILE "mpack-${MPACK_COMMIT}.tar.gz")
5566
set(MPACK_DIR "${CONTRIB_DIR}/mpack-${MPACK_COMMIT}")
67+
set(MPACK_URL "https://github.com/ludocode/mpack/archive/${MPACK_COMMIT}.tar.gz")
5668

57-
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/contrib/${MPACK_FILE}")
58-
message(FATAL_ERROR "\nMPack source is missing: contrib/${MPACK_FILE}\nTo build from the repository, you need to fetch dependencies with tools/fetch.sh")
69+
if(EXISTS "${CMAKE_SOURCE_DIR}/contrib/${MPACK_FILE}")
70+
message(STATUS "Found package: ${MPACK_FILE}")
71+
else()
72+
message(STATUS "Downloading: ${MPACK_FILE}")
73+
file(DOWNLOAD ${MPACK_URL} "${CMAKE_SOURCE_DIR}/contrib/${MPACK_FILE}")
74+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/contrib/${MPACK_FILE}")
75+
message(FATAL_ERROR "\nFailed to download source file: ${MPACK_FILE}\nFrom: ${MPACK_URL}")
76+
endif()
5977
endif()
6078

6179
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf ${CMAKE_SOURCE_DIR}/contrib/${MPACK_FILE} WORKING_DIRECTORY ${CONTRIB_DIR})
@@ -68,9 +86,16 @@ include_directories(SYSTEM ${CMAKE_BINARY_DIR} ${MPACK_DIR}/src)
6886

6987
set(RAPIDJSON_FILE "rapidjson-${RAPIDJSON_COMMIT}.tar.gz")
7088
set(RAPIDJSON_DIR "${CONTRIB_DIR}/rapidjson-${RAPIDJSON_COMMIT}")
89+
set(RAPIDJSON_URL "https://github.com/miloyip/rapidjson/archive/${RAPIDJSON_COMMIT}.tar.gz")
7190

72-
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/contrib/${RAPIDJSON_FILE}")
73-
message(FATAL_ERROR "\nRapidJSON source is missing: contrib/${RAPIDJSON_FILE}\nTo build from the repository, you need to fetch dependencies with tools/fetch.sh")
91+
if(EXISTS "${CMAKE_SOURCE_DIR}/contrib/${RAPIDJSON_FILE}")
92+
message(STATUS "Found package: ${RAPIDJSON_FILE}")
93+
else()
94+
message(STATUS "Downloading: ${RAPIDJSON_FILE}")
95+
file(DOWNLOAD ${RAPIDJSON_URL} "${CMAKE_SOURCE_DIR}/contrib/${RAPIDJSON_FILE}")
96+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/contrib/${RAPIDJSON_FILE}")
97+
message(FATAL_ERROR "\nFailed to download source file: ${RAPIDJSON_FILE}\nFrom: ${RAPIDJSON_URL}")
98+
endif()
7499
endif()
75100

76101
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf ${CMAKE_SOURCE_DIR}/contrib/${RAPIDJSON_FILE} WORKING_DIRECTORY ${CONTRIB_DIR})
@@ -82,9 +107,16 @@ include_directories(SYSTEM ${RAPIDJSON_DIR}/include)
82107

83108
set(LIBB64_FILE "libb64-${LIBB64_VERSION}.zip")
84109
set(LIBB64_DIR "${CONTRIB_DIR}/libb64-${LIBB64_VERSION}")
110+
set(LIBB64_URL "http://downloads.sourceforge.net/project/libb64/libb64/libb64/${LIBB64_FILE}?use_mirror=autoselect")
85111

86-
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/contrib/${LIBB64_FILE}")
87-
message(FATAL_ERROR "\nlibb64 source is missing: contrib/${LIBB64_FILE}\nTo build from the repository, you need to fetch dependencies with tools/fetch.sh")
112+
if(EXISTS "${CMAKE_SOURCE_DIR}/contrib/${LIBB64_FILE}")
113+
message(STATUS "Found package: ${LIBB64_FILE}")
114+
else()
115+
message(STATUS "Downloading: ${LIBB64_FILE}")
116+
file(DOWNLOAD ${LIBB64_URL} "${CMAKE_SOURCE_DIR}/contrib/${LIBB64_FILE}")
117+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/contrib/${LIBB64_FILE}")
118+
message(FATAL_ERROR "\nFailed to download source file: ${LIBB64_FILE}\nFrom: ${LIBB64_URL}")
119+
endif()
88120
endif()
89121

90122
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf "${CMAKE_SOURCE_DIR}/contrib/${LIBB64_FILE}" WORKING_DIRECTORY "${CONTRIB_DIR}")
@@ -99,21 +131,52 @@ file(GLOB_RECURSE LIBB64_SRCS ${LIBB64_DIR}/src/*.c)
99131
include_directories(SYSTEM ${LIBB64_DIR}/include)
100132

101133

102-
# targets
134+
# executable targets
103135

104136
add_executable(msgpack2json src/msgpack2json.cpp ${MPACK_SRCS} ${LIBB64_SRCS})
105137
add_executable(json2msgpack src/json2msgpack.cpp ${MPACK_SRCS} ${LIBB64_SRCS})
106138

107139
install(TARGETS msgpack2json json2msgpack DESTINATION bin)
108140

109-
install(FILES ${CMAKE_SOURCE_DIR}/docs/msgpack2json.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1)
110-
install(FILES ${CMAKE_SOURCE_DIR}/docs/json2msgpack.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1)
111141

112-
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/docs/msgpack2json.1")
113-
message(FATAL_ERROR "\nmsgpack2json man page is missing: docs/msgpack2json.1\nTo build from the repository, you need to generate manpages with tools/man.sh")
114-
endif()
115-
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/docs/json2msgpack.1")
116-
message(FATAL_ERROR "\njson2msgpack man page is missing: docs/json2msgpack.1\nTo build from the repository, you need to generate manpages with tools/man.sh")
142+
# manpages
143+
144+
if(EXISTS "${CMAKE_SOURCE_DIR}/docs/msgpack2json.1" AND EXISTS "${CMAKE_SOURCE_DIR}/docs/json2msgpack.1")
145+
# install pre-generated pages
146+
message(STATUS "Found pre-generated man pages: docs/msgpack2json.1 docs/json2msgpack.1")
147+
install(FILES ${CMAKE_SOURCE_DIR}/docs/msgpack2json.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1)
148+
install(FILES ${CMAKE_SOURCE_DIR}/docs/json2msgpack.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1)
149+
else()
150+
151+
# try to find md2man-roff
152+
find_program(MD2MAN-ROFF md2man-roff)
153+
if(MD2MAN-ROFF STREQUAL "MD2MAN-ROFF-NOTFOUND")
154+
message(WARNING "\nmd2man-roff is not installed. Man pages will not be created!\nSee: https://github.com/sunaku/md2man")
155+
else()
156+
157+
# add custom commands to build man pages
158+
# cmake is insanely verbose for creating custom builders
159+
160+
message(STATUS "Found md2man-roff: ${MD2MAN-ROFF}")
161+
add_custom_command(
162+
OUTPUT ${CMAKE_BINARY_DIR}/msgpack2json.1
163+
MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/docs/msgpack2json.md
164+
COMMAND cat ${CMAKE_SOURCE_DIR}/docs/msgpack2json.md | sed "s/\$version/${PROJECT_VERSION}/" | ${MD2MAN-ROFF} > ${CMAKE_BINARY_DIR}/msgpack2json.1
165+
VERBATIM)
166+
add_custom_target(msgpack2json-man DEPENDS ${CMAKE_BINARY_DIR}/msgpack2json.1)
167+
add_dependencies(msgpack2json msgpack2json-man)
168+
install(FILES ${CMAKE_BINARY_DIR}/msgpack2json.1 DESTINATION share/man/man1)
169+
170+
add_custom_command(
171+
OUTPUT ${CMAKE_BINARY_DIR}/json2msgpack.1
172+
MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/docs/json2msgpack.md
173+
COMMAND cat ${CMAKE_SOURCE_DIR}/docs/json2msgpack.md | sed "s/\$version/${PROJECT_VERSION}/" | ${MD2MAN-ROFF} > ${CMAKE_BINARY_DIR}/json2msgpack.1
174+
VERBATIM)
175+
add_custom_target(json2msgpack-man DEPENDS ${CMAKE_BINARY_DIR}/json2msgpack.1)
176+
add_dependencies(json2msgpack json2msgpack-man)
177+
install(FILES ${CMAKE_BINARY_DIR}/json2msgpack.1 DESTINATION share/man/man1)
178+
179+
endif()
117180
endif()
118181

119182

@@ -148,5 +211,23 @@ add_test("json2msgpack-base64-detect-bin-one" ${COMPARE} ${TESTS_DIR}/base64-bin
148211
add_test("json2msgpack-base64-mixed-partial" ${COMPARE} ${TESTS_DIR}/base64-partial-ext.mp ${VALGRIND} ./json2msgpack -bB 50 -i ${TESTS_DIR}/base64-mixed.json)
149212
add_test("json2msgpack-base64-mixed-bin" ${COMPARE} ${TESTS_DIR}/base64-bin-ext.mp ${VALGRIND} ./json2msgpack -bB 22 -i ${TESTS_DIR}/base64-mixed.json)
150213

151-
#add_test("json2msgpack-base64-bin" ${COMPARE_SCRIPT} ${TESTS_DIR}/base64-bin.mp valgrind ./json2msgpack -bi ${TESTS_DIR}/base64-prefix.json)
152-
#add_test("json2msgpack-base64-bin-lax" ${COMPARE_SCRIPT} ${TESTS_DIR}/base64-bin.mp valgrind ./json2msgpack -lbi ${TESTS_DIR}/base64-prefix-lax.json)
214+
add_test("json2msgpack-value-string" ${COMPARE} ${TESTS_DIR}/value-string.mp ${VALGRIND} ./json2msgpack -i ${TESTS_DIR}/value-string.json)
215+
add_test("json2msgpack-value-int" ${COMPARE} ${TESTS_DIR}/value-int.mp ${VALGRIND} ./json2msgpack -i ${TESTS_DIR}/value-int.json)
216+
add_test("msgpack2json-value-string" ${COMPARE} ${TESTS_DIR}/value-string.json ${VALGRIND} ./msgpack2json -i ${TESTS_DIR}/value-string.mp)
217+
add_test("msgpack2json-value-int" ${COMPARE} ${TESTS_DIR}/value-int.json ${VALGRIND} ./msgpack2json -i ${TESTS_DIR}/value-int.mp)
218+
219+
220+
# packaging
221+
222+
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND EXISTS "/etc/debian_version")
223+
message(STATUS "Debian-based Linux OS detected")
224+
set(CPACK_GENERATOR "DEB")
225+
set(CPACK_PACKAGE_NAME "msgpack-tools")
226+
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
227+
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}-${CMAKE_SYSTEM_PROCESSOR}" )
228+
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/ludocode/msgpack-tools")
229+
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Jerry Jacobs")
230+
set(CPACK_PACKAGE_CONTACT "[email protected]")
231+
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Command-line tools for converting between MessagePack and JSON")
232+
include(CPack)
233+
endif()

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ They can be used for dumping MessagePack from a file or web API to a human-reada
1010

1111
## Build Status
1212

13-
| [Travis-CI](https://travis-ci.org/) |
14-
| :-------: |
15-
| [![Build Status](https://travis-ci.org/ludocode/msgpack-tools.svg?branch=master)](https://travis-ci.org/ludocode/msgpack-tools/branches) |
13+
[travis-home]: https://travis-ci.org/
14+
[travis-msgpack-tools]: https://travis-ci.org/ludocode/msgpack-tools/branches
15+
16+
<!-- we use some deprecated HTML attributes here to get these stupid badges to line up properly -->
17+
| Branch | [Travis-CI][travis-home] |
18+
| :-------: | :-------: |
19+
| _master_ | [<img src="https://travis-ci.org/ludocode/msgpack-tools.svg?branch=master" alt="Build Status" align="top" vspace="4">][travis-msgpack-tools] |
20+
| _develop_ | [<img src="https://travis-ci.org/ludocode/msgpack-tools.svg?branch=develop" alt="Build Status" align="top" vspace="4">][travis-msgpack-tools] |
1621

1722
## Examples
1823

src/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ extern "C" {
3939
#include "b64/cencode.h"
4040
}
4141

42-
#define VERSION "0.4"
42+
#define BUFFER_SIZE 65536
4343

4444
#endif

src/json2msgpack.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,9 @@ static bool output(options_t* options, Document& document) {
223223
out_file = stdout;
224224
}
225225

226+
char* buffer = (char*)malloc(BUFFER_SIZE);
226227
mpack_writer_t writer;
227-
mpack_writer_init_stack(&writer);
228+
mpack_writer_init(&writer, buffer, BUFFER_SIZE);
228229
mpack_writer_set_context(&writer, out_file);
229230
mpack_writer_set_flush(&writer, flush);
230231

@@ -233,6 +234,7 @@ static bool output(options_t* options, Document& document) {
233234
mpack_error_t error = mpack_writer_destroy(&writer);
234235
if (out_file != stdout)
235236
fclose(out_file);
237+
free(buffer);
236238
return error == mpack_ok;
237239
}
238240

src/msgpack2json.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,11 @@ static bool base64_ext(mpack_reader_t* reader, WriterType& writer, options_t* op
145145
}
146146

147147
template <class WriterType>
148-
static bool element(mpack_reader_t* reader, WriterType& writer, options_t* options, int depth) {
148+
static bool element(mpack_reader_t* reader, WriterType& writer, options_t* options) {
149149
const mpack_tag_t tag = mpack_read_tag(reader);
150150
if (mpack_reader_error(reader) != mpack_ok)
151151
return false;
152152

153-
if (!options->debug && depth == 0 && (tag.type != mpack_type_map && tag.type != mpack_type_array)) {
154-
fprintf(stderr, "%s: Top-level object must be a map or array. Try debug viewing mode (-d)\n", options->command);
155-
return false;
156-
}
157-
158-
// TODO check not depth zero
159153
switch (tag.type) {
160154
case mpack_type_bool: return writer.Bool(tag.v.b);
161155
case mpack_type_nil: return writer.Null();
@@ -199,7 +193,7 @@ static bool element(mpack_reader_t* reader, WriterType& writer, options_t* optio
199193
if (!writer.StartArray())
200194
return false;
201195
for (size_t i = 0; i < tag.v.l; ++i)
202-
if (!element(reader, writer, options, depth + 1))
196+
if (!element(reader, writer, options))
203197
return false;
204198
mpack_done_array(reader);
205199
return writer.EndArray();
@@ -210,7 +204,7 @@ static bool element(mpack_reader_t* reader, WriterType& writer, options_t* optio
210204
for (size_t i = 0; i < tag.v.l; ++i) {
211205

212206
if (options->debug) {
213-
element(reader, writer, options, depth + 1);
207+
element(reader, writer, options);
214208
} else {
215209
uint32_t len = mpack_expect_str(reader);
216210
if (mpack_reader_error(reader) != mpack_ok) {
@@ -221,7 +215,7 @@ static bool element(mpack_reader_t* reader, WriterType& writer, options_t* optio
221215
return false;
222216
}
223217

224-
if (!element(reader, writer, options, depth + 1))
218+
if (!element(reader, writer, options))
225219
return false;
226220
}
227221
mpack_done_map(reader);
@@ -261,19 +255,27 @@ static bool convert(options_t* options) {
261255
mpack_reader_set_fill(&reader, fill);
262256
mpack_reader_set_context(&reader, in_file);
263257

264-
char* buffer = (char*)malloc(65536);
265-
FileWriteStream stream(out_file, buffer, sizeof(buffer));
266-
267258
bool ret;
268-
if (options->pretty) {
269-
PrettyWriter<FileWriteStream> writer(stream);
270-
ret = element(&reader, writer, options, 0);
271-
// RapidJSON's PrettyWriter does not add a final
272-
// newline at the end of the JSON
273-
putc('\n', out_file);
274-
} else {
275-
Writer<FileWriteStream> writer(stream);
276-
ret = element(&reader, writer, options, 0);
259+
char* buffer = (char*)malloc(BUFFER_SIZE);
260+
{
261+
FileWriteStream stream(out_file, buffer, BUFFER_SIZE);
262+
263+
if (options->pretty) {
264+
PrettyWriter<FileWriteStream> writer(stream);
265+
ret = element(&reader, writer, options);
266+
267+
// RapidJSON's PrettyWriter does not add a final
268+
// newline at the end of the JSON
269+
putc('\n', out_file);
270+
271+
} else {
272+
Writer<FileWriteStream> writer(stream);
273+
ret = element(&reader, writer, options);
274+
}
275+
276+
// Writer/FileWriteStream do not flush when writing standalone values:
277+
// https://github.com/miloyip/rapidjson/issues/684
278+
stream.Flush();
277279
}
278280

279281
free(buffer);

tests/value-int.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5

tests/value-int.mp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+


tests/value-string.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"OK"

0 commit comments

Comments
 (0)