Skip to content

Commit c6639ab

Browse files
authored
switch to CBOR as default packing mode (#216)
This commit switches the default packing mode from JSON to CBOR. It also always adds the "binary_encoding" field to the REST requests, which is how the server decides what to answer with (the ES/SQL plugin overrides the Accept HTTP header).
1 parent 0bc94e9 commit c6639ab

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

driver/queries.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,11 +2986,16 @@ static SQLRETURN statement_len_cbor(esodbc_stmt_st *stmt, size_t *enc_len,
29862986
bodylen += cbor_str_obj_len(version.cnt);
29872987
*keys += 4; /* field_m._val., idx._inc._frozen, time_zone, version */
29882988
}
2989+
/* mode */
29892990
bodylen += cbor_str_obj_len(sizeof(REQ_KEY_MODE) - 1);
29902991
bodylen += cbor_str_obj_len(sizeof(REQ_VAL_MODE) - 1);
2992+
/* client_id */
29912993
bodylen += cbor_str_obj_len(sizeof(REQ_KEY_CLT_ID) - 1);
29922994
bodylen += cbor_str_obj_len(sizeof(REQ_VAL_CLT_ID) - 1);
2993-
*keys += 2; /* mode, client_id */
2995+
/* binary_format */
2996+
bodylen += cbor_str_obj_len(sizeof(REQ_KEY_BINARY_FMT) - 1);
2997+
bodylen += CBOR_OBJ_BOOL_LEN;
2998+
*keys += 3; /* mode, client_id, binary_format */
29942999
/* TODO: request_/page_timeout */
29953000

29963001
*enc_len = bodylen;
@@ -3048,8 +3053,10 @@ static SQLRETURN statement_len_json(esodbc_stmt_st *stmt, size_t *outlen)
30483053
bodylen += sizeof(JSON_KEY_VERSION) - 1;
30493054
bodylen += version.cnt + /* 2x`"` */2;
30503055
}
3051-
bodylen += sizeof(JSON_KEY_VAL_MODE) - 1; /* "mode": "ODBC" */
3052-
bodylen += sizeof(JSON_KEY_CLT_ID) - 1; /* "client_id": "odbcXX" */
3056+
bodylen += sizeof(JSON_KEY_VAL_MODE) - 1; /* "mode": */
3057+
bodylen += sizeof(JSON_KEY_CLT_ID) - 1; /* "client_id": */
3058+
bodylen += sizeof(JSON_KEY_BINARY_FMT) - 1; /* "binary_format": false */
3059+
bodylen += sizeof("false") - 1;
30533060
/* TODO: request_/page_timeout */
30543061
bodylen += 1; /* } */
30553062

@@ -3342,6 +3349,11 @@ static SQLRETURN serialize_to_cbor(esodbc_stmt_st *stmt, cstr_st *dest,
33423349
err = cbor_encode_text_string(&map, REQ_VAL_CLT_ID,
33433350
sizeof(REQ_VAL_CLT_ID) - 1);
33443351
FAIL_ON_CBOR_ERR(stmt, err);
3352+
/* binary_format: true (false means JSON) */
3353+
err = cbor_encode_text_string(&map, REQ_KEY_BINARY_FMT,
3354+
sizeof(REQ_KEY_BINARY_FMT) - 1);
3355+
FAIL_ON_CBOR_ERR(stmt, err);
3356+
err = cbor_encode_boolean(&map, TRUE);
33453357

33463358
err = cbor_encoder_close_container(&encoder, &map);
33473359
FAIL_ON_CBOR_ERR(stmt, err);
@@ -3458,6 +3470,10 @@ static SQLRETURN serialize_to_json(esodbc_stmt_st *stmt, cstr_st *dest)
34583470
/* "client_id": "odbcXX" */
34593471
memcpy(body + pos, JSON_KEY_CLT_ID, sizeof(JSON_KEY_CLT_ID) - 1);
34603472
pos += sizeof(JSON_KEY_CLT_ID) - 1;
3473+
/* "binary_format": false (true means CBOR) */
3474+
memcpy(body + pos, JSON_KEY_BINARY_FMT, sizeof(JSON_KEY_BINARY_FMT) - 1);
3475+
pos += sizeof(JSON_KEY_BINARY_FMT) - 1;
3476+
pos += copy_bool_val(body + pos, FALSE);
34613477
body[pos ++] = '}';
34623478

34633479
/* check that the buffer hasn't been overrun. it can be used less than

driver/queries.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ SQLRETURN EsSQLRowCount(_In_ SQLHSTMT StatementHandle, _Out_ SQLLEN *RowCount);
142142
#define REQ_KEY_MULTIVAL "field_multi_value_leniency"
143143
#define REQ_KEY_IDX_FROZEN "index_include_frozen"
144144
#define REQ_KEY_TIMEZONE "time_zone"
145+
#define REQ_KEY_BINARY_FMT "binary_format"
145146
/* keys for the "params" argument */
146147
#define REQ_KEY_PARAM_TYPE "type"
147148
#define REQ_KEY_PARAM_VAL "value"
@@ -171,6 +172,7 @@ SQLRETURN EsSQLRowCount(_In_ SQLHSTMT StatementHandle, _Out_ SQLLEN *RowCount);
171172
#define JSON_KEY_MULTIVAL ", \"" REQ_KEY_MULTIVAL "\": " /* n-th */
172173
#define JSON_KEY_IDX_FROZEN ", \"" REQ_KEY_IDX_FROZEN "\": " /* n-th */
173174
#define JSON_KEY_TIMEZONE ", \"" REQ_KEY_TIMEZONE "\": " /* n-th key */
175+
#define JSON_KEY_BINARY_FMT ", \"" REQ_KEY_BINARY_FMT "\": " /* n-th key */
174176

175177
#define JSON_VAL_TIMEZONE_Z "\"" REQ_VAL_TIMEZONE_Z "\""
176178

dsneditor/EsOdbcDsnEditor/DSNEditorForm.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dsneditor/EsOdbcDsnEditor/DSNEditorForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public DsnEditorForm(
157157
numericUpDownFetchSize.Text = Builder.ContainsKey("MaxFetchSize") ? Builder["MaxFetchSize"].ToString().StripBraces() : "1000";
158158
numericUpDownBodySize.Text = Builder.ContainsKey("MaxBodySizeMB") ? Builder["MaxBodySizeMB"].ToString().StripBraces() : "100";
159159
comboBoxFloatsFormat.Text = Builder.ContainsKey("ScientificFloats") ? Builder["ScientificFloats"].ToString().StripBraces() : "default";
160-
comboBoxDataEncoding.Text = Builder.ContainsKey("Packing") ? Builder["Packing"].ToString() : "JSON";
160+
comboBoxDataEncoding.Text = Builder.ContainsKey("Packing") ? Builder["Packing"].ToString() : "CBOR";
161161
comboBoxDataCompression.Text = Builder.ContainsKey("Compression") ? Builder["Compression"].ToString() : "auto";
162162

163163
string[] noes = {"no", "false", "0"};

test/connected_dbc.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ void ConnectedDBC::assertRequest(const char *params, const char *tz)
113113
JSON_KEY_VERSION "\"%s\""
114114
JSON_KEY_VAL_MODE
115115
JSON_KEY_CLT_ID
116+
JSON_KEY_BINARY_FMT "false"
116117
"}";
117118
char expect[1024];
118119
int n;

0 commit comments

Comments
 (0)