jgarzik / univalue Goto Github PK
View Code? Open in Web Editor NEWHigh performance RAII C++ JSON library and universal value object class
License: MIT License
High performance RAII C++ JSON library and universal value object class
License: MIT License
Regression introduced by PR #61
With GCC 9.3.0, building Bitcoin Core 0.17+:
rpc/blockchain.cpp:2077:35: error: no viable conversion from 'std::atomic<int>' to 'const UniValue'
result.pushKV("progress", g_scan_progress);
^~~~~~~~~~~~~~~
See this commit, with a univalue-related change: bitcoin/bitcoin@64fb0ac
operator[] returns a const, preventing modifications. Similarly, there is no way to replace items in an Array.
I downloaded univalue zip installed it as per instructions mentioned
But It does not install any files in /usr/lib or /usr/include which creates problem for installing cpptrade software.
Kindly help
In my experience this can give interoperability issues which are very hard to troubleshoot if the user/application has a different locale setting.
I'd prefer using own implementations which strictly adhere to RFC4627 definitions.
ws = *(
%x20 / ; Space
%x09 / ; Horizontal tab
%x0A / ; Line feed or New line
%x0D ; Carriage return
)
digit1-9 = %x31-39 ; 1-9
zero = %x30 ; 0
No output at all is generated for special floating point values like NaN, -inf, +inf, resulting in unparseable output.
This is what python makes of it:
>>> json.dumps(float("inf"))
'Infinity'
>>> json.dumps(float("-inf"))
'-Infinity'
>>> json.dumps(float("-Nan"))
'NaN'
These are valid javascript, but not JSON according to https://tools.ietf.org/html/rfc7159:
Numeric values that cannot be represented in the grammar below (such
as Infinity and NaN) are not permitted.
Not sure how to handle this.
Not sure if this was designed specifically for use with bitcoin related services only, but support for wstrings and other w* types would make it a great drop in replacement for the old json spirit many services just copied from pre-univalue sources.
UniValue
as a class could take advantage of C++11 move semantics to improve efficiency in some cases. (It is probably not very relevant in practice and for Bitcoin Core, but would still be nice to have.)
What do you think, would that make sense to add? (If yes, then I'm happy to provide a PR for it.)
It seems they can only be added, never deleted?
Literally not a single method is documented :|
My main question is what is the difference between using the []
operator or find_value()
.
In line of bitcoin/bitcoin#12190 and bitcoin/bitcoin#12192 the URLs to the MIT license should be updated to use https protocol. I will draft a PR.
Commas (value-separator) between items in an array are mandatory according to RFC 4627, however univalue is somewhat lax. For example, this is accepted:
[ true true true [] [] [] ]
The same issue might exist for objects - haven't checked.
UTF-8 is not handled while writing strings in json_escape
. The result of this is that unicode sequences like '\u1234' will be expanded to their UTF-8 equivalent on a roundtrip, and re-encoded as multiple unicode characters \u00XX\u00XX...
which is not correct.
This could be handled:
If the input/output is UTF-8 encoded, UTF-8 sequences in strings can be passed through on output without any processing (according to RFC 4627 "All Unicode characters may be placed within the quotation marks except for the characters that must be escaped: quotation mark, reverse solidus, and the control characters (U+0000 through U+001F).")
From RFC 4627:
JSON text SHALL be encoded in Unicode. The default encoding is
UTF-8.
I sent this json {"jsonrpc":"2.0","method":"sendmany","params":["","{"test":9.5616}"],"id":2}
to program that use Univalue and got this error: "JSON value is not an object as expected"
Hi,
It seems Bitcoin has run of with a recent development snapshot of univalue and treated it as release 1.0.4.
Please formally issue a release 1.0.4, for those (like Debian) who prefer system-shared libraries tracking single unified upstream projects.
(or document if in fact this is a fork and the proper source is what is maintained by the Bitcoin project).
/Applications/Xcode.app/Contents/Developer/usr/bin/make all-am
CXX test/object-object.o
CXX test/unitester-unitester.o
CXX test/no_nul-no_nul.o
CXX test/test_json-test_json.o
CXX lib/libunivalue_la-univalue.lo
CXX lib/libunivalue_la-univalue_get.lo
CXX lib/libunivalue_la-univalue_read.lo
CXX lib/libunivalue_la-univalue_write.lo
CXXLD libunivalue.la
ar: `u' modifier ignored since `D' is the default (see `U')
CXXLD test/object
CXXLD test/unitester
CXXLD test/no_nul
CXXLD test/test_json
ld: warning: ignoring file ./.libs/libunivalue.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
ld: warning: ignoring file ./.libs/libunivalue.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
ld: warning: ignoring file ./.libs/libunivalue.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
Undefined symbols for architecture x86_64:
"UniValue::read(char const*, unsigned long)", referenced from:
_main in no_nul-no_nul.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Undefined symbols for architecture x86_64:
"UniValue::push_backV(std::__1::vector<UniValue, std::__1::allocator<UniValue> > const&)", referenced from:
univalue_array() in object-object.o
"UniValue::read(char const*, unsigned long)", referenced from:
univalue_typecheck() in object-object.o
univalue_readwrite() in object-object.o
"UniValue::clear()", referenced from:
univalue_set() in object-object.o
univalue_array() in object-object.o
univalue_object() in object-object.o
"UniValue::pushKV(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, UniValue const&)", referenced from:
univalue_object() in object-object.o
"UniValue::setInt(long long)", referenced from:
univalue_set() in object-object.o
univalue_object() in object-object.o
UniValue::UniValue(long long) in object-object.o
UniValue::UniValue(int) in object-object.o
"UniValue::setInt(unsigned long long)", referenced from:
univalue_set() in object-object.o
UniValue::UniValue(unsigned long long) in object-object.o
"UniValue::setStr(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
univalue_set() in object-object.o
univalue_array() in object-object.o
UniValue::UniValue(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in object-object.o
UniValue::UniValue(char const*) in object-object.o
"UniValue::pushKVs(UniValue const&)", referenced from:
univalue_object() in object-object.o
"UniValue::setBool(bool)", referenced from:
univalue_typecheck() in object-object.o
univalue_set() in object-object.o
UniValue::UniValue(bool) in object-object.o
"UniValue::setNull()", referenced from:
univalue_set() in object-object.o
"UniValue::__pushKV(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, UniValue const&)", referenced from:
univalue_object() in object-object.o
"UniValue::setArray()", referenced from:
univalue_set() in object-object.o
"UniValue::setFloat(double)", referenced from:
univalue_set() in object-object.o
UniValue::UniValue(double) in object-object.o
"UniValue::push_back(UniValue const&)", referenced from:
univalue_array() in object-object.o
make[1]: *** [test/no_nul] Error 1 "UniValue::setNumStr(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
univalue_constructor() in object-object.o
univalue_typecheck() in object-object.o
univalue_set() in object-object.o
"UniValue::setObject()", referenced from:
univalue_set() in object-object.o
univalue_object() in object-object.o
make[1]: *** Waiting for unfinished jobs....
"UniValue::checkObject(std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, UniValue::VType, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, UniValue::VType> > > const&) const", referenced from:
Undefined symbols for architecture x86_64:
univalue_object() in object-object.o
"UniValue::read(char const*, unsigned long)", referenced from:
"UniValue::write(unsigned int, unsigned int) const", referenced from:
_main in test_json-test_json.o
univalue_readwrite() in object-object.o
"UniValue::write(unsigned int, unsigned int) const", referenced from:
_main in test_json-test_json.o
"UniValue::findKey(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long&) const", referenced from:
univalue_object() in object-object.o
"UniValue::getKeys() const", referenced from:
univalue_typecheck() in object-object.o
"UniValue::get_int() const", referenced from:
ld: symbol(s) not found for architecture x86_64
univalue_typecheck() in object-object.o
"UniValue::get_obj() const", referenced from:
univalue_typecheck() in object-object.o
"UniValue::get_str() const", referenced from:
univalue_typecheck() in object-object.o
"UniValue::get_bool() const", referenced from:
univalue_typecheck() in object-object.o
"UniValue::get_real() const", referenced from:
univalue_typecheck() in object-object.o
"UniValue::getObjMap(std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, UniValue, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, UniValue> > >&) const", referenced from:
univalue_object() in object-object.o
"UniValue::getValues() const", referenced from:
univalue_typecheck() in object-object.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
"UniValue::get_array() const", referenced from:
univalue_typecheck() in object-object.o
"UniValue::get_int64() const", referenced from:
univalue_typecheck() in object-object.o
"UniValue::operator[](std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
univalue_object() in object-object.o
univalue_readwrite() in object-object.o
"UniValue::operator[](unsigned long) const", referenced from:
univalue_array() in object-object.o
univalue_readwrite() in object-object.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [test/test_json] Error 1
make[1]: *** [test/object] Error 1
ld: warning: ignoring file ./.libs/libunivalue.a, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
Undefined symbols for architecture x86_64:
"UniValue::read(char const*, unsigned long)", referenced from:
unescape_unicode_test() in unitester-unitester.o
_main in unitester-unitester.o
"UniValue::write(unsigned int, unsigned int) const", referenced from:
_main in unitester-unitester.o
"UniValue::get_str() const", referenced from:
unescape_unicode_test() in unitester-unitester.o
"UniValue::operator[](unsigned long) const", referenced from:
unescape_unicode_test() in unitester-unitester.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [test/unitester] Error 1
make: *** [all] Error 2
I was surprised to see it's not an error to call push_back on UniValues that aren't arrays and pushKV on UniValues that aren't objects. Is this by design? It caused a bug recently: bitcoin/bitcoin#10450
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.