Commit 65146e05 authored by Matthew Maurer's avatar Matthew Maurer

Merge branch 'master' into canonicalize-pr

parents ca8c1386 981814eb
...@@ -109,6 +109,9 @@ if(NOT MSVC) # Don't install pkg-config files when building with MSVC ...@@ -109,6 +109,9 @@ if(NOT MSVC) # Don't install pkg-config files when building with MSVC
configure_file(capnp-rpc.pc.in "${CMAKE_CURRENT_BINARY_DIR}/capnp-rpc.pc" @ONLY) configure_file(capnp-rpc.pc.in "${CMAKE_CURRENT_BINARY_DIR}/capnp-rpc.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/capnp-rpc.pc" DESTINATION "${LIB_INSTALL_DIR}/pkgconfig") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/capnp-rpc.pc" DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
configure_file(capnp-json.pc.in "${CMAKE_CURRENT_BINARY_DIR}/capnp-json.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/capnp-json.pc" DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
endif() endif()
unset(STDLIB_FLAG) unset(STDLIB_FLAG)
......
...@@ -74,7 +74,8 @@ public_capnpc_inputs = \ ...@@ -74,7 +74,8 @@ public_capnpc_inputs = \
src/capnp/schema.capnp \ src/capnp/schema.capnp \
src/capnp/rpc.capnp \ src/capnp/rpc.capnp \
src/capnp/rpc-twoparty.capnp \ src/capnp/rpc-twoparty.capnp \
src/capnp/persistent.capnp src/capnp/persistent.capnp \
src/capnp/compat/json.capnp
capnpc_inputs = \ capnpc_inputs = \
$(public_capnpc_inputs) \ $(public_capnpc_inputs) \
...@@ -92,12 +93,15 @@ capnpc_outputs = \ ...@@ -92,12 +93,15 @@ capnpc_outputs = \
src/capnp/rpc-twoparty.capnp.h \ src/capnp/rpc-twoparty.capnp.h \
src/capnp/persistent.capnp.c++ \ src/capnp/persistent.capnp.c++ \
src/capnp/persistent.capnp.h \ src/capnp/persistent.capnp.h \
src/capnp/compat/json.capnp.h \
src/capnp/compat/json.capnp.c++ \
src/capnp/compiler/lexer.capnp.c++ \ src/capnp/compiler/lexer.capnp.c++ \
src/capnp/compiler/lexer.capnp.h \ src/capnp/compiler/lexer.capnp.h \
src/capnp/compiler/grammar.capnp.c++ \ src/capnp/compiler/grammar.capnp.c++ \
src/capnp/compiler/grammar.capnp.h src/capnp/compiler/grammar.capnp.h
includecapnpdir = $(includedir)/capnp includecapnpdir = $(includedir)/capnp
includecapnpcompatdir = $(includecapnpdir)/compat
includekjdir = $(includedir)/kj includekjdir = $(includedir)/kj
includekjparsedir = $(includekjdir)/parse includekjparsedir = $(includekjdir)/parse
includekjstddir = $(includekjdir)/std includekjstddir = $(includekjdir)/std
...@@ -183,10 +187,14 @@ includecapnp_HEADERS = \ ...@@ -183,10 +187,14 @@ includecapnp_HEADERS = \
src/capnp/persistent.capnp.h \ src/capnp/persistent.capnp.h \
src/capnp/ez-rpc.h src/capnp/ez-rpc.h
includecapnpcompat_HEADERS = \
src/capnp/compat/json.h \
src/capnp/compat/json.capnp.h
if LITE_MODE if LITE_MODE
lib_LTLIBRARIES = libkj.la libkj-test.la libcapnp.la lib_LTLIBRARIES = libkj.la libkj-test.la libcapnp.la
else else
lib_LTLIBRARIES = libkj.la libkj-test.la libkj-async.la libcapnp.la libcapnp-rpc.la libcapnpc.la lib_LTLIBRARIES = libkj.la libkj-test.la libkj-async.la libcapnp.la libcapnp-rpc.la libcapnp-json.la libcapnpc.la
endif endif
# Don't include security release in soname -- we want to replace old binaries # Don't include security release in soname -- we want to replace old binaries
...@@ -266,6 +274,12 @@ libcapnp_rpc_la_SOURCES= \ ...@@ -266,6 +274,12 @@ libcapnp_rpc_la_SOURCES= \
src/capnp/persistent.capnp.c++ \ src/capnp/persistent.capnp.c++ \
src/capnp/ez-rpc.c++ src/capnp/ez-rpc.c++
libcapnp_json_la_LIBADD = libcapnp.la libkj-async.la libkj.la $(PTHREAD_LIBS)
libcapnp_json_la_LDFLAGS = -release $(SO_VERSION) -no-undefined
libcapnp_json_la_SOURCES= \
src/capnp/compat/json.c++ \
src/capnp/compat/json.capnp.c++
libcapnpc_la_LIBADD = libcapnp.la libkj.la $(PTHREAD_LIBS) libcapnpc_la_LIBADD = libcapnp.la libkj.la $(PTHREAD_LIBS)
libcapnpc_la_LDFLAGS = -release $(SO_VERSION) -no-undefined libcapnpc_la_LDFLAGS = -release $(SO_VERSION) -no-undefined
libcapnpc_la_SOURCES= \ libcapnpc_la_SOURCES= \
...@@ -388,9 +402,16 @@ heavy_tests = \ ...@@ -388,9 +402,16 @@ heavy_tests = \
src/capnp/rpc-test.c++ \ src/capnp/rpc-test.c++ \
src/capnp/rpc-twoparty-test.c++ \ src/capnp/rpc-twoparty-test.c++ \
src/capnp/ez-rpc-test.c++ \ src/capnp/ez-rpc-test.c++ \
src/capnp/compat/json-test.c++ \
src/capnp/compiler/lexer-test.c++ \ src/capnp/compiler/lexer-test.c++ \
src/capnp/compiler/md5-test.c++ src/capnp/compiler/md5-test.c++
capnp_test_LDADD = libcapnpc.la libcapnp-rpc.la libcapnp.la libkj-async.la libkj-test.la libkj.la capnp_test_LDADD = libcapnpc.la \
libcapnp-rpc.la \
libcapnp-json.la \
libcapnp.la \
libkj-async.la \
libkj-test.la \
libkj.la
endif !LITE_MODE endif !LITE_MODE
......
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: Cap'n Proto JSON
Description: JSON encoder and decoder for Cap'n Proto objects
Version: @VERSION@
Libs: -L${libdir} -lcapnp-json
Requires: capnp = @VERSION@ kj-async = @VERSION@
Cflags: -I${includedir}
...@@ -134,6 +134,7 @@ endfunction() ...@@ -134,6 +134,7 @@ endfunction()
find_package(PkgConfig QUIET) find_package(PkgConfig QUIET)
pkg_check_modules(PKGCONFIG_CAPNP capnp) pkg_check_modules(PKGCONFIG_CAPNP capnp)
pkg_check_modules(PKGCONFIG_CAPNP_RPC capnp-rpc QUIET) pkg_check_modules(PKGCONFIG_CAPNP_RPC capnp-rpc QUIET)
pkg_check_modules(PKGCONFIG_CAPNP_JSON capnp-json QUIET)
find_library(CAPNP_LIB_KJ kj find_library(CAPNP_LIB_KJ kj
HINTS "${PKGCONFIG_CAPNP_LIBDIR}" ${PKGCONFIG_CAPNP_LIBRARY_DIRS} HINTS "${PKGCONFIG_CAPNP_LIBDIR}" ${PKGCONFIG_CAPNP_LIBRARY_DIRS}
...@@ -147,12 +148,16 @@ find_library(CAPNP_LIB_CAPNP capnp ...@@ -147,12 +148,16 @@ find_library(CAPNP_LIB_CAPNP capnp
find_library(CAPNP_LIB_CAPNP-RPC capnp-rpc find_library(CAPNP_LIB_CAPNP-RPC capnp-rpc
HINTS "${PKGCONFIG_CAPNP_RPC_LIBDIR}" ${PKGCONFIG_CAPNP_RPC_LIBRARY_DIRS} HINTS "${PKGCONFIG_CAPNP_RPC_LIBDIR}" ${PKGCONFIG_CAPNP_RPC_LIBRARY_DIRS}
) )
mark_as_advanced(CAPNP_LIB_KJ CAPNP_LIB_KJ-ASYNC CAPNP_LIB_CAPNP CAPNP_LIB_CAPNP-RPC) find_library(CAPNP_LIB_CAPNP-JSON capnp-json
HINTS "${PKGCONFIG_CAPNP_JSON_LIBDIR}" ${PKGCONFIG_CAPNP_JSON_LIBRARY_DIRS}
)
mark_as_advanced(CAPNP_LIB_KJ CAPNP_LIB_KJ-ASYNC CAPNP_LIB_CAPNP CAPNP_LIB_CAPNP-RPC CAPNP_LIB_CAPNP-JSON)
set(CAPNP_LIBRARIES_LITE set(CAPNP_LIBRARIES_LITE
${CAPNP_LIB_CAPNP} ${CAPNP_LIB_CAPNP}
${CAPNP_LIB_KJ} ${CAPNP_LIB_KJ}
) )
set(CAPNP_LIBRARIES set(CAPNP_LIBRARIES
${CAPNP_LIB_CAPNP-JSON}
${CAPNP_LIB_CAPNP-RPC} ${CAPNP_LIB_CAPNP-RPC}
${CAPNP_LIB_CAPNP} ${CAPNP_LIB_CAPNP}
${CAPNP_LIB_KJ-ASYNC} ${CAPNP_LIB_KJ-ASYNC}
......
...@@ -101,5 +101,5 @@ AC_SUBST([STDLIB_FLAG]) ...@@ -101,5 +101,5 @@ AC_SUBST([STDLIB_FLAG])
LIBS="$PTHREAD_LIBS $LIBS" LIBS="$PTHREAD_LIBS $LIBS"
CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS" CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS"
AC_CONFIG_FILES([Makefile capnp.pc capnp-rpc.pc kj.pc kj-async.pc]) AC_CONFIG_FILES([Makefile capnp.pc capnp-rpc.pc capnp-json.pc kj.pc kj-async.pc])
AC_OUTPUT AC_OUTPUT
...@@ -7,4 +7,5 @@ export PATH=$PWD/bin:$PWD:$PATH ...@@ -7,4 +7,5 @@ export PATH=$PWD/bin:$PWD:$PATH
capnp compile -Isrc --no-standard-import --src-prefix=src -oc++:src \ capnp compile -Isrc --no-standard-import --src-prefix=src -oc++:src \
src/capnp/c++.capnp src/capnp/schema.capnp \ src/capnp/c++.capnp src/capnp/schema.capnp \
src/capnp/compiler/lexer.capnp src/capnp/compiler/grammar.capnp \ src/capnp/compiler/lexer.capnp src/capnp/compiler/grammar.capnp \
src/capnp/rpc.capnp src/capnp/rpc-twoparty.capnp src/capnp/persistent.capnp src/capnp/rpc.capnp src/capnp/rpc-twoparty.capnp src/capnp/persistent.capnp \
src/capnp/compat/json.capnp
...@@ -94,6 +94,26 @@ if(NOT CAPNP_LITE) ...@@ -94,6 +94,26 @@ if(NOT CAPNP_LITE)
install(FILES ${capnp-rpc_headers} ${capnp-rpc_schemas} DESTINATION "${INCLUDE_INSTALL_DIR}/capnp") install(FILES ${capnp-rpc_headers} ${capnp-rpc_schemas} DESTINATION "${INCLUDE_INSTALL_DIR}/capnp")
endif() endif()
# capnp-json ========================================================================
set(capnp-json_sources
compat/json.c++
compat/json.capnp.c++
)
set(capnp-json_headers
compat/json.h
compat/json.capnp.h
)
set(capnp-json_schemas
compat/json.capnp
)
if(NOT CAPNP_LITE)
add_library(capnp-json ${capnp-json_sources})
target_link_libraries(capnp-json capnp kj-async kj)
install(TARGETS capnp-json ARCHIVE DESTINATION "${LIB_INSTALL_DIR}")
install(FILES ${capnp-json_headers} ${capnp-json_schemas} DESTINATION "${INCLUDE_INSTALL_DIR}/capnp/compat")
endif()
# Tools/Compilers ============================================================== # Tools/Compilers ==============================================================
set(capnpc_sources set(capnpc_sources
...@@ -185,7 +205,7 @@ if(BUILD_TESTING) ...@@ -185,7 +205,7 @@ if(BUILD_TESTING)
if(CAPNP_LITE) if(CAPNP_LITE)
set(test_libraries capnp kj-test kj) set(test_libraries capnp kj-test kj)
else() else()
set(test_libraries capnp-rpc capnp capnpc kj-async kj-test kj) set(test_libraries capnp-json capnp-rpc capnp capnpc kj-async kj-test kj)
endif() endif()
add_executable(capnp-tests add_executable(capnp-tests
...@@ -228,6 +248,7 @@ if(BUILD_TESTING) ...@@ -228,6 +248,7 @@ if(BUILD_TESTING)
compiler/lexer-test.c++ compiler/lexer-test.c++
compiler/md5-test.c++ compiler/md5-test.c++
test-util.c++ test-util.c++
compat/json-test.c++
${test_capnp_cpp_files} ${test_capnp_cpp_files}
${test_capnp_h_files} ${test_capnp_h_files}
) )
......
...@@ -37,7 +37,8 @@ case "$INPUT" in ...@@ -37,7 +37,8 @@ case "$INPUT" in
*capnp/rpc-twoparty.capnp | \ *capnp/rpc-twoparty.capnp | \
*capnp/persistent.capnp | \ *capnp/persistent.capnp | \
*capnp/compiler/lexer.capnp | \ *capnp/compiler/lexer.capnp | \
*capnp/compiler/grammar.capnp ) *capnp/compiler/grammar.capnp | \
*capnp/compat/json.capnp )
exit 0 exit 0
;; ;;
esac esac
......
// Generated by Cap'n Proto compiler, DO NOT EDIT
// source: json.capnp
#include "json.capnp.h"
namespace capnp {
namespace schemas {
static const ::capnp::_::AlignedData<136> b_8825ffaa852cda72 = {
{ 0, 0, 0, 0, 5, 0, 6, 0,
114, 218, 44, 133, 170, 255, 37, 136,
11, 0, 0, 0, 1, 0, 2, 0,
52, 94, 58, 164, 151, 146, 249, 142,
1, 0, 7, 0, 0, 0, 7, 0,
0, 0, 0, 0, 0, 0, 0, 0,
21, 0, 0, 0, 170, 0, 0, 0,
29, 0, 0, 0, 39, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
49, 0, 0, 0, 143, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
106, 115, 111, 110, 46, 99, 97, 112,
110, 112, 58, 74, 115, 111, 110, 86,
97, 108, 117, 101, 0, 0, 0, 0,
8, 0, 0, 0, 1, 0, 1, 0,
204, 55, 169, 83, 216, 85, 120, 194,
9, 0, 0, 0, 50, 0, 0, 0,
96, 187, 212, 61, 21, 132, 191, 155,
5, 0, 0, 0, 42, 0, 0, 0,
70, 105, 101, 108, 100, 0, 0, 0,
67, 97, 108, 108, 0, 0, 0, 0,
28, 0, 0, 0, 3, 0, 4, 0,
0, 0, 255, 255, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
181, 0, 0, 0, 42, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
176, 0, 0, 0, 3, 0, 1, 0,
188, 0, 0, 0, 2, 0, 1, 0,
1, 0, 254, 255, 16, 0, 0, 0,
0, 0, 1, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
185, 0, 0, 0, 66, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
180, 0, 0, 0, 3, 0, 1, 0,
192, 0, 0, 0, 2, 0, 1, 0,
2, 0, 253, 255, 1, 0, 0, 0,
0, 0, 1, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
189, 0, 0, 0, 58, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
184, 0, 0, 0, 3, 0, 1, 0,
196, 0, 0, 0, 2, 0, 1, 0,
3, 0, 252, 255, 0, 0, 0, 0,
0, 0, 1, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
193, 0, 0, 0, 58, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
188, 0, 0, 0, 3, 0, 1, 0,
200, 0, 0, 0, 2, 0, 1, 0,
4, 0, 251, 255, 0, 0, 0, 0,
0, 0, 1, 0, 4, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
197, 0, 0, 0, 50, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
192, 0, 0, 0, 3, 0, 1, 0,
220, 0, 0, 0, 2, 0, 1, 0,
5, 0, 250, 255, 0, 0, 0, 0,
0, 0, 1, 0, 5, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
217, 0, 0, 0, 58, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
212, 0, 0, 0, 3, 0, 1, 0,
240, 0, 0, 0, 2, 0, 1, 0,
6, 0, 249, 255, 0, 0, 0, 0,
0, 0, 1, 0, 6, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
237, 0, 0, 0, 42, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
232, 0, 0, 0, 3, 0, 1, 0,
244, 0, 0, 0, 2, 0, 1, 0,
110, 117, 108, 108, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
98, 111, 111, 108, 101, 97, 110, 0,
1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
110, 117, 109, 98, 101, 114, 0, 0,
11, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
11, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
115, 116, 114, 105, 110, 103, 0, 0,
12, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
12, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
97, 114, 114, 97, 121, 0, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0, 1, 0,
16, 0, 0, 0, 0, 0, 0, 0,
114, 218, 44, 133, 170, 255, 37, 136,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
111, 98, 106, 101, 99, 116, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0, 1, 0,
16, 0, 0, 0, 0, 0, 0, 0,
204, 55, 169, 83, 216, 85, 120, 194,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
99, 97, 108, 108, 0, 0, 0, 0,
16, 0, 0, 0, 0, 0, 0, 0,
96, 187, 212, 61, 21, 132, 191, 155,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
16, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, }
};
::capnp::word const* const bp_8825ffaa852cda72 = b_8825ffaa852cda72.words;
#if !CAPNP_LITE
static const ::capnp::_::RawSchema* const d_8825ffaa852cda72[] = {
&s_8825ffaa852cda72,
&s_9bbf84153dd4bb60,
&s_c27855d853a937cc,
};
static const uint16_t m_8825ffaa852cda72[] = {4, 1, 6, 0, 2, 5, 3};
static const uint16_t i_8825ffaa852cda72[] = {0, 1, 2, 3, 4, 5, 6};
const ::capnp::_::RawSchema s_8825ffaa852cda72 = {
0x8825ffaa852cda72, b_8825ffaa852cda72.words, 136, d_8825ffaa852cda72, m_8825ffaa852cda72,
3, 7, i_8825ffaa852cda72, nullptr, nullptr, { &s_8825ffaa852cda72, nullptr, nullptr, 0, 0, nullptr }
};
#endif // !CAPNP_LITE
static const ::capnp::_::AlignedData<48> b_c27855d853a937cc = {
{ 0, 0, 0, 0, 5, 0, 6, 0,
204, 55, 169, 83, 216, 85, 120, 194,
21, 0, 0, 0, 1, 0, 0, 0,
114, 218, 44, 133, 170, 255, 37, 136,
2, 0, 7, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
21, 0, 0, 0, 218, 0, 0, 0,
33, 0, 0, 0, 7, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
29, 0, 0, 0, 119, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
106, 115, 111, 110, 46, 99, 97, 112,
110, 112, 58, 74, 115, 111, 110, 86,
97, 108, 117, 101, 46, 70, 105, 101,
108, 100, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 1, 0,
8, 0, 0, 0, 3, 0, 4, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
41, 0, 0, 0, 42, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
36, 0, 0, 0, 3, 0, 1, 0,
48, 0, 0, 0, 2, 0, 1, 0,
1, 0, 0, 0, 1, 0, 0, 0,
0, 0, 1, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
45, 0, 0, 0, 50, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
40, 0, 0, 0, 3, 0, 1, 0,
52, 0, 0, 0, 2, 0, 1, 0,
110, 97, 109, 101, 0, 0, 0, 0,
12, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
12, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
118, 97, 108, 117, 101, 0, 0, 0,
16, 0, 0, 0, 0, 0, 0, 0,
114, 218, 44, 133, 170, 255, 37, 136,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
16, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, }
};
::capnp::word const* const bp_c27855d853a937cc = b_c27855d853a937cc.words;
#if !CAPNP_LITE
static const ::capnp::_::RawSchema* const d_c27855d853a937cc[] = {
&s_8825ffaa852cda72,
};
static const uint16_t m_c27855d853a937cc[] = {0, 1};
static const uint16_t i_c27855d853a937cc[] = {0, 1};
const ::capnp::_::RawSchema s_c27855d853a937cc = {
0xc27855d853a937cc, b_c27855d853a937cc.words, 48, d_c27855d853a937cc, m_c27855d853a937cc,
1, 2, i_c27855d853a937cc, nullptr, nullptr, { &s_c27855d853a937cc, nullptr, nullptr, 0, 0, nullptr }
};
#endif // !CAPNP_LITE
static const ::capnp::_::AlignedData<53> b_9bbf84153dd4bb60 = {
{ 0, 0, 0, 0, 5, 0, 6, 0,
96, 187, 212, 61, 21, 132, 191, 155,
21, 0, 0, 0, 1, 0, 0, 0,
114, 218, 44, 133, 170, 255, 37, 136,
2, 0, 7, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
21, 0, 0, 0, 210, 0, 0, 0,
33, 0, 0, 0, 7, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
29, 0, 0, 0, 119, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
106, 115, 111, 110, 46, 99, 97, 112,
110, 112, 58, 74, 115, 111, 110, 86,
97, 108, 117, 101, 46, 67, 97, 108,
108, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 1, 0,
8, 0, 0, 0, 3, 0, 4, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
41, 0, 0, 0, 74, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
40, 0, 0, 0, 3, 0, 1, 0,
52, 0, 0, 0, 2, 0, 1, 0,
1, 0, 0, 0, 1, 0, 0, 0,
0, 0, 1, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
49, 0, 0, 0, 58, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
44, 0, 0, 0, 3, 0, 1, 0,
72, 0, 0, 0, 2, 0, 1, 0,
102, 117, 110, 99, 116, 105, 111, 110,
0, 0, 0, 0, 0, 0, 0, 0,
12, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
12, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
112, 97, 114, 97, 109, 115, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0, 1, 0,
16, 0, 0, 0, 0, 0, 0, 0,
114, 218, 44, 133, 170, 255, 37, 136,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
14, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, }
};
::capnp::word const* const bp_9bbf84153dd4bb60 = b_9bbf84153dd4bb60.words;
#if !CAPNP_LITE
static const ::capnp::_::RawSchema* const d_9bbf84153dd4bb60[] = {
&s_8825ffaa852cda72,
};
static const uint16_t m_9bbf84153dd4bb60[] = {0, 1};
static const uint16_t i_9bbf84153dd4bb60[] = {0, 1};
const ::capnp::_::RawSchema s_9bbf84153dd4bb60 = {
0x9bbf84153dd4bb60, b_9bbf84153dd4bb60.words, 53, d_9bbf84153dd4bb60, m_9bbf84153dd4bb60,
1, 2, i_9bbf84153dd4bb60, nullptr, nullptr, { &s_9bbf84153dd4bb60, nullptr, nullptr, 0, 0, nullptr }
};
#endif // !CAPNP_LITE
} // namespace schemas
} // namespace capnp
// =======================================================================================
namespace capnp {
// JsonValue
#ifndef _MSC_VER
constexpr uint16_t JsonValue::_capnpPrivate::dataWordSize;
constexpr uint16_t JsonValue::_capnpPrivate::pointerCount;
#endif
#if !CAPNP_LITE
constexpr ::capnp::Kind JsonValue::_capnpPrivate::kind;
constexpr ::capnp::_::RawSchema const* JsonValue::_capnpPrivate::schema;
constexpr ::capnp::_::RawBrandedSchema const* JsonValue::_capnpPrivate::brand;
#endif // !CAPNP_LITE
// JsonValue::Field
#ifndef _MSC_VER
constexpr uint16_t JsonValue::Field::_capnpPrivate::dataWordSize;
constexpr uint16_t JsonValue::Field::_capnpPrivate::pointerCount;
#endif
#if !CAPNP_LITE
constexpr ::capnp::Kind JsonValue::Field::_capnpPrivate::kind;
constexpr ::capnp::_::RawSchema const* JsonValue::Field::_capnpPrivate::schema;
constexpr ::capnp::_::RawBrandedSchema const* JsonValue::Field::_capnpPrivate::brand;
#endif // !CAPNP_LITE
// JsonValue::Call
#ifndef _MSC_VER
constexpr uint16_t JsonValue::Call::_capnpPrivate::dataWordSize;
constexpr uint16_t JsonValue::Call::_capnpPrivate::pointerCount;
#endif
#if !CAPNP_LITE
constexpr ::capnp::Kind JsonValue::Call::_capnpPrivate::kind;
constexpr ::capnp::_::RawSchema const* JsonValue::Call::_capnpPrivate::schema;
constexpr ::capnp::_::RawBrandedSchema const* JsonValue::Call::_capnpPrivate::brand;
#endif // !CAPNP_LITE
} // namespace
// Generated by Cap'n Proto compiler, DO NOT EDIT
// source: json.capnp
#ifndef CAPNP_INCLUDED_8ef99297a43a5e34_
#define CAPNP_INCLUDED_8ef99297a43a5e34_
#include <capnp/generated-header-support.h>
#if CAPNP_VERSION != 6000
#error "Version mismatch between generated code and library headers. You must use the same version of the Cap'n Proto compiler and library."
#endif
namespace capnp {
namespace schemas {
CAPNP_DECLARE_SCHEMA(8825ffaa852cda72);
CAPNP_DECLARE_SCHEMA(c27855d853a937cc);
CAPNP_DECLARE_SCHEMA(9bbf84153dd4bb60);
} // namespace schemas
} // namespace capnp
namespace capnp {
struct JsonValue {
JsonValue() = delete;
class Reader;
class Builder;
class Pipeline;
enum Which: uint16_t {
NULL_,
BOOLEAN,
NUMBER,
STRING,
ARRAY,
OBJECT,
CALL,
};
struct Field;
struct Call;
struct _capnpPrivate {
CAPNP_DECLARE_STRUCT_HEADER(8825ffaa852cda72, 2, 1)
#if !CAPNP_LITE
static constexpr ::capnp::_::RawBrandedSchema const* brand = &schema->defaultBrand;
#endif // !CAPNP_LITE
};
};
struct JsonValue::Field {
Field() = delete;
class Reader;
class Builder;
class Pipeline;
struct _capnpPrivate {
CAPNP_DECLARE_STRUCT_HEADER(c27855d853a937cc, 0, 2)
#if !CAPNP_LITE
static constexpr ::capnp::_::RawBrandedSchema const* brand = &schema->defaultBrand;
#endif // !CAPNP_LITE
};
};
struct JsonValue::Call {
Call() = delete;
class Reader;
class Builder;
class Pipeline;
struct _capnpPrivate {
CAPNP_DECLARE_STRUCT_HEADER(9bbf84153dd4bb60, 0, 2)
#if !CAPNP_LITE
static constexpr ::capnp::_::RawBrandedSchema const* brand = &schema->defaultBrand;
#endif // !CAPNP_LITE
};
};
// =======================================================================================
class JsonValue::Reader {
public:
typedef JsonValue Reads;
Reader() = default;
inline explicit Reader(::capnp::_::StructReader base): _reader(base) {}
inline ::capnp::MessageSize totalSize() const {
return _reader.totalSize().asPublic();
}
#if !CAPNP_LITE
inline ::kj::StringTree toString() const {
return ::capnp::_::structString(_reader, *_capnpPrivate::brand);
}
#endif // !CAPNP_LITE
inline Which which() const;
inline bool isNull() const;
inline ::capnp::Void getNull() const;
inline bool isBoolean() const;
inline bool getBoolean() const;
inline bool isNumber() const;
inline double getNumber() const;
inline bool isString() const;
inline bool hasString() const;
inline ::capnp::Text::Reader getString() const;
inline bool isArray() const;
inline bool hasArray() const;
inline ::capnp::List< ::capnp::JsonValue>::Reader getArray() const;
inline bool isObject() const;
inline bool hasObject() const;
inline ::capnp::List< ::capnp::JsonValue::Field>::Reader getObject() const;
inline bool isCall() const;
inline bool hasCall() const;
inline ::capnp::JsonValue::Call::Reader getCall() const;
private:
::capnp::_::StructReader _reader;
template <typename, ::capnp::Kind>
friend struct ::capnp::ToDynamic_;
template <typename, ::capnp::Kind>
friend struct ::capnp::_::PointerHelpers;
template <typename, ::capnp::Kind>
friend struct ::capnp::List;
friend class ::capnp::MessageBuilder;
friend class ::capnp::Orphanage;
};
class JsonValue::Builder {
public:
typedef JsonValue Builds;
Builder() = delete; // Deleted to discourage incorrect usage.
// You can explicitly initialize to nullptr instead.
inline Builder(decltype(nullptr)) {}
inline explicit Builder(::capnp::_::StructBuilder base): _builder(base) {}
inline operator Reader() const { return Reader(_builder.asReader()); }
inline Reader asReader() const { return *this; }
inline ::capnp::MessageSize totalSize() const { return asReader().totalSize(); }
#if !CAPNP_LITE
inline ::kj::StringTree toString() const { return asReader().toString(); }
#endif // !CAPNP_LITE
inline Which which();
inline bool isNull();
inline ::capnp::Void getNull();
inline void setNull( ::capnp::Void value = ::capnp::VOID);
inline bool isBoolean();
inline bool getBoolean();
inline void setBoolean(bool value);
inline bool isNumber();
inline double getNumber();
inline void setNumber(double value);
inline bool isString();
inline bool hasString();
inline ::capnp::Text::Builder getString();
inline void setString( ::capnp::Text::Reader value);
inline ::capnp::Text::Builder initString(unsigned int size);
inline void adoptString(::capnp::Orphan< ::capnp::Text>&& value);
inline ::capnp::Orphan< ::capnp::Text> disownString();
inline bool isArray();
inline bool hasArray();
inline ::capnp::List< ::capnp::JsonValue>::Builder getArray();
inline void setArray( ::capnp::List< ::capnp::JsonValue>::Reader value);
inline ::capnp::List< ::capnp::JsonValue>::Builder initArray(unsigned int size);
inline void adoptArray(::capnp::Orphan< ::capnp::List< ::capnp::JsonValue>>&& value);
inline ::capnp::Orphan< ::capnp::List< ::capnp::JsonValue>> disownArray();
inline bool isObject();
inline bool hasObject();
inline ::capnp::List< ::capnp::JsonValue::Field>::Builder getObject();
inline void setObject( ::capnp::List< ::capnp::JsonValue::Field>::Reader value);
inline ::capnp::List< ::capnp::JsonValue::Field>::Builder initObject(unsigned int size);
inline void adoptObject(::capnp::Orphan< ::capnp::List< ::capnp::JsonValue::Field>>&& value);
inline ::capnp::Orphan< ::capnp::List< ::capnp::JsonValue::Field>> disownObject();
inline bool isCall();
inline bool hasCall();
inline ::capnp::JsonValue::Call::Builder getCall();
inline void setCall( ::capnp::JsonValue::Call::Reader value);
inline ::capnp::JsonValue::Call::Builder initCall();
inline void adoptCall(::capnp::Orphan< ::capnp::JsonValue::Call>&& value);
inline ::capnp::Orphan< ::capnp::JsonValue::Call> disownCall();
private:
::capnp::_::StructBuilder _builder;
template <typename, ::capnp::Kind>
friend struct ::capnp::ToDynamic_;
friend class ::capnp::Orphanage;
template <typename, ::capnp::Kind>
friend struct ::capnp::_::PointerHelpers;
};
#if !CAPNP_LITE
class JsonValue::Pipeline {
public:
typedef JsonValue Pipelines;
inline Pipeline(decltype(nullptr)): _typeless(nullptr) {}
inline explicit Pipeline(::capnp::AnyPointer::Pipeline&& typeless)
: _typeless(kj::mv(typeless)) {}
private:
::capnp::AnyPointer::Pipeline _typeless;
friend class ::capnp::PipelineHook;
template <typename, ::capnp::Kind>
friend struct ::capnp::ToDynamic_;
};
#endif // !CAPNP_LITE
class JsonValue::Field::Reader {
public:
typedef Field Reads;
Reader() = default;
inline explicit Reader(::capnp::_::StructReader base): _reader(base) {}
inline ::capnp::MessageSize totalSize() const {
return _reader.totalSize().asPublic();
}
#if !CAPNP_LITE
inline ::kj::StringTree toString() const {
return ::capnp::_::structString(_reader, *_capnpPrivate::brand);
}
#endif // !CAPNP_LITE
inline bool hasName() const;
inline ::capnp::Text::Reader getName() const;
inline bool hasValue() const;
inline ::capnp::JsonValue::Reader getValue() const;
private:
::capnp::_::StructReader _reader;
template <typename, ::capnp::Kind>
friend struct ::capnp::ToDynamic_;
template <typename, ::capnp::Kind>
friend struct ::capnp::_::PointerHelpers;
template <typename, ::capnp::Kind>
friend struct ::capnp::List;
friend class ::capnp::MessageBuilder;
friend class ::capnp::Orphanage;
};
class JsonValue::Field::Builder {
public:
typedef Field Builds;
Builder() = delete; // Deleted to discourage incorrect usage.
// You can explicitly initialize to nullptr instead.
inline Builder(decltype(nullptr)) {}
inline explicit Builder(::capnp::_::StructBuilder base): _builder(base) {}
inline operator Reader() const { return Reader(_builder.asReader()); }
inline Reader asReader() const { return *this; }
inline ::capnp::MessageSize totalSize() const { return asReader().totalSize(); }
#if !CAPNP_LITE
inline ::kj::StringTree toString() const { return asReader().toString(); }
#endif // !CAPNP_LITE
inline bool hasName();
inline ::capnp::Text::Builder getName();
inline void setName( ::capnp::Text::Reader value);
inline ::capnp::Text::Builder initName(unsigned int size);
inline void adoptName(::capnp::Orphan< ::capnp::Text>&& value);
inline ::capnp::Orphan< ::capnp::Text> disownName();
inline bool hasValue();
inline ::capnp::JsonValue::Builder getValue();
inline void setValue( ::capnp::JsonValue::Reader value);
inline ::capnp::JsonValue::Builder initValue();
inline void adoptValue(::capnp::Orphan< ::capnp::JsonValue>&& value);
inline ::capnp::Orphan< ::capnp::JsonValue> disownValue();
private:
::capnp::_::StructBuilder _builder;
template <typename, ::capnp::Kind>
friend struct ::capnp::ToDynamic_;
friend class ::capnp::Orphanage;
template <typename, ::capnp::Kind>
friend struct ::capnp::_::PointerHelpers;
};
#if !CAPNP_LITE
class JsonValue::Field::Pipeline {
public:
typedef Field Pipelines;
inline Pipeline(decltype(nullptr)): _typeless(nullptr) {}
inline explicit Pipeline(::capnp::AnyPointer::Pipeline&& typeless)
: _typeless(kj::mv(typeless)) {}
inline ::capnp::JsonValue::Pipeline getValue();
private:
::capnp::AnyPointer::Pipeline _typeless;
friend class ::capnp::PipelineHook;
template <typename, ::capnp::Kind>
friend struct ::capnp::ToDynamic_;
};
#endif // !CAPNP_LITE
class JsonValue::Call::Reader {
public:
typedef Call Reads;
Reader() = default;
inline explicit Reader(::capnp::_::StructReader base): _reader(base) {}
inline ::capnp::MessageSize totalSize() const {
return _reader.totalSize().asPublic();
}
#if !CAPNP_LITE
inline ::kj::StringTree toString() const {
return ::capnp::_::structString(_reader, *_capnpPrivate::brand);
}
#endif // !CAPNP_LITE
inline bool hasFunction() const;
inline ::capnp::Text::Reader getFunction() const;
inline bool hasParams() const;
inline ::capnp::List< ::capnp::JsonValue>::Reader getParams() const;
private:
::capnp::_::StructReader _reader;
template <typename, ::capnp::Kind>
friend struct ::capnp::ToDynamic_;
template <typename, ::capnp::Kind>
friend struct ::capnp::_::PointerHelpers;
template <typename, ::capnp::Kind>
friend struct ::capnp::List;
friend class ::capnp::MessageBuilder;
friend class ::capnp::Orphanage;
};
class JsonValue::Call::Builder {
public:
typedef Call Builds;
Builder() = delete; // Deleted to discourage incorrect usage.
// You can explicitly initialize to nullptr instead.
inline Builder(decltype(nullptr)) {}
inline explicit Builder(::capnp::_::StructBuilder base): _builder(base) {}
inline operator Reader() const { return Reader(_builder.asReader()); }
inline Reader asReader() const { return *this; }
inline ::capnp::MessageSize totalSize() const { return asReader().totalSize(); }
#if !CAPNP_LITE
inline ::kj::StringTree toString() const { return asReader().toString(); }
#endif // !CAPNP_LITE
inline bool hasFunction();
inline ::capnp::Text::Builder getFunction();
inline void setFunction( ::capnp::Text::Reader value);
inline ::capnp::Text::Builder initFunction(unsigned int size);
inline void adoptFunction(::capnp::Orphan< ::capnp::Text>&& value);
inline ::capnp::Orphan< ::capnp::Text> disownFunction();
inline bool hasParams();
inline ::capnp::List< ::capnp::JsonValue>::Builder getParams();
inline void setParams( ::capnp::List< ::capnp::JsonValue>::Reader value);
inline ::capnp::List< ::capnp::JsonValue>::Builder initParams(unsigned int size);
inline void adoptParams(::capnp::Orphan< ::capnp::List< ::capnp::JsonValue>>&& value);
inline ::capnp::Orphan< ::capnp::List< ::capnp::JsonValue>> disownParams();
private:
::capnp::_::StructBuilder _builder;
template <typename, ::capnp::Kind>
friend struct ::capnp::ToDynamic_;
friend class ::capnp::Orphanage;
template <typename, ::capnp::Kind>
friend struct ::capnp::_::PointerHelpers;
};
#if !CAPNP_LITE
class JsonValue::Call::Pipeline {
public:
typedef Call Pipelines;
inline Pipeline(decltype(nullptr)): _typeless(nullptr) {}
inline explicit Pipeline(::capnp::AnyPointer::Pipeline&& typeless)
: _typeless(kj::mv(typeless)) {}
private:
::capnp::AnyPointer::Pipeline _typeless;
friend class ::capnp::PipelineHook;
template <typename, ::capnp::Kind>
friend struct ::capnp::ToDynamic_;
};
#endif // !CAPNP_LITE
// =======================================================================================
inline ::capnp::JsonValue::Which JsonValue::Reader::which() const {
return _reader.getDataField<Which>(0 * ::capnp::ELEMENTS);
}
inline ::capnp::JsonValue::Which JsonValue::Builder::which() {
return _builder.getDataField<Which>(0 * ::capnp::ELEMENTS);
}
inline bool JsonValue::Reader::isNull() const {
return which() == JsonValue::NULL_;
}
inline bool JsonValue::Builder::isNull() {
return which() == JsonValue::NULL_;
}
inline ::capnp::Void JsonValue::Reader::getNull() const {
KJ_IREQUIRE((which() == JsonValue::NULL_),
"Must check which() before get()ing a union member.");
return _reader.getDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS);
}
inline ::capnp::Void JsonValue::Builder::getNull() {
KJ_IREQUIRE((which() == JsonValue::NULL_),
"Must check which() before get()ing a union member.");
return _builder.getDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS);
}
inline void JsonValue::Builder::setNull( ::capnp::Void value) {
_builder.setDataField<JsonValue::Which>(
0 * ::capnp::ELEMENTS, JsonValue::NULL_);
_builder.setDataField< ::capnp::Void>(
0 * ::capnp::ELEMENTS, value);
}
inline bool JsonValue::Reader::isBoolean() const {
return which() == JsonValue::BOOLEAN;
}
inline bool JsonValue::Builder::isBoolean() {
return which() == JsonValue::BOOLEAN;
}
inline bool JsonValue::Reader::getBoolean() const {
KJ_IREQUIRE((which() == JsonValue::BOOLEAN),
"Must check which() before get()ing a union member.");
return _reader.getDataField<bool>(
16 * ::capnp::ELEMENTS);
}
inline bool JsonValue::Builder::getBoolean() {
KJ_IREQUIRE((which() == JsonValue::BOOLEAN),
"Must check which() before get()ing a union member.");
return _builder.getDataField<bool>(
16 * ::capnp::ELEMENTS);
}
inline void JsonValue::Builder::setBoolean(bool value) {
_builder.setDataField<JsonValue::Which>(
0 * ::capnp::ELEMENTS, JsonValue::BOOLEAN);
_builder.setDataField<bool>(
16 * ::capnp::ELEMENTS, value);
}
inline bool JsonValue::Reader::isNumber() const {
return which() == JsonValue::NUMBER;
}
inline bool JsonValue::Builder::isNumber() {
return which() == JsonValue::NUMBER;
}
inline double JsonValue::Reader::getNumber() const {
KJ_IREQUIRE((which() == JsonValue::NUMBER),
"Must check which() before get()ing a union member.");
return _reader.getDataField<double>(
1 * ::capnp::ELEMENTS);
}
inline double JsonValue::Builder::getNumber() {
KJ_IREQUIRE((which() == JsonValue::NUMBER),
"Must check which() before get()ing a union member.");
return _builder.getDataField<double>(
1 * ::capnp::ELEMENTS);
}
inline void JsonValue::Builder::setNumber(double value) {
_builder.setDataField<JsonValue::Which>(
0 * ::capnp::ELEMENTS, JsonValue::NUMBER);
_builder.setDataField<double>(
1 * ::capnp::ELEMENTS, value);
}
inline bool JsonValue::Reader::isString() const {
return which() == JsonValue::STRING;
}
inline bool JsonValue::Builder::isString() {
return which() == JsonValue::STRING;
}
inline bool JsonValue::Reader::hasString() const {
if (which() != JsonValue::STRING) return false;
return !_reader.getPointerField(0 * ::capnp::POINTERS).isNull();
}
inline bool JsonValue::Builder::hasString() {
if (which() != JsonValue::STRING) return false;
return !_builder.getPointerField(0 * ::capnp::POINTERS).isNull();
}
inline ::capnp::Text::Reader JsonValue::Reader::getString() const {
KJ_IREQUIRE((which() == JsonValue::STRING),
"Must check which() before get()ing a union member.");
return ::capnp::_::PointerHelpers< ::capnp::Text>::get(
_reader.getPointerField(0 * ::capnp::POINTERS));
}
inline ::capnp::Text::Builder JsonValue::Builder::getString() {
KJ_IREQUIRE((which() == JsonValue::STRING),
"Must check which() before get()ing a union member.");
return ::capnp::_::PointerHelpers< ::capnp::Text>::get(
_builder.getPointerField(0 * ::capnp::POINTERS));
}
inline void JsonValue::Builder::setString( ::capnp::Text::Reader value) {
_builder.setDataField<JsonValue::Which>(
0 * ::capnp::ELEMENTS, JsonValue::STRING);
::capnp::_::PointerHelpers< ::capnp::Text>::set(
_builder.getPointerField(0 * ::capnp::POINTERS), value);
}
inline ::capnp::Text::Builder JsonValue::Builder::initString(unsigned int size) {
_builder.setDataField<JsonValue::Which>(
0 * ::capnp::ELEMENTS, JsonValue::STRING);
return ::capnp::_::PointerHelpers< ::capnp::Text>::init(
_builder.getPointerField(0 * ::capnp::POINTERS), size);
}
inline void JsonValue::Builder::adoptString(
::capnp::Orphan< ::capnp::Text>&& value) {
_builder.setDataField<JsonValue::Which>(
0 * ::capnp::ELEMENTS, JsonValue::STRING);
::capnp::_::PointerHelpers< ::capnp::Text>::adopt(
_builder.getPointerField(0 * ::capnp::POINTERS), kj::mv(value));
}
inline ::capnp::Orphan< ::capnp::Text> JsonValue::Builder::disownString() {
KJ_IREQUIRE((which() == JsonValue::STRING),
"Must check which() before get()ing a union member.");
return ::capnp::_::PointerHelpers< ::capnp::Text>::disown(
_builder.getPointerField(0 * ::capnp::POINTERS));
}
inline bool JsonValue::Reader::isArray() const {
return which() == JsonValue::ARRAY;
}
inline bool JsonValue::Builder::isArray() {
return which() == JsonValue::ARRAY;
}
inline bool JsonValue::Reader::hasArray() const {
if (which() != JsonValue::ARRAY) return false;
return !_reader.getPointerField(0 * ::capnp::POINTERS).isNull();
}
inline bool JsonValue::Builder::hasArray() {
if (which() != JsonValue::ARRAY) return false;
return !_builder.getPointerField(0 * ::capnp::POINTERS).isNull();
}
inline ::capnp::List< ::capnp::JsonValue>::Reader JsonValue::Reader::getArray() const {
KJ_IREQUIRE((which() == JsonValue::ARRAY),
"Must check which() before get()ing a union member.");
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue>>::get(
_reader.getPointerField(0 * ::capnp::POINTERS));
}
inline ::capnp::List< ::capnp::JsonValue>::Builder JsonValue::Builder::getArray() {
KJ_IREQUIRE((which() == JsonValue::ARRAY),
"Must check which() before get()ing a union member.");
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue>>::get(
_builder.getPointerField(0 * ::capnp::POINTERS));
}
inline void JsonValue::Builder::setArray( ::capnp::List< ::capnp::JsonValue>::Reader value) {
_builder.setDataField<JsonValue::Which>(
0 * ::capnp::ELEMENTS, JsonValue::ARRAY);
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue>>::set(
_builder.getPointerField(0 * ::capnp::POINTERS), value);
}
inline ::capnp::List< ::capnp::JsonValue>::Builder JsonValue::Builder::initArray(unsigned int size) {
_builder.setDataField<JsonValue::Which>(
0 * ::capnp::ELEMENTS, JsonValue::ARRAY);
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue>>::init(
_builder.getPointerField(0 * ::capnp::POINTERS), size);
}
inline void JsonValue::Builder::adoptArray(
::capnp::Orphan< ::capnp::List< ::capnp::JsonValue>>&& value) {
_builder.setDataField<JsonValue::Which>(
0 * ::capnp::ELEMENTS, JsonValue::ARRAY);
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue>>::adopt(
_builder.getPointerField(0 * ::capnp::POINTERS), kj::mv(value));
}
inline ::capnp::Orphan< ::capnp::List< ::capnp::JsonValue>> JsonValue::Builder::disownArray() {
KJ_IREQUIRE((which() == JsonValue::ARRAY),
"Must check which() before get()ing a union member.");
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue>>::disown(
_builder.getPointerField(0 * ::capnp::POINTERS));
}
inline bool JsonValue::Reader::isObject() const {
return which() == JsonValue::OBJECT;
}
inline bool JsonValue::Builder::isObject() {
return which() == JsonValue::OBJECT;
}
inline bool JsonValue::Reader::hasObject() const {
if (which() != JsonValue::OBJECT) return false;
return !_reader.getPointerField(0 * ::capnp::POINTERS).isNull();
}
inline bool JsonValue::Builder::hasObject() {
if (which() != JsonValue::OBJECT) return false;
return !_builder.getPointerField(0 * ::capnp::POINTERS).isNull();
}
inline ::capnp::List< ::capnp::JsonValue::Field>::Reader JsonValue::Reader::getObject() const {
KJ_IREQUIRE((which() == JsonValue::OBJECT),
"Must check which() before get()ing a union member.");
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue::Field>>::get(
_reader.getPointerField(0 * ::capnp::POINTERS));
}
inline ::capnp::List< ::capnp::JsonValue::Field>::Builder JsonValue::Builder::getObject() {
KJ_IREQUIRE((which() == JsonValue::OBJECT),
"Must check which() before get()ing a union member.");
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue::Field>>::get(
_builder.getPointerField(0 * ::capnp::POINTERS));
}
inline void JsonValue::Builder::setObject( ::capnp::List< ::capnp::JsonValue::Field>::Reader value) {
_builder.setDataField<JsonValue::Which>(
0 * ::capnp::ELEMENTS, JsonValue::OBJECT);
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue::Field>>::set(
_builder.getPointerField(0 * ::capnp::POINTERS), value);
}
inline ::capnp::List< ::capnp::JsonValue::Field>::Builder JsonValue::Builder::initObject(unsigned int size) {
_builder.setDataField<JsonValue::Which>(
0 * ::capnp::ELEMENTS, JsonValue::OBJECT);
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue::Field>>::init(
_builder.getPointerField(0 * ::capnp::POINTERS), size);
}
inline void JsonValue::Builder::adoptObject(
::capnp::Orphan< ::capnp::List< ::capnp::JsonValue::Field>>&& value) {
_builder.setDataField<JsonValue::Which>(
0 * ::capnp::ELEMENTS, JsonValue::OBJECT);
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue::Field>>::adopt(
_builder.getPointerField(0 * ::capnp::POINTERS), kj::mv(value));
}
inline ::capnp::Orphan< ::capnp::List< ::capnp::JsonValue::Field>> JsonValue::Builder::disownObject() {
KJ_IREQUIRE((which() == JsonValue::OBJECT),
"Must check which() before get()ing a union member.");
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue::Field>>::disown(
_builder.getPointerField(0 * ::capnp::POINTERS));
}
inline bool JsonValue::Reader::isCall() const {
return which() == JsonValue::CALL;
}
inline bool JsonValue::Builder::isCall() {
return which() == JsonValue::CALL;
}
inline bool JsonValue::Reader::hasCall() const {
if (which() != JsonValue::CALL) return false;
return !_reader.getPointerField(0 * ::capnp::POINTERS).isNull();
}
inline bool JsonValue::Builder::hasCall() {
if (which() != JsonValue::CALL) return false;
return !_builder.getPointerField(0 * ::capnp::POINTERS).isNull();
}
inline ::capnp::JsonValue::Call::Reader JsonValue::Reader::getCall() const {
KJ_IREQUIRE((which() == JsonValue::CALL),
"Must check which() before get()ing a union member.");
return ::capnp::_::PointerHelpers< ::capnp::JsonValue::Call>::get(
_reader.getPointerField(0 * ::capnp::POINTERS));
}
inline ::capnp::JsonValue::Call::Builder JsonValue::Builder::getCall() {
KJ_IREQUIRE((which() == JsonValue::CALL),
"Must check which() before get()ing a union member.");
return ::capnp::_::PointerHelpers< ::capnp::JsonValue::Call>::get(
_builder.getPointerField(0 * ::capnp::POINTERS));
}
inline void JsonValue::Builder::setCall( ::capnp::JsonValue::Call::Reader value) {
_builder.setDataField<JsonValue::Which>(
0 * ::capnp::ELEMENTS, JsonValue::CALL);
::capnp::_::PointerHelpers< ::capnp::JsonValue::Call>::set(
_builder.getPointerField(0 * ::capnp::POINTERS), value);
}
inline ::capnp::JsonValue::Call::Builder JsonValue::Builder::initCall() {
_builder.setDataField<JsonValue::Which>(
0 * ::capnp::ELEMENTS, JsonValue::CALL);
return ::capnp::_::PointerHelpers< ::capnp::JsonValue::Call>::init(
_builder.getPointerField(0 * ::capnp::POINTERS));
}
inline void JsonValue::Builder::adoptCall(
::capnp::Orphan< ::capnp::JsonValue::Call>&& value) {
_builder.setDataField<JsonValue::Which>(
0 * ::capnp::ELEMENTS, JsonValue::CALL);
::capnp::_::PointerHelpers< ::capnp::JsonValue::Call>::adopt(
_builder.getPointerField(0 * ::capnp::POINTERS), kj::mv(value));
}
inline ::capnp::Orphan< ::capnp::JsonValue::Call> JsonValue::Builder::disownCall() {
KJ_IREQUIRE((which() == JsonValue::CALL),
"Must check which() before get()ing a union member.");
return ::capnp::_::PointerHelpers< ::capnp::JsonValue::Call>::disown(
_builder.getPointerField(0 * ::capnp::POINTERS));
}
inline bool JsonValue::Field::Reader::hasName() const {
return !_reader.getPointerField(0 * ::capnp::POINTERS).isNull();
}
inline bool JsonValue::Field::Builder::hasName() {
return !_builder.getPointerField(0 * ::capnp::POINTERS).isNull();
}
inline ::capnp::Text::Reader JsonValue::Field::Reader::getName() const {
return ::capnp::_::PointerHelpers< ::capnp::Text>::get(
_reader.getPointerField(0 * ::capnp::POINTERS));
}
inline ::capnp::Text::Builder JsonValue::Field::Builder::getName() {
return ::capnp::_::PointerHelpers< ::capnp::Text>::get(
_builder.getPointerField(0 * ::capnp::POINTERS));
}
inline void JsonValue::Field::Builder::setName( ::capnp::Text::Reader value) {
::capnp::_::PointerHelpers< ::capnp::Text>::set(
_builder.getPointerField(0 * ::capnp::POINTERS), value);
}
inline ::capnp::Text::Builder JsonValue::Field::Builder::initName(unsigned int size) {
return ::capnp::_::PointerHelpers< ::capnp::Text>::init(
_builder.getPointerField(0 * ::capnp::POINTERS), size);
}
inline void JsonValue::Field::Builder::adoptName(
::capnp::Orphan< ::capnp::Text>&& value) {
::capnp::_::PointerHelpers< ::capnp::Text>::adopt(
_builder.getPointerField(0 * ::capnp::POINTERS), kj::mv(value));
}
inline ::capnp::Orphan< ::capnp::Text> JsonValue::Field::Builder::disownName() {
return ::capnp::_::PointerHelpers< ::capnp::Text>::disown(
_builder.getPointerField(0 * ::capnp::POINTERS));
}
inline bool JsonValue::Field::Reader::hasValue() const {
return !_reader.getPointerField(1 * ::capnp::POINTERS).isNull();
}
inline bool JsonValue::Field::Builder::hasValue() {
return !_builder.getPointerField(1 * ::capnp::POINTERS).isNull();
}
inline ::capnp::JsonValue::Reader JsonValue::Field::Reader::getValue() const {
return ::capnp::_::PointerHelpers< ::capnp::JsonValue>::get(
_reader.getPointerField(1 * ::capnp::POINTERS));
}
inline ::capnp::JsonValue::Builder JsonValue::Field::Builder::getValue() {
return ::capnp::_::PointerHelpers< ::capnp::JsonValue>::get(
_builder.getPointerField(1 * ::capnp::POINTERS));
}
#if !CAPNP_LITE
inline ::capnp::JsonValue::Pipeline JsonValue::Field::Pipeline::getValue() {
return ::capnp::JsonValue::Pipeline(_typeless.getPointerField(1));
}
#endif // !CAPNP_LITE
inline void JsonValue::Field::Builder::setValue( ::capnp::JsonValue::Reader value) {
::capnp::_::PointerHelpers< ::capnp::JsonValue>::set(
_builder.getPointerField(1 * ::capnp::POINTERS), value);
}
inline ::capnp::JsonValue::Builder JsonValue::Field::Builder::initValue() {
return ::capnp::_::PointerHelpers< ::capnp::JsonValue>::init(
_builder.getPointerField(1 * ::capnp::POINTERS));
}
inline void JsonValue::Field::Builder::adoptValue(
::capnp::Orphan< ::capnp::JsonValue>&& value) {
::capnp::_::PointerHelpers< ::capnp::JsonValue>::adopt(
_builder.getPointerField(1 * ::capnp::POINTERS), kj::mv(value));
}
inline ::capnp::Orphan< ::capnp::JsonValue> JsonValue::Field::Builder::disownValue() {
return ::capnp::_::PointerHelpers< ::capnp::JsonValue>::disown(
_builder.getPointerField(1 * ::capnp::POINTERS));
}
inline bool JsonValue::Call::Reader::hasFunction() const {
return !_reader.getPointerField(0 * ::capnp::POINTERS).isNull();
}
inline bool JsonValue::Call::Builder::hasFunction() {
return !_builder.getPointerField(0 * ::capnp::POINTERS).isNull();
}
inline ::capnp::Text::Reader JsonValue::Call::Reader::getFunction() const {
return ::capnp::_::PointerHelpers< ::capnp::Text>::get(
_reader.getPointerField(0 * ::capnp::POINTERS));
}
inline ::capnp::Text::Builder JsonValue::Call::Builder::getFunction() {
return ::capnp::_::PointerHelpers< ::capnp::Text>::get(
_builder.getPointerField(0 * ::capnp::POINTERS));
}
inline void JsonValue::Call::Builder::setFunction( ::capnp::Text::Reader value) {
::capnp::_::PointerHelpers< ::capnp::Text>::set(
_builder.getPointerField(0 * ::capnp::POINTERS), value);
}
inline ::capnp::Text::Builder JsonValue::Call::Builder::initFunction(unsigned int size) {
return ::capnp::_::PointerHelpers< ::capnp::Text>::init(
_builder.getPointerField(0 * ::capnp::POINTERS), size);
}
inline void JsonValue::Call::Builder::adoptFunction(
::capnp::Orphan< ::capnp::Text>&& value) {
::capnp::_::PointerHelpers< ::capnp::Text>::adopt(
_builder.getPointerField(0 * ::capnp::POINTERS), kj::mv(value));
}
inline ::capnp::Orphan< ::capnp::Text> JsonValue::Call::Builder::disownFunction() {
return ::capnp::_::PointerHelpers< ::capnp::Text>::disown(
_builder.getPointerField(0 * ::capnp::POINTERS));
}
inline bool JsonValue::Call::Reader::hasParams() const {
return !_reader.getPointerField(1 * ::capnp::POINTERS).isNull();
}
inline bool JsonValue::Call::Builder::hasParams() {
return !_builder.getPointerField(1 * ::capnp::POINTERS).isNull();
}
inline ::capnp::List< ::capnp::JsonValue>::Reader JsonValue::Call::Reader::getParams() const {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue>>::get(
_reader.getPointerField(1 * ::capnp::POINTERS));
}
inline ::capnp::List< ::capnp::JsonValue>::Builder JsonValue::Call::Builder::getParams() {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue>>::get(
_builder.getPointerField(1 * ::capnp::POINTERS));
}
inline void JsonValue::Call::Builder::setParams( ::capnp::List< ::capnp::JsonValue>::Reader value) {
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue>>::set(
_builder.getPointerField(1 * ::capnp::POINTERS), value);
}
inline ::capnp::List< ::capnp::JsonValue>::Builder JsonValue::Call::Builder::initParams(unsigned int size) {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue>>::init(
_builder.getPointerField(1 * ::capnp::POINTERS), size);
}
inline void JsonValue::Call::Builder::adoptParams(
::capnp::Orphan< ::capnp::List< ::capnp::JsonValue>>&& value) {
::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue>>::adopt(
_builder.getPointerField(1 * ::capnp::POINTERS), kj::mv(value));
}
inline ::capnp::Orphan< ::capnp::List< ::capnp::JsonValue>> JsonValue::Call::Builder::disownParams() {
return ::capnp::_::PointerHelpers< ::capnp::List< ::capnp::JsonValue>>::disown(
_builder.getPointerField(1 * ::capnp::POINTERS));
}
} // namespace
#endif // CAPNP_INCLUDED_8ef99297a43a5e34_
...@@ -41,11 +41,13 @@ TESTDATA=`dirname "$0"`/../testdata ...@@ -41,11 +41,13 @@ TESTDATA=`dirname "$0"`/../testdata
$CAPNP encode $SCHEMA TestAllTypes < $TESTDATA/short.txt | cmp $TESTDATA/binary - || fail encode $CAPNP encode $SCHEMA TestAllTypes < $TESTDATA/short.txt | cmp $TESTDATA/binary - || fail encode
$CAPNP encode --flat $SCHEMA TestAllTypes < $TESTDATA/short.txt | cmp $TESTDATA/flat - || fail encode flat $CAPNP encode --flat $SCHEMA TestAllTypes < $TESTDATA/short.txt | cmp $TESTDATA/flat - || fail encode flat
$CAPNP encode --packed $SCHEMA TestAllTypes < $TESTDATA/short.txt | cmp $TESTDATA/packed - || fail encode packed $CAPNP encode --packed $SCHEMA TestAllTypes < $TESTDATA/short.txt | cmp $TESTDATA/packed - || fail encode packed
$CAPNP encode --packed --flat $SCHEMA TestAllTypes < $TESTDATA/short.txt | cmp $TESTDATA/packedflat - || fail encode packedflat
$CAPNP encode $SCHEMA TestAllTypes < $TESTDATA/pretty.txt | cmp $TESTDATA/binary - || fail parse pretty $CAPNP encode $SCHEMA TestAllTypes < $TESTDATA/pretty.txt | cmp $TESTDATA/binary - || fail parse pretty
$CAPNP decode $SCHEMA TestAllTypes < $TESTDATA/binary | cmp $TESTDATA/pretty.txt - || fail decode $CAPNP decode $SCHEMA TestAllTypes < $TESTDATA/binary | cmp $TESTDATA/pretty.txt - || fail decode
$CAPNP decode --flat $SCHEMA TestAllTypes < $TESTDATA/flat | cmp $TESTDATA/pretty.txt - || fail decode flat $CAPNP decode --flat $SCHEMA TestAllTypes < $TESTDATA/flat | cmp $TESTDATA/pretty.txt - || fail decode flat
$CAPNP decode --packed $SCHEMA TestAllTypes < $TESTDATA/packed | cmp $TESTDATA/pretty.txt - || fail decode packed $CAPNP decode --packed $SCHEMA TestAllTypes < $TESTDATA/packed | cmp $TESTDATA/pretty.txt - || fail decode packed
$CAPNP decode --packed --flat $SCHEMA TestAllTypes < $TESTDATA/packedflat | cmp $TESTDATA/pretty.txt - || fail decode packedflat
$CAPNP decode --short $SCHEMA TestAllTypes < $TESTDATA/binary | cmp $TESTDATA/short.txt - || fail decode short $CAPNP decode --short $SCHEMA TestAllTypes < $TESTDATA/binary | cmp $TESTDATA/short.txt - || fail decode short
$CAPNP decode $SCHEMA TestAllTypes < $TESTDATA/segmented | cmp $TESTDATA/pretty.txt - || fail decode segmented $CAPNP decode $SCHEMA TestAllTypes < $TESTDATA/segmented | cmp $TESTDATA/pretty.txt - || fail decode segmented
......
...@@ -593,13 +593,11 @@ public: ...@@ -593,13 +593,11 @@ public:
} }
kj::MainBuilder::Validity codeFlat() { kj::MainBuilder::Validity codeFlat() {
if (binary) return "cannot be used with --binary"; if (binary) return "cannot be used with --binary";
if (packed) return "cannot be used with --packed";
flat = true; flat = true;
return true; return true;
} }
kj::MainBuilder::Validity codePacked() { kj::MainBuilder::Validity codePacked() {
if (binary) return "cannot be used with --binary"; if (binary) return "cannot be used with --binary";
if (flat) return "cannot be used with --flat";
packed = true; packed = true;
return true; return true;
} }
...@@ -683,12 +681,21 @@ public: ...@@ -683,12 +681,21 @@ public:
input.skip(buffer.size()); input.skip(buffer.size());
} }
// Technically we don't know if the bytes are aligned so we'd better copy them to a new if (packed) {
// array. Note that if we have a non-whole number of words we chop off the straggler bytes. words = kj::heapArray<word>(computeUnpackedSizeInWords(allBytes));
// This is fine because if those bytes are actually part of the message we will hit an error kj::ArrayInputStream input(allBytes);
// later and if they are not then who cares? capnp::_::PackedInputStream unpacker(input);
words = kj::heapArray<word>(allBytes.size() / sizeof(word)); unpacker.read(words.asBytes().begin(), words.asBytes().size());
memcpy(words.begin(), allBytes.begin(), words.size() * sizeof(word)); word dummy;
KJ_ASSERT(unpacker.tryRead(&dummy, sizeof(dummy), sizeof(dummy)) == 0);
} else {
// Technically we don't know if the bytes are aligned so we'd better copy them to a new
// array. Note that if we have a non-whole number of words we chop off the straggler
// bytes. This is fine because if those bytes are actually part of the message we will
// hit an error later and if they are not then who cares?
words = kj::heapArray<word>(allBytes.size() / sizeof(word));
memcpy(words.begin(), allBytes.begin(), words.size() * sizeof(word));
}
} }
kj::ArrayPtr<const word> segments = words; kj::ArrayPtr<const word> segments = words;
...@@ -869,7 +876,8 @@ private: ...@@ -869,7 +876,8 @@ private:
return isPlausiblyFlat(prefix.slice(segment0Offset, prefix.size()), segmentCount); return isPlausiblyFlat(prefix.slice(segment0Offset, prefix.size()), segmentCount);
} }
Plausibility isPlausiblyPacked(kj::ArrayPtr<const byte> prefix) { Plausibility isPlausiblyPacked(kj::ArrayPtr<const byte> prefix,
kj::Function<Plausibility(kj::ArrayPtr<const byte>)> checkUnpacked) {
kj::Vector<byte> unpacked; kj::Vector<byte> unpacked;
// Try to unpack a prefix so that we can check it. // Try to unpack a prefix so that we can check it.
...@@ -910,11 +918,93 @@ private: ...@@ -910,11 +918,93 @@ private:
} }
} }
return isPlausiblyBinary(unpacked); return checkUnpacked(unpacked);
}
Plausibility isPlausiblyPacked(kj::ArrayPtr<const byte> prefix) {
return isPlausiblyPacked(prefix, KJ_BIND_METHOD(*this, isPlausiblyBinary));
}
Plausibility isPlausiblyPackedFlat(kj::ArrayPtr<const byte> prefix) {
return isPlausiblyPacked(prefix, [this](kj::ArrayPtr<const byte> prefix) {
return isPlausiblyFlat(prefix);
});
} }
kj::MainBuilder::Validity checkPlausibility(kj::ArrayPtr<const byte> prefix) { kj::MainBuilder::Validity checkPlausibility(kj::ArrayPtr<const byte> prefix) {
if (flat) { if (flat && packed) {
switch (isPlausiblyPackedFlat(prefix)) {
case PLAUSIBLE:
break;
case IMPOSSIBLE:
if (plausibleOrWrongType(isPlausiblyPacked(prefix))) {
return "The input is not in --packed --flat format. It looks like it is in --packed "
"format. Try removing --flat.";
} else if (plausibleOrWrongType(isPlausiblyFlat(prefix))) {
return "The input is not in --packed --flat format. It looks like it is in --flat "
"format. Try removing --packed.";
} else if (plausibleOrWrongType(isPlausiblyBinary(prefix))) {
return "The input is not in --packed --flat format. It looks like it is in regular "
"binary format. Try removing the --packed and --flat flags.";
} else {
return "The input is not a Cap'n Proto message.";
}
case IMPLAUSIBLE:
if (plausibleOrWrongType(isPlausiblyPacked(prefix))) {
context.warning(
"*** WARNING ***\n"
"The input data does not appear to be in --packed --flat format. It looks like\n"
"it may be in --packed format. I'll try to parse it in --packed --flat format\n"
"as you requested, but if it doesn't work, try removing --flat. Use --quiet to\n"
"suppress this warning.\n"
"*** END WARNING ***\n");
} else if (plausibleOrWrongType(isPlausiblyFlat(prefix))) {
context.warning(
"*** WARNING ***\n"
"The input data does not appear to be in --packed --flat format. It looks like\n"
"it may be in --flat format. I'll try to parse it in --packed --flat format as\n"
"you requested, but if it doesn't work, try removing --packed. Use --quiet to\n"
"suppress this warning.\n"
"*** END WARNING ***\n");
} else if (plausibleOrWrongType(isPlausiblyBinary(prefix))) {
context.warning(
"*** WARNING ***\n"
"The input data does not appear to be in --packed --flat format. It looks like\n"
"it may be in regular binary format. I'll try to parse it in --packed --flat\n"
"format as you requested, but if it doesn't work, try removing --packed and\n"
"--flat. Use --quiet to suppress this warning.\n"
"*** END WARNING ***\n");
} else {
context.warning(
"*** WARNING ***\n"
"The input data does not appear to be a Cap'n Proto message in any known\n"
"binary format. I'll try to parse it anyway, but if it doesn't work, please\n"
"check your input. Use --quiet to suppress this warning.\n"
"*** END WARNING ***\n");
}
break;
case WRONG_TYPE:
if (plausibleOrWrongType(isPlausiblyPacked(prefix))) {
context.warning(
"*** WARNING ***\n"
"The input data does not appear to be the type that you specified. I'll try\n"
"to parse it anyway, but if it doesn't look right, please verify that you\n"
"have the right type. This could also be because the input is not in --flat\n"
"format; indeed, it looks like this input may be in regular --packed format,\n"
"so you might want to try removing --flat. Use --quiet to suppress this\n"
"warning.\n"
"*** END WARNING ***\n");
} else {
context.warning(
"*** WARNING ***\n"
"The input data does not appear to be the type that you specified. I'll try\n"
"to parse it anyway, but if it doesn't look right, please verify that you\n"
"have the right type. Use --quiet to suppress this warning.\n"
"*** END WARNING ***\n");
}
break;
}
} else if (flat) {
switch (isPlausiblyFlat(prefix)) { switch (isPlausiblyFlat(prefix)) {
case PLAUSIBLE: case PLAUSIBLE:
break; break;
...@@ -922,6 +1012,9 @@ private: ...@@ -922,6 +1012,9 @@ private:
if (plausibleOrWrongType(isPlausiblyPacked(prefix))) { if (plausibleOrWrongType(isPlausiblyPacked(prefix))) {
return "The input is not in --flat format. It looks like it is in --packed format. " return "The input is not in --flat format. It looks like it is in --packed format. "
"Try that instead."; "Try that instead.";
} else if (plausibleOrWrongType(isPlausiblyPackedFlat(prefix))) {
return "The input is not in --flat format. It looks like it is in --packed --flat "
"format. Try adding --packed.";
} else if (plausibleOrWrongType(isPlausiblyBinary(prefix))) { } else if (plausibleOrWrongType(isPlausiblyBinary(prefix))) {
return "The input is not in --flat format. It looks like it is in regular binary " return "The input is not in --flat format. It looks like it is in regular binary "
"format. Try removing the --flat flag."; "format. Try removing the --flat flag.";
...@@ -937,6 +1030,14 @@ private: ...@@ -937,6 +1030,14 @@ private:
"requested, but if it doesn't work, try --packed instead. Use --quiet to\n" "requested, but if it doesn't work, try --packed instead. Use --quiet to\n"
"suppress this warning.\n" "suppress this warning.\n"
"*** END WARNING ***\n"); "*** END WARNING ***\n");
} else if (plausibleOrWrongType(isPlausiblyPackedFlat(prefix))) {
context.warning(
"*** WARNING ***\n"
"The input data does not appear to be in --flat format. It looks like it may\n"
"be in --packed --flat format. I'll try to parse it in --flat format as you\n"
"requested, but if it doesn't work, try adding --packed. Use --quiet to\n"
"suppress this warning.\n"
"*** END WARNING ***\n");
} else if (plausibleOrWrongType(isPlausiblyBinary(prefix))) { } else if (plausibleOrWrongType(isPlausiblyBinary(prefix))) {
context.warning( context.warning(
"*** WARNING ***\n" "*** WARNING ***\n"
...@@ -983,6 +1084,10 @@ private: ...@@ -983,6 +1084,10 @@ private:
if (plausibleOrWrongType(isPlausiblyBinary(prefix))) { if (plausibleOrWrongType(isPlausiblyBinary(prefix))) {
return "The input is not in --packed format. It looks like it is in regular binary " return "The input is not in --packed format. It looks like it is in regular binary "
"format. Try removing the --packed flag."; "format. Try removing the --packed flag.";
} else if (plausibleOrWrongType(isPlausiblyPackedFlat(prefix))) {
return "The input is not in --packed format, nor does it look like it is in regular "
"binary format. It looks like it could be in --packed --flat format, although "
"that is unusual so I could be wrong.";
} else if (plausibleOrWrongType(isPlausiblyFlat(prefix))) { } else if (plausibleOrWrongType(isPlausiblyFlat(prefix))) {
return "The input is not in --packed format, nor does it look like it is in regular " return "The input is not in --packed format, nor does it look like it is in regular "
"binary format. It looks like it could be in --flat format, although that " "binary format. It looks like it could be in --flat format, although that "
...@@ -991,7 +1096,15 @@ private: ...@@ -991,7 +1096,15 @@ private:
return "The input is not a Cap'n Proto message."; return "The input is not a Cap'n Proto message.";
} }
case IMPLAUSIBLE: case IMPLAUSIBLE:
if (plausibleOrWrongType(isPlausiblyBinary(prefix))) { if (plausibleOrWrongType(isPlausiblyPackedFlat(prefix))) {
context.warning(
"*** WARNING ***\n"
"The input data does not appear to be in --packed format. It looks like it may\n"
"be in --packed --flat format. I'll try to parse it in --packed format as you\n"
"requested, but if it doesn't work, try adding --flat. Use --quiet to\n"
"suppress this warning.\n"
"*** END WARNING ***\n");
} else if (plausibleOrWrongType(isPlausiblyBinary(prefix))) {
context.warning( context.warning(
"*** WARNING ***\n" "*** WARNING ***\n"
"The input data does not appear to be in --packed format. It looks like it\n" "The input data does not appear to be in --packed format. It looks like it\n"
...@@ -1039,6 +1152,10 @@ private: ...@@ -1039,6 +1152,10 @@ private:
return "The input is not in regular binary format, nor does it look like it is in " return "The input is not in regular binary format, nor does it look like it is in "
"--packed format. It looks like it could be in --flat format, although that " "--packed format. It looks like it could be in --flat format, although that "
"is unusual so I could be wrong."; "is unusual so I could be wrong.";
} else if (plausibleOrWrongType(isPlausiblyPackedFlat(prefix))) {
return "The input is not in regular binary format, nor does it look like it is in "
"--packed format. It looks like it could be in --packed --flat format, "
"although that is unusual so I could be wrong.";
} else { } else {
return "The input is not a Cap'n Proto message."; return "The input is not a Cap'n Proto message.";
} }
...@@ -1051,6 +1168,14 @@ private: ...@@ -1051,6 +1168,14 @@ private:
"requested, but if it doesn't work, try adding --packed. Use --quiet to\n" "requested, but if it doesn't work, try adding --packed. Use --quiet to\n"
"suppress this warning.\n" "suppress this warning.\n"
"*** END WARNING ***\n"); "*** END WARNING ***\n");
} else if (plausibleOrWrongType(isPlausiblyPacked(prefix))) {
context.warning(
"*** WARNING ***\n"
"The input data does not appear to be in regular binary format. It looks like\n"
"it may be in --packed --flat format. I'll try to parse it in regular format as\n"
"you requested, but if it doesn't work, try adding --packed --flat. Use --quiet\n"
"to suppress this warning.\n"
"*** END WARNING ***\n");
} else if (plausibleOrWrongType(isPlausiblyFlat(prefix))) { } else if (plausibleOrWrongType(isPlausiblyFlat(prefix))) {
context.warning( context.warning(
"*** WARNING ***\n" "*** WARNING ***\n"
...@@ -1313,7 +1438,10 @@ private: ...@@ -1313,7 +1438,10 @@ private:
flatMessage.setRoot(value); flatMessage.setRoot(value);
flatMessage.requireFilled(); flatMessage.requireFilled();
if (flat) { if (flat && packed) {
capnp::_::PackedOutputStream packer(output);
packer.write(space.begin(), space.size() * sizeof(word));
} else if (flat) {
output.write(space.begin(), space.size() * sizeof(word)); output.write(space.begin(), space.size() * sizeof(word));
} else if (packed) { } else if (packed) {
writePackedMessage(output, flatMessage); writePackedMessage(output, flatMessage);
......
...@@ -1662,6 +1662,8 @@ struct WireHelpers { ...@@ -1662,6 +1662,8 @@ struct WireHelpers {
return { segment, ptr }; return { segment, ptr };
} else { } else {
// List of structs. // List of structs.
KJ_DASSERT(value.structDataSize % BITS_PER_WORD == 0 * BITS);
WordCount declDataSize = roundBitsUpToWords(value.structDataSize); WordCount declDataSize = roundBitsUpToWords(value.structDataSize);
WirePointerCount declPointerCount = value.structPointerCount; WirePointerCount declPointerCount = value.structPointerCount;
......
...@@ -667,7 +667,8 @@ class ListBuilder: public kj::DisallowConstCopy { ...@@ -667,7 +667,8 @@ class ListBuilder: public kj::DisallowConstCopy {
public: public:
inline explicit ListBuilder(ElementSize elementSize) inline explicit ListBuilder(ElementSize elementSize)
: segment(nullptr), capTable(nullptr), ptr(nullptr), elementCount(0 * ELEMENTS), : segment(nullptr), capTable(nullptr), ptr(nullptr), elementCount(0 * ELEMENTS),
step(0 * BITS / ELEMENTS), elementSize(elementSize) {} step(0 * BITS / ELEMENTS), elementSize(elementSize), structDataSize(0 * BITS),
structPointerCount(0 * POINTERS) {}
MSVC_DEFAULT_ASSIGNMENT_WORKAROUND(, ListBuilder) MSVC_DEFAULT_ASSIGNMENT_WORKAROUND(, ListBuilder)
......
...@@ -39,6 +39,11 @@ public: ...@@ -39,6 +39,11 @@ public:
~TestPipe() {} ~TestPipe() {}
const std::string& getData() { return data; } const std::string& getData() { return data; }
kj::ArrayPtr<const byte> getArray() {
return kj::arrayPtr(reinterpret_cast<const byte*>(data.data()), data.size());
}
void resetRead(size_t preferredReadSize = kj::maxValue) { void resetRead(size_t preferredReadSize = kj::maxValue) {
readPos = 0; readPos = 0;
this->preferredReadSize = preferredReadSize; this->preferredReadSize = preferredReadSize;
...@@ -84,6 +89,8 @@ private: ...@@ -84,6 +89,8 @@ private:
void expectPacksTo(kj::ArrayPtr<const byte> unpacked, kj::ArrayPtr<const byte> packed) { void expectPacksTo(kj::ArrayPtr<const byte> unpacked, kj::ArrayPtr<const byte> packed) {
TestPipe pipe; TestPipe pipe;
EXPECT_EQ(unpacked.size(), computeUnpackedSizeInWords(packed) * sizeof(word));
// ----------------------------------------------------------------- // -----------------------------------------------------------------
// write // write
...@@ -244,6 +251,8 @@ TEST(Packed, RoundTrip) { ...@@ -244,6 +251,8 @@ TEST(Packed, RoundTrip) {
TestPipe pipe; TestPipe pipe;
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
checkTestMessage(reader.getRoot<TestAllTypes>()); checkTestMessage(reader.getRoot<TestAllTypes>());
} }
...@@ -255,6 +264,8 @@ TEST(Packed, RoundTripScratchSpace) { ...@@ -255,6 +264,8 @@ TEST(Packed, RoundTripScratchSpace) {
TestPipe pipe; TestPipe pipe;
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
word scratch[1024]; word scratch[1024];
PackedMessageReader reader(pipe, ReaderOptions(), kj::ArrayPtr<word>(scratch, 1024)); PackedMessageReader reader(pipe, ReaderOptions(), kj::ArrayPtr<word>(scratch, 1024));
checkTestMessage(reader.getRoot<TestAllTypes>()); checkTestMessage(reader.getRoot<TestAllTypes>());
...@@ -267,6 +278,8 @@ TEST(Packed, RoundTripLazy) { ...@@ -267,6 +278,8 @@ TEST(Packed, RoundTripLazy) {
TestPipe pipe(1); TestPipe pipe(1);
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
checkTestMessage(reader.getRoot<TestAllTypes>()); checkTestMessage(reader.getRoot<TestAllTypes>());
} }
...@@ -278,6 +291,8 @@ TEST(Packed, RoundTripOddSegmentCount) { ...@@ -278,6 +291,8 @@ TEST(Packed, RoundTripOddSegmentCount) {
TestPipe pipe; TestPipe pipe;
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
checkTestMessage(reader.getRoot<TestAllTypes>()); checkTestMessage(reader.getRoot<TestAllTypes>());
} }
...@@ -289,6 +304,8 @@ TEST(Packed, RoundTripOddSegmentCountLazy) { ...@@ -289,6 +304,8 @@ TEST(Packed, RoundTripOddSegmentCountLazy) {
TestPipe pipe(1); TestPipe pipe(1);
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
checkTestMessage(reader.getRoot<TestAllTypes>()); checkTestMessage(reader.getRoot<TestAllTypes>());
} }
...@@ -300,6 +317,8 @@ TEST(Packed, RoundTripEvenSegmentCount) { ...@@ -300,6 +317,8 @@ TEST(Packed, RoundTripEvenSegmentCount) {
TestPipe pipe; TestPipe pipe;
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
checkTestMessage(reader.getRoot<TestAllTypes>()); checkTestMessage(reader.getRoot<TestAllTypes>());
} }
...@@ -311,6 +330,8 @@ TEST(Packed, RoundTripEvenSegmentCountLazy) { ...@@ -311,6 +330,8 @@ TEST(Packed, RoundTripEvenSegmentCountLazy) {
TestPipe pipe(1); TestPipe pipe(1);
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
checkTestMessage(reader.getRoot<TestAllTypes>()); checkTestMessage(reader.getRoot<TestAllTypes>());
} }
...@@ -326,6 +347,9 @@ TEST(Packed, RoundTripTwoMessages) { ...@@ -326,6 +347,9 @@ TEST(Packed, RoundTripTwoMessages) {
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
writePackedMessage(pipe, builder2); writePackedMessage(pipe, builder2);
EXPECT_EQ(computeSerializedSizeInWords(builder) + computeSerializedSizeInWords(builder2),
computeUnpackedSizeInWords(pipe.getArray()));
{ {
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
checkTestMessage(reader.getRoot<TestAllTypes>()); checkTestMessage(reader.getRoot<TestAllTypes>());
...@@ -346,6 +370,8 @@ TEST(Packed, RoundTripAllZero) { ...@@ -346,6 +370,8 @@ TEST(Packed, RoundTripAllZero) {
TestPipe pipe; TestPipe pipe;
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
checkTestMessageAllZero(reader.getRoot<TestAllTypes>()); checkTestMessageAllZero(reader.getRoot<TestAllTypes>());
...@@ -362,6 +388,8 @@ TEST(Packed, RoundTripAllZeroScratchSpace) { ...@@ -362,6 +388,8 @@ TEST(Packed, RoundTripAllZeroScratchSpace) {
TestPipe pipe; TestPipe pipe;
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
word scratch[1024]; word scratch[1024];
PackedMessageReader reader(pipe, ReaderOptions(), kj::ArrayPtr<word>(scratch, 1024)); PackedMessageReader reader(pipe, ReaderOptions(), kj::ArrayPtr<word>(scratch, 1024));
checkTestMessageAllZero(reader.getRoot<TestAllTypes>()); checkTestMessageAllZero(reader.getRoot<TestAllTypes>());
...@@ -374,6 +402,8 @@ TEST(Packed, RoundTripAllZeroLazy) { ...@@ -374,6 +402,8 @@ TEST(Packed, RoundTripAllZeroLazy) {
TestPipe pipe(1); TestPipe pipe(1);
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
checkTestMessageAllZero(reader.getRoot<TestAllTypes>()); checkTestMessageAllZero(reader.getRoot<TestAllTypes>());
} }
...@@ -385,6 +415,8 @@ TEST(Packed, RoundTripAllZeroOddSegmentCount) { ...@@ -385,6 +415,8 @@ TEST(Packed, RoundTripAllZeroOddSegmentCount) {
TestPipe pipe; TestPipe pipe;
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
checkTestMessageAllZero(reader.getRoot<TestAllTypes>()); checkTestMessageAllZero(reader.getRoot<TestAllTypes>());
} }
...@@ -396,6 +428,8 @@ TEST(Packed, RoundTripAllZeroOddSegmentCountLazy) { ...@@ -396,6 +428,8 @@ TEST(Packed, RoundTripAllZeroOddSegmentCountLazy) {
TestPipe pipe(1); TestPipe pipe(1);
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
checkTestMessageAllZero(reader.getRoot<TestAllTypes>()); checkTestMessageAllZero(reader.getRoot<TestAllTypes>());
} }
...@@ -407,6 +441,8 @@ TEST(Packed, RoundTripAllZeroEvenSegmentCount) { ...@@ -407,6 +441,8 @@ TEST(Packed, RoundTripAllZeroEvenSegmentCount) {
TestPipe pipe; TestPipe pipe;
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
checkTestMessageAllZero(reader.getRoot<TestAllTypes>()); checkTestMessageAllZero(reader.getRoot<TestAllTypes>());
} }
...@@ -418,6 +454,8 @@ TEST(Packed, RoundTripAllZeroEvenSegmentCountLazy) { ...@@ -418,6 +454,8 @@ TEST(Packed, RoundTripAllZeroEvenSegmentCountLazy) {
TestPipe pipe(1); TestPipe pipe(1);
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
checkTestMessageAllZero(reader.getRoot<TestAllTypes>()); checkTestMessageAllZero(reader.getRoot<TestAllTypes>());
} }
...@@ -434,6 +472,8 @@ TEST(Packed, RoundTripHugeString) { ...@@ -434,6 +472,8 @@ TEST(Packed, RoundTripHugeString) {
TestPipe pipe; TestPipe pipe;
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
EXPECT_TRUE(reader.getRoot<TestAllTypes>().getTextField() == huge); EXPECT_TRUE(reader.getRoot<TestAllTypes>().getTextField() == huge);
} }
...@@ -448,6 +488,8 @@ TEST(Packed, RoundTripHugeStringScratchSpace) { ...@@ -448,6 +488,8 @@ TEST(Packed, RoundTripHugeStringScratchSpace) {
TestPipe pipe; TestPipe pipe;
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
word scratch[1024]; word scratch[1024];
PackedMessageReader reader(pipe, ReaderOptions(), kj::ArrayPtr<word>(scratch, 1024)); PackedMessageReader reader(pipe, ReaderOptions(), kj::ArrayPtr<word>(scratch, 1024));
EXPECT_TRUE(reader.getRoot<TestAllTypes>().getTextField() == huge); EXPECT_TRUE(reader.getRoot<TestAllTypes>().getTextField() == huge);
...@@ -463,6 +505,8 @@ TEST(Packed, RoundTripHugeStringLazy) { ...@@ -463,6 +505,8 @@ TEST(Packed, RoundTripHugeStringLazy) {
TestPipe pipe(1); TestPipe pipe(1);
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
EXPECT_TRUE(reader.getRoot<TestAllTypes>().getTextField() == huge); EXPECT_TRUE(reader.getRoot<TestAllTypes>().getTextField() == huge);
} }
...@@ -477,6 +521,8 @@ TEST(Packed, RoundTripHugeStringOddSegmentCount) { ...@@ -477,6 +521,8 @@ TEST(Packed, RoundTripHugeStringOddSegmentCount) {
TestPipe pipe; TestPipe pipe;
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
EXPECT_TRUE(reader.getRoot<TestAllTypes>().getTextField() == huge); EXPECT_TRUE(reader.getRoot<TestAllTypes>().getTextField() == huge);
} }
...@@ -491,6 +537,8 @@ TEST(Packed, RoundTripHugeStringOddSegmentCountLazy) { ...@@ -491,6 +537,8 @@ TEST(Packed, RoundTripHugeStringOddSegmentCountLazy) {
TestPipe pipe(1); TestPipe pipe(1);
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
EXPECT_TRUE(reader.getRoot<TestAllTypes>().getTextField() == huge); EXPECT_TRUE(reader.getRoot<TestAllTypes>().getTextField() == huge);
} }
...@@ -505,6 +553,8 @@ TEST(Packed, RoundTripHugeStringEvenSegmentCount) { ...@@ -505,6 +553,8 @@ TEST(Packed, RoundTripHugeStringEvenSegmentCount) {
TestPipe pipe; TestPipe pipe;
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
EXPECT_TRUE(reader.getRoot<TestAllTypes>().getTextField() == huge); EXPECT_TRUE(reader.getRoot<TestAllTypes>().getTextField() == huge);
} }
...@@ -519,6 +569,8 @@ TEST(Packed, RoundTripHugeStringEvenSegmentCountLazy) { ...@@ -519,6 +569,8 @@ TEST(Packed, RoundTripHugeStringEvenSegmentCountLazy) {
TestPipe pipe(1); TestPipe pipe(1);
writePackedMessage(pipe, builder); writePackedMessage(pipe, builder);
EXPECT_EQ(computeSerializedSizeInWords(builder), computeUnpackedSizeInWords(pipe.getArray()));
PackedMessageReader reader(pipe); PackedMessageReader reader(pipe);
EXPECT_TRUE(reader.getRoot<TestAllTypes>().getTextField() == huge); EXPECT_TRUE(reader.getRoot<TestAllTypes>().getTextField() == huge);
} }
......
...@@ -43,7 +43,7 @@ size_t PackedInputStream::tryRead(void* dst, size_t minBytes, size_t maxBytes) { ...@@ -43,7 +43,7 @@ size_t PackedInputStream::tryRead(void* dst, size_t minBytes, size_t maxBytes) {
uint8_t* const outEnd = reinterpret_cast<uint8_t*>(dst) + maxBytes; uint8_t* const outEnd = reinterpret_cast<uint8_t*>(dst) + maxBytes;
uint8_t* const outMin = reinterpret_cast<uint8_t*>(dst) + minBytes; uint8_t* const outMin = reinterpret_cast<uint8_t*>(dst) + minBytes;
kj::ArrayPtr<const byte> buffer = inner.getReadBuffer(); kj::ArrayPtr<const byte> buffer = inner.tryGetReadBuffer();
if (buffer.size() == 0) { if (buffer.size() == 0) {
return 0; return 0;
} }
...@@ -476,4 +476,32 @@ void writePackedMessageToFd(int fd, kj::ArrayPtr<const kj::ArrayPtr<const word>> ...@@ -476,4 +476,32 @@ void writePackedMessageToFd(int fd, kj::ArrayPtr<const kj::ArrayPtr<const word>>
writePackedMessage(output, segments); writePackedMessage(output, segments);
} }
size_t computeUnpackedSizeInWords(kj::ArrayPtr<const byte> packedBytes) {
const byte* ptr = packedBytes.begin();
const byte* end = packedBytes.end();
size_t total = 0;
while (ptr < end) {
uint tag = *ptr;
size_t count = __builtin_popcount(tag);
total += 1;
KJ_REQUIRE(end - ptr >= count, "invalid packed data");
ptr += count + 1;
if (tag == 0) {
KJ_REQUIRE(ptr < end, "invalid packed data");
total += *ptr++;
} else if (tag == 0xff) {
KJ_REQUIRE(ptr < end, "invalid packed data");
size_t words = *ptr++;
total += words;
size_t bytes = words * sizeof(word);
KJ_REQUIRE(end - ptr >= bytes, "invalid packed data");
ptr += bytes;
}
}
return total;
}
} // namespace capnp } // namespace capnp
...@@ -106,6 +106,10 @@ void writePackedMessageToFd(int fd, MessageBuilder& builder); ...@@ -106,6 +106,10 @@ void writePackedMessageToFd(int fd, MessageBuilder& builder);
void writePackedMessageToFd(int fd, kj::ArrayPtr<const kj::ArrayPtr<const word>> segments); void writePackedMessageToFd(int fd, kj::ArrayPtr<const kj::ArrayPtr<const word>> segments);
// Write a single packed message to the file descriptor. // Write a single packed message to the file descriptor.
size_t computeUnpackedSizeInWords(kj::ArrayPtr<const byte> packedBytes);
// Computes the number of words to which the given packed bytes will unpack. Not intended for use
// in performance-sensitive situations.
// ======================================================================================= // =======================================================================================
// inline stuff // inline stuff
......
...@@ -103,6 +103,22 @@ public: ...@@ -103,6 +103,22 @@ public:
} }
} }
inline void operator=(decltype(nullptr)) {
builder = nullptr;
}
inline void clear() {
while (builder.size() > 0) {
builder.removeLast();
}
}
inline void truncate(size_t size) {
while (builder.size() > size) {
builder.removeLast();
}
}
private: private:
ArrayBuilder<T> builder; ArrayBuilder<T> builder;
......
...@@ -22,7 +22,7 @@ project's documentation for details. ...@@ -22,7 +22,7 @@ project's documentation for details.
##### Serialization only ##### Serialization only
* [C](https://github.com/jmckaskill/c-capnproto) by [@jmckaskill](https://github.com/jmckaskill) * [C](https://github.com/opensourcerouting/c-capnproto) by [OpenSourceRouting](https://www.opensourcerouting.org/) / [@eqvinox](https://github.com/eqvinox) (originally by [@jmckaskill](https://github.com/jmckaskill))
* [C#](https://github.com/mgravell/capnproto-net) by [@mgravell](https://github.com/mgravell) * [C#](https://github.com/mgravell/capnproto-net) by [@mgravell](https://github.com/mgravell)
* [Go](https://github.com/glycerine/go-capnproto) by [@glycerine](https://github.com/glycerine) (originally by [@jmckaskill](https://github.com/jmckaskill)) * [Go](https://github.com/glycerine/go-capnproto) by [@glycerine](https://github.com/glycerine) (originally by [@jmckaskill](https://github.com/jmckaskill))
* [Java](https://github.com/dwrensha/capnproto-java/) by [@dwrensha](https://github.com/dwrensha) * [Java](https://github.com/dwrensha/capnproto-java/) by [@dwrensha](https://github.com/dwrensha)
...@@ -41,8 +41,8 @@ new languages. ...@@ -41,8 +41,8 @@ new languages.
* [Common Test Framework](https://github.com/kaos/capnp_test) by [@kaos](https://github.com/kaos) * [Common Test Framework](https://github.com/kaos/capnp_test) by [@kaos](https://github.com/kaos)
* [Sublime Syntax Highlighting](https://github.com/joshuawarner32/capnproto-sublime) by * [Sublime Syntax Highlighting](https://github.com/joshuawarner32/capnproto-sublime) by
[@joshuawarner32](https://github.com/joshuawarner32) [@joshuawarner32](https://github.com/joshuawarner32)
* [Vim Syntax Highlighting](https://github.com/cstrahan/vim-capnp) by * [Vim Syntax Highlighting](https://github.com/peter-edge/vim-capnp) by [@peter-edge](https://github.com/peter-edge)
[@cstrahan](https://github.com/cstrahan) (originally by [@cstrahan](https://github.com/cstrahan))
* [Wireshark Dissector Plugin](https://github.com/kaos/wireshark-plugins) by [@kaos](https://github.com/kaos) * [Wireshark Dissector Plugin](https://github.com/kaos/wireshark-plugins) by [@kaos](https://github.com/kaos)
## Contribute Your Own! ## Contribute Your Own!
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment