Switch JSON encoding/decoding to Jiffy
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/bc948321 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/bc948321 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/bc948321 Branch: refs/heads/import Commit: bc9483216b76c4bf61eb7223e0e14289420129e3 Parents: 331d549 Author: Paul J. Davis <paul.joseph.da...@gmail.com> Authored: Tue Feb 4 22:20:32 2014 -0600 Committer: Paul J. Davis <paul.joseph.da...@gmail.com> Committed: Tue Feb 4 22:20:32 2014 -0600 ---------------------------------------------------------------------- include/couch_db.hrl | 4 ++-- src/couch_util.erl | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/bc948321/include/couch_db.hrl ---------------------------------------------------------------------- diff --git a/include/couch_db.hrl b/include/couch_db.hrl index ffecae0..2c015df 100644 --- a/include/couch_db.hrl +++ b/include/couch_db.hrl @@ -18,8 +18,8 @@ -define(MIN_STR, <<"">>). -define(MAX_STR, <<255>>). % illegal utf string --define(JSON_ENCODE(V), ejson:encode(V)). --define(JSON_DECODE(V), ejson:decode(V)). +-define(JSON_ENCODE(V), couch_util:json_encode(V)). +-define(JSON_DECODE(V), couch_util:json_decode(V)). -define(b2l(V), binary_to_list(V)). -define(l2b(V), list_to_binary(V)). http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/bc948321/src/couch_util.erl ---------------------------------------------------------------------- diff --git a/src/couch_util.erl b/src/couch_util.erl index d09211a..beb9622 100644 --- a/src/couch_util.erl +++ b/src/couch_util.erl @@ -21,6 +21,7 @@ -export([get_nested_json_value/2, json_user_ctx/1]). -export([proplist_apply_field/2, json_apply_field/2]). -export([to_binary/1, to_integer/1, to_list/1, url_encode/1]). +-export([json_encode/1, json_decode/1]). -export([verify/2,simple_call/2,shutdown_sync/1]). -export([get_value/2, get_value/3]). -export([md5/1, md5_init/0, md5_update/2, md5_final/1]). @@ -376,6 +377,17 @@ url_encode([H|T]) -> url_encode([]) -> []. +json_encode(V) -> + jiffy:encode(V, [force_utf8]). + +json_decode(V) -> + try + jiffy:decode(V) + catch + throw:Error -> + throw({invalid_json, Error}) + end. + verify([X|RestX], [Y|RestY], Result) -> verify(RestX, RestY, (X bxor Y) bor Result); verify([], [], Result) ->