Skip to content

Commit

Permalink
Victor/json/remove span reader from json (Azure#342)
Browse files Browse the repository at this point in the history
* remove az_result_byte and az_span_reader
  • Loading branch information
vhvb1989 authored Feb 11, 2020
1 parent 37e1056 commit d108343
Show file tree
Hide file tree
Showing 17 changed files with 295 additions and 339 deletions.
1 change: 0 additions & 1 deletion sdk/core/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ add_library (
src/az_json_token.c
src/az_log.c
src/az_span.c
src/az_span_reader.c
)

if(MSVC)
Expand Down
3 changes: 1 addition & 2 deletions sdk/core/core/inc/az_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <az_result.h>
#include <az_span.h>
#include <az_span_reader.h>

#include <stdbool.h>

Expand Down Expand Up @@ -132,7 +131,7 @@ AZ_NODISCARD az_result az_json_builder_append_array_close(az_json_builder * self
typedef uint64_t az_json_stack;
typedef struct {
struct {
az_span_reader reader;
az_span reader;
az_json_stack stack;
} _internal;
} az_json_parser;
Expand Down
51 changes: 0 additions & 51 deletions sdk/core/core/inc/az_span_reader.h

This file was deleted.

17 changes: 1 addition & 16 deletions sdk/core/core/src/az_http_response_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,6 @@ AZ_NODISCARD az_result _az_slice_is_not_http_whitespace(az_span slice) {
return _az_is_http_whitespace(az_span_ptr(slice)[0]) == true ? AZ_CONTINUE : AZ_OK;
}

AZ_NODISCARD az_result _az_is_expected_span(az_span * self, az_span expected) {
az_span actual_span = { 0 };

int32_t expected_length = az_span_length(expected);
AZ_RETURN_IF_FAILED(az_span_slice(*self, 0, expected_length, &actual_span));

if (!az_span_is_equal(actual_span, expected)) {
return AZ_ERROR_PARSER_UNEXPECTED_CHAR;
}
// move reader after the expected span (means it was parsed as expected)
AZ_RETURN_IF_FAILED(az_span_slice(*self, expected_length, -1, self));

return AZ_OK;
}

/* PRIVATE Function. parse next */
AZ_NODISCARD az_result _az_get_digit(az_span * self, uint8_t * save_here) {

Expand Down Expand Up @@ -194,7 +179,7 @@ AZ_NODISCARD az_result az_http_response_get_next_header(az_http_response * self,
int32_t offset = 0;
int32_t offset_value_end = offset;
while (true) {
uint8_t c = reader->_internal.ptr[offset];
uint8_t c = az_span_ptr(*reader)[offset];
offset += 1;
if (c == '\r') {
break; // break as soon as end of value char is found
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/core/src/az_json_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ AZ_NODISCARD az_result az_json_builder_write_span(az_json_builder * self, az_spa
AZ_RETURN_IF_FAILED(az_span_append(*json, AZ_SPAN_FROM_STR("\""), json));

for (int32_t i = 0; i < az_span_length(value); ++i) {
az_result_byte const c = az_span_ptr(value)[i];
uint8_t const c = az_span_ptr(value)[i];

// check if the character has to be escaped.
{
Expand All @@ -38,7 +38,7 @@ AZ_NODISCARD az_result az_json_builder_write_span(az_json_builder * self, az_spa
}
}
// check if the character has to be escaped as a UNICODE escape sequence.
if (0 <= c && c < 0x20) {
if (c < 0x20) {
uint8_t array[6] = {
'\\',
'u',
Expand Down
7 changes: 4 additions & 3 deletions sdk/core/core/src/az_json_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
#include <_az_cfg.h>

AZ_NODISCARD bool az_json_pointer_token_eq_json_string(az_span pointer_token, az_span json_string) {
az_span_reader pt_reader = az_span_reader_create(pointer_token);
az_span_reader js_reader = az_span_reader_create(json_string);
// copy spans to read them
az_span pt_reader = pointer_token;
az_span js_reader = json_string;
while (true) {
uint32_t pt_c = { 0 };
az_result const pt_result = az_span_reader_read_json_pointer_token_char(&pt_reader, &pt_c);
Expand Down Expand Up @@ -68,7 +69,7 @@ az_json_parse_by_pointer(az_span json, az_span pointer, az_json_token * out_toke

az_json_parser json_parser = { 0 };
AZ_RETURN_IF_FAILED(az_json_parser_init(&json_parser, json));
az_span_reader pointer_parser = az_span_reader_create(pointer);
az_span pointer_parser = pointer;

AZ_RETURN_IF_FAILED(az_json_parser_parse_token(&json_parser, out_token));

Expand Down
Loading

0 comments on commit d108343

Please sign in to comment.