@databricks/sql 1.4.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/README.md +1 -1
  2. package/dist/DBSQLClient.d.ts +15 -8
  3. package/dist/DBSQLClient.js +76 -81
  4. package/dist/DBSQLClient.js.map +1 -1
  5. package/dist/DBSQLOperation/FetchResultsHelper.d.ts +3 -3
  6. package/dist/DBSQLOperation/FetchResultsHelper.js +4 -3
  7. package/dist/DBSQLOperation/FetchResultsHelper.js.map +1 -1
  8. package/dist/DBSQLOperation/index.d.ts +19 -10
  9. package/dist/DBSQLOperation/index.js +178 -47
  10. package/dist/DBSQLOperation/index.js.map +1 -1
  11. package/dist/DBSQLParameter.d.ts +33 -0
  12. package/dist/DBSQLParameter.js +87 -0
  13. package/dist/DBSQLParameter.js.map +1 -0
  14. package/dist/DBSQLSession.d.ts +10 -7
  15. package/dist/DBSQLSession.js +188 -23
  16. package/dist/DBSQLSession.js.map +1 -1
  17. package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.d.ts +3 -3
  18. package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.js +3 -4
  19. package/dist/connection/auth/DatabricksOAuth/AuthorizationCode.js.map +1 -1
  20. package/dist/connection/auth/DatabricksOAuth/OAuthManager.d.ts +11 -3
  21. package/dist/connection/auth/DatabricksOAuth/OAuthManager.js +74 -20
  22. package/dist/connection/auth/DatabricksOAuth/OAuthManager.js.map +1 -1
  23. package/dist/connection/auth/DatabricksOAuth/index.d.ts +4 -6
  24. package/dist/connection/auth/DatabricksOAuth/index.js +1 -1
  25. package/dist/connection/auth/DatabricksOAuth/index.js.map +1 -1
  26. package/dist/connection/auth/PlainHttpAuthentication.d.ts +6 -3
  27. package/dist/connection/auth/PlainHttpAuthentication.js +1 -0
  28. package/dist/connection/auth/PlainHttpAuthentication.js.map +1 -1
  29. package/dist/connection/connections/HttpConnection.d.ts +16 -9
  30. package/dist/connection/connections/HttpConnection.js +60 -51
  31. package/dist/connection/connections/HttpConnection.js.map +1 -1
  32. package/dist/connection/connections/ThriftHttpConnection.d.ts +38 -0
  33. package/dist/connection/connections/ThriftHttpConnection.js +134 -0
  34. package/dist/connection/connections/ThriftHttpConnection.js.map +1 -0
  35. package/dist/connection/contracts/IAuthentication.d.ts +2 -2
  36. package/dist/connection/contracts/IConnectionOptions.d.ts +17 -19
  37. package/dist/connection/contracts/IConnectionProvider.d.ts +6 -3
  38. package/dist/contracts/IClientContext.d.ts +10 -0
  39. package/dist/{connection/contracts/IThriftConnection.js → contracts/IClientContext.js} +1 -1
  40. package/dist/contracts/IClientContext.js.map +1 -0
  41. package/dist/contracts/IDBSQLClient.d.ts +4 -0
  42. package/dist/contracts/IDBSQLSession.d.ts +34 -0
  43. package/dist/contracts/IDriver.d.ts +24 -0
  44. package/dist/contracts/IDriver.js +3 -0
  45. package/dist/contracts/IDriver.js.map +1 -0
  46. package/dist/errors/OperationStateError.js +2 -1
  47. package/dist/errors/OperationStateError.js.map +1 -1
  48. package/dist/errors/ParameterError.d.ts +2 -0
  49. package/dist/errors/ParameterError.js +6 -0
  50. package/dist/errors/ParameterError.js.map +1 -0
  51. package/dist/errors/StagingError.d.ts +2 -0
  52. package/dist/errors/StagingError.js +6 -0
  53. package/dist/errors/StagingError.js.map +1 -0
  54. package/dist/hive/HiveDriver.d.ts +8 -5
  55. package/dist/hive/HiveDriver.js +23 -23
  56. package/dist/hive/HiveDriver.js.map +1 -1
  57. package/dist/index.d.ts +2 -1
  58. package/dist/index.js +4 -1
  59. package/dist/index.js.map +1 -1
  60. package/dist/result/ArrowResult.d.ts +3 -1
  61. package/dist/result/ArrowResult.js +6 -4
  62. package/dist/result/ArrowResult.js.map +1 -1
  63. package/dist/result/CloudFetchResult.d.ts +2 -1
  64. package/dist/result/CloudFetchResult.js +5 -3
  65. package/dist/result/CloudFetchResult.js.map +1 -1
  66. package/dist/result/JsonResult.d.ts +3 -1
  67. package/dist/result/JsonResult.js +2 -1
  68. package/dist/result/JsonResult.js.map +1 -1
  69. package/dist/utils/index.d.ts +1 -2
  70. package/dist/utils/index.js +1 -3
  71. package/dist/utils/index.js.map +1 -1
  72. package/dist/version.d.ts +1 -1
  73. package/dist/version.js +1 -1
  74. package/package.json +3 -5
  75. package/thrift/TCLIService.d.ts +2 -1
  76. package/thrift/TCLIService.js +1 -1
  77. package/thrift/TCLIService_types.d.ts +11 -3
  78. package/thrift/TCLIService_types.js +41 -4
  79. package/dist/DBSQLOperation/CompleteOperationHelper.d.ts +0 -13
  80. package/dist/DBSQLOperation/CompleteOperationHelper.js +0 -56
  81. package/dist/DBSQLOperation/CompleteOperationHelper.js.map +0 -1
  82. package/dist/DBSQLOperation/OperationStatusHelper.d.ts +0 -16
  83. package/dist/DBSQLOperation/OperationStatusHelper.js +0 -138
  84. package/dist/DBSQLOperation/OperationStatusHelper.js.map +0 -1
  85. package/dist/DBSQLOperation/SchemaHelper.d.ts +0 -13
  86. package/dist/DBSQLOperation/SchemaHelper.js +0 -74
  87. package/dist/DBSQLOperation/SchemaHelper.js.map +0 -1
  88. package/dist/connection/contracts/IThriftConnection.d.ts +0 -4
  89. package/dist/connection/contracts/IThriftConnection.js.map +0 -1
  90. package/dist/node_modules/thrift/LICENSE +0 -306
  91. package/dist/node_modules/thrift/README.md +0 -210
  92. package/dist/node_modules/thrift/lib/nodejs/README.md +0 -142
  93. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/binary.js +0 -168
  94. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/binary_protocol.js +0 -367
  95. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/browser.js +0 -49
  96. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/buffered_transport.js +0 -186
  97. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/compact_protocol.js +0 -915
  98. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/connection.js +0 -396
  99. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/create_client.js +0 -54
  100. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/framed_transport.js +0 -185
  101. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/header_protocol.js +0 -258
  102. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/header_transport.js +0 -341
  103. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/http_connection.js +0 -292
  104. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/index.js +0 -76
  105. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/input_buffer_underrun_error.js +0 -32
  106. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/int64_util.js +0 -91
  107. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/json_parse.js +0 -299
  108. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/json_protocol.js +0 -799
  109. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/log.js +0 -87
  110. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/multiplexed_processor.js +0 -63
  111. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/multiplexed_protocol.js +0 -73
  112. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/protocol.js +0 -22
  113. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/server.js +0 -123
  114. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/thrift.js +0 -241
  115. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/transport.js +0 -22
  116. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/web_server.js +0 -567
  117. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/ws_connection.js +0 -286
  118. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/ws_transport.js +0 -206
  119. package/dist/node_modules/thrift/lib/nodejs/lib/thrift/xhr_connection.js +0 -280
  120. package/dist/node_modules/thrift/package.json +0 -72
  121. package/dist/utils/areHeadersEqual.d.ts +0 -2
  122. package/dist/utils/areHeadersEqual.js +0 -49
  123. package/dist/utils/areHeadersEqual.js.map +0 -1
