major change to api, {incomplete, Next, Force} replaced by {incomplete, Next/1} where Next/1 accepts 'end_stream' to replicate what Force/1 used to do
This commit is contained in:
parent
1188f02d9f
commit
42a18cfcd9
5 changed files with 354 additions and 193 deletions
|
@ -83,39 +83,29 @@
|
|||
).
|
||||
|
||||
|
||||
%% two macros to simplify incomplete handling
|
||||
-define(incomplete(Valid, Incomplete, Finish),
|
||||
case Valid of
|
||||
true -> {error, badjson}
|
||||
; false -> {incomplete, Incomplete, Finish}
|
||||
end
|
||||
).
|
||||
|
||||
-define(ferror, fun() -> {error, badjson} end).
|
||||
|
||||
|
||||
%% compilation macros for unified decoder
|
||||
-ifdef(utf8).
|
||||
-define(encoding, utf8).
|
||||
-define(partial_codepoint(Bin), byte_size(Bin) >= 1).
|
||||
-define(partial_codepoint(Bin), byte_size(Bin) < 1).
|
||||
-endif.
|
||||
|
||||
-ifdef(utf16).
|
||||
-define(encoding, utf16).
|
||||
-define(partial_codepoint(Bin), byte_size(Bin) >= 2).
|
||||
-define(partial_codepoint(Bin), byte_size(Bin) < 2).
|
||||
-endif.
|
||||
|
||||
-ifdef(utf16le).
|
||||
-define(encoding, utf16-little).
|
||||
-define(partial_codepoint(Bin), byte_size(Bin) >= 2).
|
||||
-define(partial_codepoint(Bin), byte_size(Bin) < 2).
|
||||
-endif.
|
||||
|
||||
-ifdef(utf32).
|
||||
-define(encoding, utf32).
|
||||
-define(partial_codepoint(Bin), byte_size(Bin) >= 4).
|
||||
-define(partial_codepoint(Bin), byte_size(Bin) < 4).
|
||||
-endif.
|
||||
|
||||
-ifdef(utf32le).
|
||||
-define(encoding, utf32-little).
|
||||
-define(partial_codepoint(Bin), byte_size(Bin) >= 4).
|
||||
-define(partial_codepoint(Bin), byte_size(Bin) < 4).
|
||||
-endif.
|
|
@ -58,5 +58,6 @@
|
|||
-type jsx_parser() :: fun((json()) -> jsx_parser_result()).
|
||||
|
||||
-type jsx_parser_result() :: {event, jsx_event(), fun(() -> jsx_parser_result())}
|
||||
| {incomplete, jsx_parser(), fun(() -> jsx_parser_result())}
|
||||
| {error, badjson}.
|
||||
| {incomplete, jsx_parser()}
|
||||
| {error, badjson}
|
||||
| ok.
|
Loading…
Add table
Add a link
Reference in a new issue