]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/lib/nodejs/lib/thrift/header_protocol.js
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / thrift / lib / nodejs / lib / thrift / header_protocol.js
CommitLineData
f67539c2
TL
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 */
19var util = require('util');
20var TBinaryProtocol = require('./binary_protocol');
21var TCompactProtocol = require('./compact_protocol');
22var THeaderTransport = require('./header_transport');
23
24var ProtocolMap = {};
25ProtocolMap[THeaderTransport.SubprotocolId.BINARY] = TBinaryProtocol;
26ProtocolMap[THeaderTransport.SubprotocolId.COMPACT] = TCompactProtocol;
27
28module.exports = THeaderProtocol;
29
30function THeaderProtocolError(message) {
31 Error.call(this);
32 Error.captureStackTrace(this, this.constructor);
33 this.name = this.constructor.name;
34 this.message = message;
35}
36
37util.inherits(THeaderProtocolError, Error);
38
39/**
40 * A framed protocol with headers.
41 *
42 * THeaderProtocol frames other Thrift protocols and adds support for
43 * optional out-of-band headers. The currently supported subprotocols are
44 * TBinaryProtocol and TCompactProtocol. It can currently only be used with
45 * transports that inherit THeaderTransport.
46 *
47 * THeaderProtocol does not currently support THTTPServer, TNonblockingServer,
48 * or TProcessPoolServer.
49 *
50 * See doc/specs/HeaderFormat.md for details of the wire format.
51 */
52function THeaderProtocol(trans) {
53 if (!(trans instanceof THeaderTransport)) {
54 throw new THeaderProtocolError(
55 'Only transports that inherit THeaderTransport can be' +
56 ' used with THeaderProtocol'
57 );
58 }
59 this.trans = trans;
60 this.setProtocol();
61};
62
63THeaderProtocol.prototype.flush = function() {
64 // Headers must be written prior to flushing because because
65 // you need to calculate the length of the payload for the length
66 // field of the header
67 this.trans.writeHeaders();
68 return this.trans.flush();
69};
70
71THeaderProtocol.prototype.writeMessageBegin = function(name, type, seqid) {
72 return this.protocol.writeMessageBegin(name, type, seqid);
73};
74
75THeaderProtocol.prototype.writeMessageEnd = function() {
76 return this.protocol.writeMessageEnd();
77};
78
79THeaderProtocol.prototype.writeStructBegin = function(name) {
80 return this.protocol.writeStructBegin(name);
81};
82
83THeaderProtocol.prototype.writeStructEnd = function() {
84 return this.protocol.writeStructEnd();
85};
86
87THeaderProtocol.prototype.writeFieldBegin = function(name, type, id) {
88 return this.protocol.writeFieldBegin(name, type, id);
89}
90
91THeaderProtocol.prototype.writeFieldEnd = function() {
92 return this.protocol.writeFieldEnd();
93};
94
95THeaderProtocol.prototype.writeFieldStop = function() {
96 return this.protocol.writeFieldStop();
97};
98
99THeaderProtocol.prototype.writeMapBegin = function(ktype, vtype, size) {
100 return this.protocol.writeMapBegin(ktype, vtype, size);
101};
102
103THeaderProtocol.prototype.writeMapEnd = function() {
104 return this.protocol.writeMapEnd();
105};
106
107THeaderProtocol.prototype.writeListBegin = function(etype, size) {
108 return this.protocol.writeListBegin(etype, size);
109};
110
111THeaderProtocol.prototype.writeListEnd = function() {
112 return this.protocol.writeListEnd();
113};
114
115THeaderProtocol.prototype.writeSetBegin = function(etype, size) {
116 return this.protocol.writeSetBegin(etype, size);
117};
118
119THeaderProtocol.prototype.writeSetEnd = function() {
120 return this.protocol.writeSetEnd();
121};
122
123THeaderProtocol.prototype.writeBool = function(b) {
124 return this.protocol.writeBool(b);
125};
126
127THeaderProtocol.prototype.writeByte = function(b) {
128 return this.protocol.writeByte(b);
129};
130
131THeaderProtocol.prototype.writeI16 = function(i16) {
132 return this.protocol.writeI16(i16);
133};
134
135THeaderProtocol.prototype.writeI32 = function(i32) {
136 return this.protocol.writeI32(i32);
137};
138
139THeaderProtocol.prototype.writeI64 = function(i64) {
140 return this.protocol.writeI64(i64);
141};
142
143THeaderProtocol.prototype.writeDouble = function(dub) {
144 return this.protocol.writeDouble(dub);
145};
146
147THeaderProtocol.prototype.writeStringOrBinary = function(name, encoding, arg) {
148 return this.protocol.writeStringOrBinary(name, encoding, arg);
149};
150
151THeaderProtocol.prototype.writeString = function(arg) {
152 return this.protocol.writeString(arg);
153};
154
155THeaderProtocol.prototype.writeBinary = function(arg) {
156 return this.protocol.writeBinary(arg);
157};
158
159THeaderProtocol.prototype.readMessageBegin = function() {
160 this.trans.readHeaders();
161 this.setProtocol();
162 return this.protocol.readMessageBegin();
163};
164
165THeaderProtocol.prototype.readMessageEnd = function() {
166 return this.protocol.readMessageEnd();
167};
168
169THeaderProtocol.prototype.readStructBegin = function() {
170 return this.protocol.readStructBegin();
171};
172
173THeaderProtocol.prototype.readStructEnd = function() {
174 return this.protocol.readStructEnd();
175};
176
177THeaderProtocol.prototype.readFieldBegin = function() {
178 return this.protocol.readFieldBegin();
179};
180
181THeaderProtocol.prototype.readFieldEnd = function() {
182 return this.protocol.readFieldEnd();
183};
184
185THeaderProtocol.prototype.readMapBegin = function() {
186 return this.protocol.readMapBegin();
187};
188
189THeaderProtocol.prototype.readMapEnd = function() {
190 return this.protocol.readMapEnd();
191};
192
193THeaderProtocol.prototype.readListBegin = function() {
194 return this.protocol.readListBegin();
195};
196
197THeaderProtocol.prototype.readListEnd = function() {
198 return this.protocol.readListEnd();
199};
200
201THeaderProtocol.prototype.readSetBegin = function() {
202 return this.protocol.readSetBegin();
203};
204
205THeaderProtocol.prototype.readSetEnd = function() {
206 return this.protocol.readSetEnd();
207};
208
209THeaderProtocol.prototype.readBool = function() {
210 return this.protocol.readBool();
211};
212
213THeaderProtocol.prototype.readByte = function() {
214 return this.protocol.readByte();
215};
216
217THeaderProtocol.prototype.readI16 = function() {
218 return this.protocol.readI16();
219};
220
221THeaderProtocol.prototype.readI32 = function() {
222 return this.protocol.readI32();
223};
224
225THeaderProtocol.prototype.readI64 = function() {
226 return this.protocol.readI64();
227};
228
229THeaderProtocol.prototype.readDouble = function() {
230 return this.protocol.readDouble();
231};
232
233THeaderProtocol.prototype.readBinary = function() {
234 return this.protocol.readBinary();
235};
236
237THeaderProtocol.prototype.readString = function() {
238 return this.protocol.readString();
239};
240
241THeaderProtocol.prototype.getTransport = function() {
242 return this.trans;
243};
244
245THeaderProtocol.prototype.skip = function(type) {
246 return this.protocol.skip(type);
247};
248
249THeaderProtocol.prototype.setProtocol = function(subProtocolId) {
250 var subProtocolId = this.trans.getProtocolId();
251 if (!ProtocolMap[subProtocolId]) {
252 throw new THeaderProtocolError('Headers not supported for protocol ' + subProtocolId);
253 }
254
255 this.protocol = new ProtocolMap[subProtocolId](this.trans);
256};