Skip to content

Switch to CBOR as default packing mode #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions driver/queries.c
Original file line number Diff line number Diff line change
Expand Up @@ -2986,11 +2986,16 @@ static SQLRETURN statement_len_cbor(esodbc_stmt_st *stmt, size_t *enc_len,
bodylen += cbor_str_obj_len(version.cnt);
*keys += 4; /* field_m._val., idx._inc._frozen, time_zone, version */
}
/* mode */
bodylen += cbor_str_obj_len(sizeof(REQ_KEY_MODE) - 1);
bodylen += cbor_str_obj_len(sizeof(REQ_VAL_MODE) - 1);
/* client_id */
bodylen += cbor_str_obj_len(sizeof(REQ_KEY_CLT_ID) - 1);
bodylen += cbor_str_obj_len(sizeof(REQ_VAL_CLT_ID) - 1);
*keys += 2; /* mode, client_id */
/* binary_format */
bodylen += cbor_str_obj_len(sizeof(REQ_KEY_BINARY_FMT) - 1);
bodylen += CBOR_OBJ_BOOL_LEN;
*keys += 3; /* mode, client_id, binary_format */
/* TODO: request_/page_timeout */

*enc_len = bodylen;
Expand Down Expand Up @@ -3048,8 +3053,10 @@ static SQLRETURN statement_len_json(esodbc_stmt_st *stmt, size_t *outlen)
bodylen += sizeof(JSON_KEY_VERSION) - 1;
bodylen += version.cnt + /* 2x`"` */2;
}
bodylen += sizeof(JSON_KEY_VAL_MODE) - 1; /* "mode": "ODBC" */
bodylen += sizeof(JSON_KEY_CLT_ID) - 1; /* "client_id": "odbcXX" */
bodylen += sizeof(JSON_KEY_VAL_MODE) - 1; /* "mode": */
bodylen += sizeof(JSON_KEY_CLT_ID) - 1; /* "client_id": */
bodylen += sizeof(JSON_KEY_BINARY_FMT) - 1; /* "binary_format": false */
bodylen += sizeof("false") - 1;
/* TODO: request_/page_timeout */
bodylen += 1; /* } */

Expand Down Expand Up @@ -3342,6 +3349,11 @@ static SQLRETURN serialize_to_cbor(esodbc_stmt_st *stmt, cstr_st *dest,
err = cbor_encode_text_string(&map, REQ_VAL_CLT_ID,
sizeof(REQ_VAL_CLT_ID) - 1);
FAIL_ON_CBOR_ERR(stmt, err);
/* binary_format: true (false means JSON) */
err = cbor_encode_text_string(&map, REQ_KEY_BINARY_FMT,
sizeof(REQ_KEY_BINARY_FMT) - 1);
FAIL_ON_CBOR_ERR(stmt, err);
err = cbor_encode_boolean(&map, TRUE);

err = cbor_encoder_close_container(&encoder, &map);
FAIL_ON_CBOR_ERR(stmt, err);
Expand Down Expand Up @@ -3458,6 +3470,10 @@ static SQLRETURN serialize_to_json(esodbc_stmt_st *stmt, cstr_st *dest)
/* "client_id": "odbcXX" */
memcpy(body + pos, JSON_KEY_CLT_ID, sizeof(JSON_KEY_CLT_ID) - 1);
pos += sizeof(JSON_KEY_CLT_ID) - 1;
/* "binary_format": false (true means CBOR) */
memcpy(body + pos, JSON_KEY_BINARY_FMT, sizeof(JSON_KEY_BINARY_FMT) - 1);
pos += sizeof(JSON_KEY_BINARY_FMT) - 1;
pos += copy_bool_val(body + pos, FALSE);
body[pos ++] = '}';

/* check that the buffer hasn't been overrun. it can be used less than
Expand Down
2 changes: 2 additions & 0 deletions driver/queries.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ SQLRETURN EsSQLRowCount(_In_ SQLHSTMT StatementHandle, _Out_ SQLLEN *RowCount);
#define REQ_KEY_MULTIVAL "field_multi_value_leniency"
#define REQ_KEY_IDX_FROZEN "index_include_frozen"
#define REQ_KEY_TIMEZONE "time_zone"
#define REQ_KEY_BINARY_FMT "binary_format"
/* keys for the "params" argument */
#define REQ_KEY_PARAM_TYPE "type"
#define REQ_KEY_PARAM_VAL "value"
Expand Down Expand Up @@ -171,6 +172,7 @@ SQLRETURN EsSQLRowCount(_In_ SQLHSTMT StatementHandle, _Out_ SQLLEN *RowCount);
#define JSON_KEY_MULTIVAL ", \"" REQ_KEY_MULTIVAL "\": " /* n-th */
#define JSON_KEY_IDX_FROZEN ", \"" REQ_KEY_IDX_FROZEN "\": " /* n-th */
#define JSON_KEY_TIMEZONE ", \"" REQ_KEY_TIMEZONE "\": " /* n-th key */
#define JSON_KEY_BINARY_FMT ", \"" REQ_KEY_BINARY_FMT "\": " /* n-th key */

#define JSON_VAL_TIMEZONE_Z "\"" REQ_VAL_TIMEZONE_Z "\""

Expand Down
4 changes: 2 additions & 2 deletions dsneditor/EsOdbcDsnEditor/DSNEditorForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dsneditor/EsOdbcDsnEditor/DSNEditorForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public DsnEditorForm(
numericUpDownFetchSize.Text = Builder.ContainsKey("MaxFetchSize") ? Builder["MaxFetchSize"].ToString().StripBraces() : "1000";
numericUpDownBodySize.Text = Builder.ContainsKey("MaxBodySizeMB") ? Builder["MaxBodySizeMB"].ToString().StripBraces() : "100";
comboBoxFloatsFormat.Text = Builder.ContainsKey("ScientificFloats") ? Builder["ScientificFloats"].ToString().StripBraces() : "default";
comboBoxDataEncoding.Text = Builder.ContainsKey("Packing") ? Builder["Packing"].ToString() : "JSON";
comboBoxDataEncoding.Text = Builder.ContainsKey("Packing") ? Builder["Packing"].ToString() : "CBOR";
comboBoxDataCompression.Text = Builder.ContainsKey("Compression") ? Builder["Compression"].ToString() : "auto";

string[] noes = {"no", "false", "0"};
Expand Down
1 change: 1 addition & 0 deletions test/connected_dbc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ void ConnectedDBC::assertRequest(const char *params, const char *tz)
JSON_KEY_VERSION "\"%s\""
JSON_KEY_VAL_MODE
JSON_KEY_CLT_ID
JSON_KEY_BINARY_FMT "false"
"}";
char expect[1024];
int n;
Expand Down