@@ -1,142 +0,0 @@
1
- Thrift Node.js Library
2
- =========================
3
-
4
- License
5
- -------
6
- Licensed to the Apache Software Foundation (ASF) under one
7
- or more contributor license agreements. See the NOTICE file
8
- distributed with this work for additional information
9
- regarding copyright ownership. The ASF licenses this file
10
- to you under the Apache License, Version 2.0 (the
11
- "License"); you may not use this file except in compliance
12
- with the License. You may obtain a copy of the License at
13
-
14
- http://www.apache.org/licenses/LICENSE-2.0
15
-
16
- Unless required by applicable law or agreed to in writing,
17
- software distributed under the License is distributed on an
18
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19
- KIND, either express or implied. See the License for the
20
- specific language governing permissions and limitations
21
- under the License.
22
-
23
- ## Compatibility
24
-
25
- node version 6 or later is required
26
-
27
- ## Install
28
-
29
- npm install thrift
30
-
31
- ## Thrift Compiler
32
-
33
- You can compile IDL sources for Node.js with the following command:
34
-
35
- thrift --gen js:node thrift_file
36
-
37
- ## Cassandra Client Example:
38
-
39
- Here is a Cassandra example:
40
-
41
- ```js
42
- var thrift = require('thrift'),
43
- Cassandra = require('./gen-nodejs/Cassandra')
44
- ttypes = require('./gen-nodejs/cassandra_types');
45
-
46
- var connection = thrift.createConnection("localhost", 9160),
47
- client = thrift.createClient(Cassandra, connection);
48
-
49
- connection.on('error', function(err) {
50
- console.error(err);
51
- });
52
-
53
- client.get_slice("Keyspace", "key", new ttypes.ColumnParent({column_family: "ExampleCF"}), new ttypes.SlicePredicate({slice_range: new ttypes.SliceRange({start: '', finish: ''})}), ttypes.ConsistencyLevel.ONE, function(err, data) {
54
- if (err) {
55
- // handle err
56
- } else {
57
- // data == [ttypes.ColumnOrSuperColumn, ...]
58
- }
59
- connection.end();
60
- });
61
- ```
62
-
63
- <a name="int64"></a>
64
- ## Int64
65
-
66
- Since JavaScript represents all numbers as doubles, int64 values cannot be accurately represented naturally. To solve this, int64 values in responses will be wrapped with Thrift.Int64 objects. The Int64 implementation used is [broofa/node-int64](https://github.com/broofa/node-int64).
67
-
68
- ## Client and server examples
69
-
70
- Several example clients and servers are included in the thrift/lib/nodejs/examples folder and the cross language tutorial thrift/tutorial/nodejs folder.
71
-
72
- ## Use on browsers
73
-
74
- You can use code generated with js:node on browsers with Webpack. Here is an example.
75
-
76
- thrift --gen js:node,ts,es6,with_ns
77
-
78
- ```javascript
79
- import * as thrift from 'thrift';
80
- import { MyServiceClient } from '../gen-nodejs/MyService';
81
-
82
- let host = window.location.hostname;
83
- let port = 443;
84
- let opts = {
85
- transport: thrift.TBufferedTransport,
86
- protocol: thrift.TJSONProtocol,
87
- headers: {
88
- 'Content-Type': 'application/vnd.apache.thrift.json',
89
- },
90
- https: true,
91
- path: '/url/path',
92
- useCORS: true,
93
- };
94
-
95
- let connection = thrift.createXHRConnection(host, port, opts);
96
- let thriftClient = thrift.createXHRClient(MyServiceClient, connection);
97
-
98
- connection.on('error', (err) => {
99
- console.error(err);
100
- });
101
-
102
- thriftClient.myService(param)
103
- .then((result) => {
104
- console.log(result);
105
- })
106
- .catch((err) => {
107
- ....
108
- });
109
- ```
110
-
111
- Bundlers, like webpack, will use thrift/browser.js by default because of the
112
- `"browser": "./lib/nodejs/lib/thrift/browser.js"` field in package.json.
113
-
114
- ### Browser example with WebSocket, BufferedTransport and BinaryProtocol
115
- ```javascript
116
- import thrift from 'thrift';
117
- import { MyServiceClient } from '../gen-nodejs/MyService';
118
-
119
- const host = window.location.hostname;
120
- const port = 9090;
121
- const opts = {
122
- transport: thrift.TBufferedTransport,
123
- protocol: thrift.TBinaryProtocol
124
- }
125
- const connection = thrift.createWSConnection(host, port, opts);
126
- connection.open();
127
- const thriftClient = thrift.createWSClient(MyServiceClient, connection);
128
-
129
- connection.on('error', (err) => {
130
- console.error(err);
131
- });
132
-
133
- thriftClient.myService(param)
134
- .then((result) => {
135
- console.log(result);
136
- })
137
- .catch((err) => {
138
- ....
139
- });
140
- ```
141
-
142
-
@@ -1,168 +0,0 @@
1
- /*
2
- * Licensed to the Apache Software Foundation (ASF) under one
3
- * or more contributor license agreements. See the NOTICE file
4
- * distributed with this work for additional information
5
- * regarding copyright ownership. The ASF licenses this file
6
- * to you under the Apache License, Version 2.0 (the
7
- * "License"); you may not use this file except in compliance
8
- * with the License. You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing,
13
- * software distributed under the License is distributed on an
14
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- * KIND, either express or implied. See the License for the
16
- * specific language governing permissions and limitations
17
- * under the License.
18
- */
19
-
20
- var POW_8 = Math.pow(2, 8);
21
- var POW_16 = Math.pow(2, 16);
22
- var POW_24 = Math.pow(2, 24);
23
- var POW_32 = Math.pow(2, 32);
24
- var POW_40 = Math.pow(2, 40);
25
- var POW_48 = Math.pow(2, 48);
26
- var POW_52 = Math.pow(2, 52);
27
- var POW_1022 = Math.pow(2, 1022);
28
-
29
- exports.readByte = function(b){
30
- return b > 127 ? b-256 : b;
31
- };
32
-
33
- exports.readI16 = function(buff, off) {
34
- off = off || 0;
35
- var v = buff[off + 1];
36
- v += buff[off] << 8;
37
- if (buff[off] & 128) {
38
- v -= POW_16;
39
- }
40
- return v;
41
- };
42
-
43
- exports.readI32 = function(buff, off) {
44
- off = off || 0;
45
- var v = buff[off + 3];
46
- v += buff[off + 2] << 8;
47
- v += buff[off + 1] << 16;
48
- v += buff[off] * POW_24;
49
- if (buff[off] & 0x80) {
50
- v -= POW_32;
51
- }
52
- return v;
53
- };
54
-
55
- exports.writeI16 = function(buff, v) {
56
- buff[1] = v & 0xff;
57
- v >>= 8;
58
- buff[0] = v & 0xff;
59
- return buff;
60
- };
61
-
62
- exports.writeI32 = function(buff, v) {
63
- buff[3] = v & 0xff;
64
- v >>= 8;
65
- buff[2] = v & 0xff;
66
- v >>= 8;
67
- buff[1] = v & 0xff;
68
- v >>= 8;
69
- buff[0] = v & 0xff;
70
- return buff;
71
- };
72
-
73
- exports.readDouble = function(buff, off) {
74
- off = off || 0;
75
- var signed = buff[off] & 0x80;
76
- var e = (buff[off+1] & 0xF0) >> 4;
77
- e += (buff[off] & 0x7F) << 4;
78
-
79
- var m = buff[off+7];
80
- m += buff[off+6] << 8;
81
- m += buff[off+5] << 16;
82
- m += buff[off+4] * POW_24;
83
- m += buff[off+3] * POW_32;
84
- m += buff[off+2] * POW_40;
85
- m += (buff[off+1] & 0x0F) * POW_48;
86
-
87
- switch (e) {
88
- case 0:
89
- e = -1022;
90
- break;
91
- case 2047:
92
- return m ? NaN : (signed ? -Infinity : Infinity);
93
- default:
94
- m += POW_52;
95
- e -= 1023;
96
- }
97
-
98
- if (signed) {
99
- m *= -1;
100
- }
101
-
102
- return m * Math.pow(2, e - 52);
103
- };
104
-
105
- /*
106
- * Based on code from the jspack module:
107
- * http://code.google.com/p/jspack/
108
- */
109
- exports.writeDouble = function(buff, v) {
110
- var m, e, c;
111
-
112
- buff[0] = (v < 0 ? 0x80 : 0x00);
113
-
114
- v = Math.abs(v);
115
- if (v !== v) {
116
- // NaN, use QNaN IEEE format
117
- m = 2251799813685248;
118
- e = 2047;
119
- } else if (v === Infinity) {
120
- m = 0;
121
- e = 2047;
122
- } else {
123
- e = Math.floor(Math.log(v) / Math.LN2);
124
- c = Math.pow(2, -e);
125
- if (v * c < 1) {
126
- e--;
127
- c *= 2;
128
- }
129
-
130
- if (e + 1023 >= 2047)
131
- {
132
- // Overflow
133
- m = 0;
134
- e = 2047;
135
- }
136
- else if (e + 1023 >= 1)
137
- {
138
- // Normalized - term order matters, as Math.pow(2, 52-e) and v*Math.pow(2, 52) can overflow
139
- m = (v*c-1) * POW_52;
140
- e += 1023;
141
- }
142
- else
143
- {
144
- // Denormalized - also catches the '0' case, somewhat by chance
145
- m = (v * POW_1022) * POW_52;
146
- e = 0;
147
- }
148
- }
149
-
150
- buff[1] = (e << 4) & 0xf0;
151
- buff[0] |= (e >> 4) & 0x7f;
152
-
153
- buff[7] = m & 0xff;
154
- m = Math.floor(m / POW_8);
155
- buff[6] = m & 0xff;
156
- m = Math.floor(m / POW_8);
157
- buff[5] = m & 0xff;
158
- m = Math.floor(m / POW_8);
159
- buff[4] = m & 0xff;
160
- m >>= 8;
161
- buff[3] = m & 0xff;
162
- m >>= 8;
163
- buff[2] = m & 0xff;
164
- m >>= 8;
165
- buff[1] |= m & 0x0f;
166
-
167
- return buff;
168
- };
@@ -1,367 +0,0 @@
1
- /*
2
- * Licensed to the Apache Software Foundation (ASF) under one
3
- * or more contributor license agreements. See the NOTICE file
4
- * distributed with this work for additional information
5
- * regarding copyright ownership. The ASF licenses this file
6
- * to you under the Apache License, Version 2.0 (the
7
- * "License"); you may not use this file except in compliance
8
- * with the License. You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing,
13
- * software distributed under the License is distributed on an
14
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- * KIND, either express or implied. See the License for the
16
- * specific language governing permissions and limitations
17
- * under the License.
18
- */
19
-
20
- var log = require('./log');
21
- var binary = require('./binary');
22
- var Int64 = require('node-int64');
23
- var Thrift = require('./thrift');
24
- var Type = Thrift.Type;
25
-
26
- module.exports = TBinaryProtocol;
27
-
28
- // JavaScript supports only numeric doubles, therefore even hex values are always signed.
29
- // The largest integer value which can be represented in JavaScript is +/-2^53.
30
- // Bitwise operations convert numbers to 32 bit integers but perform sign extension
31
- // upon assigning values back to variables.
32
- var VERSION_MASK = -65536, // 0xffff0000
33
- VERSION_1 = -2147418112, // 0x80010000
34
- TYPE_MASK = 0x000000ff;
35
-
36
- TBinaryProtocol.VERSION_MASK = VERSION_MASK;
37
- TBinaryProtocol.VERSION_1 = VERSION_1;
38
- TBinaryProtocol.TYPE_MASK = TYPE_MASK
39
-
40
- function TBinaryProtocol(trans, strictRead, strictWrite) {
41
- this.trans = trans;
42
- this.strictRead = (strictRead !== undefined ? strictRead : false);
43
- this.strictWrite = (strictWrite !== undefined ? strictWrite : true);
44
- this._seqid = null;
45
- };
46
-
47
- TBinaryProtocol.prototype.flush = function() {
48
- return this.trans.flush();
49
- };
50
-
51
- TBinaryProtocol.prototype.writeMessageBegin = function(name, type, seqid) {
52
- if (this.strictWrite) {
53
- this.writeI32(VERSION_1 | type);
54
- this.writeString(name);
55
- this.writeI32(seqid);
56
- } else {
57
- this.writeString(name);
58
- this.writeByte(type);
59
- this.writeI32(seqid);
60
- }
61
- // Record client seqid to find callback again
62
- if (this._seqid !== null) {
63
- log.warning('SeqId already set', { 'name': name });
64
- } else {
65
- this._seqid = seqid;
66
- this.trans.setCurrSeqId(seqid);
67
- }
68
- };
69
-
70
- TBinaryProtocol.prototype.writeMessageEnd = function() {
71
- if (this._seqid !== null) {
72
- this._seqid = null;
73
- } else {
74
- log.warning('No seqid to unset');
75
- }
76
- };
77
-
78
- TBinaryProtocol.prototype.writeStructBegin = function(name) {
79
- };
80
-
81
- TBinaryProtocol.prototype.writeStructEnd = function() {
82
- };
83
-
84
- TBinaryProtocol.prototype.writeFieldBegin = function(name, type, id) {
85
- this.writeByte(type);
86
- this.writeI16(id);
87
- };
88
-
89
- TBinaryProtocol.prototype.writeFieldEnd = function() {
90
- };
91
-
92
- TBinaryProtocol.prototype.writeFieldStop = function() {
93
- this.writeByte(Type.STOP);
94
- };
95
-
96
- TBinaryProtocol.prototype.writeMapBegin = function(ktype, vtype, size) {
97
- this.writeByte(ktype);
98
- this.writeByte(vtype);
99
- this.writeI32(size);
100
- };
101
-
102
- TBinaryProtocol.prototype.writeMapEnd = function() {
103
- };
104
-
105
- TBinaryProtocol.prototype.writeListBegin = function(etype, size) {
106
- this.writeByte(etype);
107
- this.writeI32(size);
108
- };
109
-
110
- TBinaryProtocol.prototype.writeListEnd = function() {
111
- };
112
-
113
- TBinaryProtocol.prototype.writeSetBegin = function(etype, size) {
114
- this.writeByte(etype);
115
- this.writeI32(size);
116
- };
117
-
118
- TBinaryProtocol.prototype.writeSetEnd = function() {
119
- };
120
-
121
- TBinaryProtocol.prototype.writeBool = function(bool) {
122
- if (bool) {
123
- this.writeByte(1);
124
- } else {
125
- this.writeByte(0);
126
- }
127
- };
128
-
129
- TBinaryProtocol.prototype.writeByte = function(b) {
130
- this.trans.write(new Buffer([b]));
131
- };
132
-
133
- TBinaryProtocol.prototype.writeI16 = function(i16) {
134
- this.trans.write(binary.writeI16(new Buffer(2), i16));
135
- };
136
-
137
- TBinaryProtocol.prototype.writeI32 = function(i32) {
138
- this.trans.write(binary.writeI32(new Buffer(4), i32));
139
- };
140
-
141
- TBinaryProtocol.prototype.writeI64 = function(i64) {
142
- if (i64.buffer) {
143
- this.trans.write(i64.buffer);
144
- } else {
145
- this.trans.write(new Int64(i64).buffer);
146
- }
147
- };
148
-
149
- TBinaryProtocol.prototype.writeDouble = function(dub) {
150
- this.trans.write(binary.writeDouble(new Buffer(8), dub));
151
- };
152
-
153
- TBinaryProtocol.prototype.writeStringOrBinary = function(name, encoding, arg) {
154
- if (typeof(arg) === 'string') {
155
- this.writeI32(Buffer.byteLength(arg, encoding));
156
- this.trans.write(new Buffer(arg, encoding));
157
- } else if ((arg instanceof Buffer) ||
158
- (Object.prototype.toString.call(arg) == '[object Uint8Array]')) {
159
- // Buffers in Node.js under Browserify may extend UInt8Array instead of
160
- // defining a new object. We detect them here so we can write them
161
- // correctly
162
- this.writeI32(arg.length);
163
- this.trans.write(arg);
164
- } else {
165
- throw new Error(name + ' called without a string/Buffer argument: ' + arg);
166
- }
167
- };
168
-
169
- TBinaryProtocol.prototype.writeString = function(arg) {
170
- this.writeStringOrBinary('writeString', 'utf8', arg);
171
- };
172
-
173
- TBinaryProtocol.prototype.writeBinary = function(arg) {
174
- this.writeStringOrBinary('writeBinary', 'binary', arg);
175
- };
176
-
177
- TBinaryProtocol.prototype.readMessageBegin = function() {
178
- var sz = this.readI32();
179
- var type, name, seqid;
180
-
181
- if (sz < 0) {
182
- var version = sz & VERSION_MASK;
183
- if (version != VERSION_1) {
184
- throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.BAD_VERSION, "Bad version in readMessageBegin: " + sz);
185
- }
186
- type = sz & TYPE_MASK;
187
- name = this.readString();
188
- seqid = this.readI32();
189
- } else {
190
- if (this.strictRead) {
191
- throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.BAD_VERSION, "No protocol version header");
192
- }
193
- name = this.trans.read(sz);
194
- type = this.readByte();
195
- seqid = this.readI32();
196
- }
197
- return {fname: name, mtype: type, rseqid: seqid};
198
- };
199
-
200
- TBinaryProtocol.prototype.readMessageEnd = function() {
201
- };
202
-
203
- TBinaryProtocol.prototype.readStructBegin = function() {
204
- return {fname: ''};
205
- };
206
-
207
- TBinaryProtocol.prototype.readStructEnd = function() {
208
- };
209
-
210
- TBinaryProtocol.prototype.readFieldBegin = function() {
211
- var type = this.readByte();
212
- if (type == Type.STOP) {
213
- return {fname: null, ftype: type, fid: 0};
214
- }
215
- var id = this.readI16();
216
- return {fname: null, ftype: type, fid: id};
217
- };
218
-
219
- TBinaryProtocol.prototype.readFieldEnd = function() {
220
- };
221
-
222
- TBinaryProtocol.prototype.readMapBegin = function() {
223
- var ktype = this.readByte();
224
- var vtype = this.readByte();
225
- var size = this.readI32();
226
- return {ktype: ktype, vtype: vtype, size: size};
227
- };
228
-
229
- TBinaryProtocol.prototype.readMapEnd = function() {
230
- };
231
-
232
- TBinaryProtocol.prototype.readListBegin = function() {
233
- var etype = this.readByte();
234
- var size = this.readI32();
235
- return {etype: etype, size: size};
236
- };
237
-
238
- TBinaryProtocol.prototype.readListEnd = function() {
239
- };
240
-
241
- TBinaryProtocol.prototype.readSetBegin = function() {
242
- var etype = this.readByte();
243
- var size = this.readI32();
244
- return {etype: etype, size: size};
245
- };
246
-
247
- TBinaryProtocol.prototype.readSetEnd = function() {
248
- };
249
-
250
- TBinaryProtocol.prototype.readBool = function() {
251
- var b = this.readByte();
252
- if (b === 0) {
253
- return false;
254
- }
255
- return true;
256
- };
257
-
258
- TBinaryProtocol.prototype.readByte = function() {
259
- return this.trans.readByte();
260
- };
261
-
262
- TBinaryProtocol.prototype.readI16 = function() {
263
- return this.trans.readI16();
264
- };
265
-
266
- TBinaryProtocol.prototype.readI32 = function() {
267
- return this.trans.readI32();
268
- };
269
-
270
- TBinaryProtocol.prototype.readI64 = function() {
271
- var buff = this.trans.read(8);
272
- return new Int64(buff);
273
- };
274
-
275
- TBinaryProtocol.prototype.readDouble = function() {
276
- return this.trans.readDouble();
277
- };
278
-
279
- TBinaryProtocol.prototype.readBinary = function() {
280
- var len = this.readI32();
281
- if (len === 0) {
282
- return new Buffer(0);
283
- }
284
-
285
- if (len < 0) {
286
- throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.NEGATIVE_SIZE, "Negative binary size");
287
- }
288
- return this.trans.read(len);
289
- };
290
-
291
- TBinaryProtocol.prototype.readString = function() {
292
- var len = this.readI32();
293
- if (len === 0) {
294
- return "";
295
- }
296
-
297
- if (len < 0) {
298
- throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.NEGATIVE_SIZE, "Negative string size");
299
- }
300
- return this.trans.readString(len);
301
- };
302
-
303
- TBinaryProtocol.prototype.getTransport = function() {
304
- return this.trans;
305
- };
306
-
307
- TBinaryProtocol.prototype.skip = function(type) {
308
- switch (type) {
309
- case Type.BOOL:
310
- this.readBool();
311
- break;
312
- case Type.BYTE:
313
- this.readByte();
314
- break;
315
- case Type.I16:
316
- this.readI16();
317
- break;
318
- case Type.I32:
319
- this.readI32();
320
- break;
321
- case Type.I64:
322
- this.readI64();
323
- break;
324
- case Type.DOUBLE:
325
- this.readDouble();
326
- break;
327
- case Type.STRING:
328
- this.readString();
329
- break;
330
- case Type.STRUCT:
331
- this.readStructBegin();
332
- while (true) {
333
- var r = this.readFieldBegin();
334
- if (r.ftype === Type.STOP) {
335
- break;
336
- }
337
- this.skip(r.ftype);
338
- this.readFieldEnd();
339
- }
340
- this.readStructEnd();
341
- break;
342
- case Type.MAP:
343
- var mapBegin = this.readMapBegin();
344
- for (var i = 0; i < mapBegin.size; ++i) {
345
- this.skip(mapBegin.ktype);
346
- this.skip(mapBegin.vtype);
347
- }
348
- this.readMapEnd();
349
- break;
350
- case Type.SET:
351
- var setBegin = this.readSetBegin();
352
- for (var i2 = 0; i2 < setBegin.size; ++i2) {
353
- this.skip(setBegin.etype);
354
- }
355
- this.readSetEnd();
356
- break;
357
- case Type.LIST:
358
- var listBegin = this.readListBegin();
359
- for (var i3 = 0; i3 < listBegin.size; ++i3) {
360
- this.skip(listBegin.etype);
361
- }
362
- this.readListEnd();
363
- break;
364
- default:
365
- throw new Error("Invalid type: " + type);
366
- }
367
- };