Skip to content

Commit d70c20a

Browse files
committed
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). (cherry picked from commit c6639ab)
1 parent 3c62da7 commit d70c20a

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

driver/queries.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2976,11 +2976,16 @@ static SQLRETURN statement_len_cbor(esodbc_stmt_st *stmt, size_t *enc_len,
29762976
bodylen += cbor_str_obj_len(tz_param.cnt); /* lax len */
29772977
*keys += 3; /* field_m._val., idx._inc._frozen, time_zone */
29782978
}
2979+
/* mode */
29792980
bodylen += cbor_str_obj_len(sizeof(REQ_KEY_MODE) - 1);
29802981
bodylen += cbor_str_obj_len(sizeof(REQ_VAL_MODE) - 1);
2982+
/* client_id */
29812983
bodylen += cbor_str_obj_len(sizeof(REQ_KEY_CLT_ID) - 1);
29822984
bodylen += cbor_str_obj_len(sizeof(REQ_VAL_CLT_ID) - 1);
2983-
*keys += 2; /* mode, client_id */
2985+
/* binary_format */
2986+
bodylen += cbor_str_obj_len(sizeof(REQ_KEY_BINARY_FMT) - 1);
2987+
bodylen += CBOR_OBJ_BOOL_LEN;
2988+
*keys += 3; /* mode, client_id, binary_format */
29842989
/* TODO: request_/page_timeout */
29852990

29862991
*enc_len = bodylen;
@@ -3037,6 +3042,8 @@ static SQLRETURN statement_len_json(esodbc_stmt_st *stmt, size_t *outlen)
30373042
}
30383043
bodylen += sizeof(JSON_KEY_VAL_MODE) - 1; /* "mode": */
30393044
bodylen += sizeof(JSON_KEY_CLT_ID) - 1; /* "client_id": */
3045+
bodylen += sizeof(JSON_KEY_BINARY_FMT) - 1; /* "binary_format": false */
3046+
bodylen += sizeof("false") - 1;
30403047
/* TODO: request_/page_timeout */
30413048
bodylen += 1; /* } */
30423049

@@ -3323,6 +3330,11 @@ static SQLRETURN serialize_to_cbor(esodbc_stmt_st *stmt, cstr_st *dest,
33233330
err = cbor_encode_text_string(&map, REQ_VAL_CLT_ID,
33243331
sizeof(REQ_VAL_CLT_ID) - 1);
33253332
FAIL_ON_CBOR_ERR(stmt, err);
3333+
/* binary_format: true (false means JSON) */
3334+
err = cbor_encode_text_string(&map, REQ_KEY_BINARY_FMT,
3335+
sizeof(REQ_KEY_BINARY_FMT) - 1);
3336+
FAIL_ON_CBOR_ERR(stmt, err);
3337+
err = cbor_encode_boolean(&map, TRUE);
33263338

33273339
err = cbor_encoder_close_container(&encoder, &map);
33283340
FAIL_ON_CBOR_ERR(stmt, err);
@@ -3431,6 +3443,10 @@ static SQLRETURN serialize_to_json(esodbc_stmt_st *stmt, cstr_st *dest)
34313443
pos += sizeof(JSON_KEY_VAL_MODE) - 1;
34323444
memcpy(body + pos, JSON_KEY_CLT_ID, sizeof(JSON_KEY_CLT_ID) - 1);
34333445
pos += sizeof(JSON_KEY_CLT_ID) - 1;
3446+
/* "binary_format": false (true means CBOR) */
3447+
memcpy(body + pos, JSON_KEY_BINARY_FMT, sizeof(JSON_KEY_BINARY_FMT) - 1);
3448+
pos += sizeof(JSON_KEY_BINARY_FMT) - 1;
3449+
pos += copy_bool_val(body + pos, FALSE);
34343450
body[pos ++] = '}';
34353451

34363452
/* 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
@@ -104,6 +104,7 @@ void ConnectedDBC::assertRequest(const char *params, const char *tz)
104104
JSON_KEY_TIMEZONE "%s%s%s"
105105
JSON_KEY_VAL_MODE
106106
JSON_KEY_CLT_ID
107+
JSON_KEY_BINARY_FMT "false"
107108
"}";
108109
char expect[1024];
109110
int n;

0 commit comments

Comments
 (0)