]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/nodejs/lib/thrift/header_protocol.js
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
19 var util
= require('util');
20 var TBinaryProtocol
= require('./binary_protocol');
21 var TCompactProtocol
= require('./compact_protocol');
22 var THeaderTransport
= require('./header_transport');
25 ProtocolMap
[THeaderTransport
.SubprotocolId
.BINARY
] = TBinaryProtocol
;
26 ProtocolMap
[THeaderTransport
.SubprotocolId
.COMPACT
] = TCompactProtocol
;
28 module
.exports
= THeaderProtocol
;
30 function THeaderProtocolError(message
) {
32 Error
.captureStackTrace(this, this.constructor);
33 this.name
= this.constructor.name
;
34 this.message
= message
;
37 util
.inherits(THeaderProtocolError
, Error
);
40 * A framed protocol with headers.
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.
47 * THeaderProtocol does not currently support THTTPServer, TNonblockingServer,
48 * or TProcessPoolServer.
50 * See doc/specs/HeaderFormat.md for details of the wire format.
52 function THeaderProtocol(trans
) {
53 if (!(trans
instanceof THeaderTransport
)) {
54 throw new THeaderProtocolError(
55 'Only transports that inherit THeaderTransport can be' +
56 ' used with THeaderProtocol'
63 THeaderProtocol
.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();
71 THeaderProtocol
.prototype.writeMessageBegin = function(name
, type
, seqid
) {
72 return this.protocol
.writeMessageBegin(name
, type
, seqid
);
75 THeaderProtocol
.prototype.writeMessageEnd = function() {
76 return this.protocol
.writeMessageEnd();
79 THeaderProtocol
.prototype.writeStructBegin = function(name
) {
80 return this.protocol
.writeStructBegin(name
);
83 THeaderProtocol
.prototype.writeStructEnd = function() {
84 return this.protocol
.writeStructEnd();
87 THeaderProtocol
.prototype.writeFieldBegin = function(name
, type
, id
) {
88 return this.protocol
.writeFieldBegin(name
, type
, id
);
91 THeaderProtocol
.prototype.writeFieldEnd = function() {
92 return this.protocol
.writeFieldEnd();
95 THeaderProtocol
.prototype.writeFieldStop = function() {
96 return this.protocol
.writeFieldStop();
99 THeaderProtocol
.prototype.writeMapBegin = function(ktype
, vtype
, size
) {
100 return this.protocol
.writeMapBegin(ktype
, vtype
, size
);
103 THeaderProtocol
.prototype.writeMapEnd = function() {
104 return this.protocol
.writeMapEnd();
107 THeaderProtocol
.prototype.writeListBegin = function(etype
, size
) {
108 return this.protocol
.writeListBegin(etype
, size
);
111 THeaderProtocol
.prototype.writeListEnd = function() {
112 return this.protocol
.writeListEnd();
115 THeaderProtocol
.prototype.writeSetBegin = function(etype
, size
) {
116 return this.protocol
.writeSetBegin(etype
, size
);
119 THeaderProtocol
.prototype.writeSetEnd = function() {
120 return this.protocol
.writeSetEnd();
123 THeaderProtocol
.prototype.writeBool = function(b
) {
124 return this.protocol
.writeBool(b
);
127 THeaderProtocol
.prototype.writeByte = function(b
) {
128 return this.protocol
.writeByte(b
);
131 THeaderProtocol
.prototype.writeI16 = function(i16
) {
132 return this.protocol
.writeI16(i16
);
135 THeaderProtocol
.prototype.writeI32 = function(i32
) {
136 return this.protocol
.writeI32(i32
);
139 THeaderProtocol
.prototype.writeI64 = function(i64
) {
140 return this.protocol
.writeI64(i64
);
143 THeaderProtocol
.prototype.writeDouble = function(dub
) {
144 return this.protocol
.writeDouble(dub
);
147 THeaderProtocol
.prototype.writeStringOrBinary = function(name
, encoding
, arg
) {
148 return this.protocol
.writeStringOrBinary(name
, encoding
, arg
);
151 THeaderProtocol
.prototype.writeString = function(arg
) {
152 return this.protocol
.writeString(arg
);
155 THeaderProtocol
.prototype.writeBinary = function(arg
) {
156 return this.protocol
.writeBinary(arg
);
159 THeaderProtocol
.prototype.readMessageBegin = function() {
160 this.trans
.readHeaders();
162 return this.protocol
.readMessageBegin();
165 THeaderProtocol
.prototype.readMessageEnd = function() {
166 return this.protocol
.readMessageEnd();
169 THeaderProtocol
.prototype.readStructBegin = function() {
170 return this.protocol
.readStructBegin();
173 THeaderProtocol
.prototype.readStructEnd = function() {
174 return this.protocol
.readStructEnd();
177 THeaderProtocol
.prototype.readFieldBegin = function() {
178 return this.protocol
.readFieldBegin();
181 THeaderProtocol
.prototype.readFieldEnd = function() {
182 return this.protocol
.readFieldEnd();
185 THeaderProtocol
.prototype.readMapBegin = function() {
186 return this.protocol
.readMapBegin();
189 THeaderProtocol
.prototype.readMapEnd = function() {
190 return this.protocol
.readMapEnd();
193 THeaderProtocol
.prototype.readListBegin = function() {
194 return this.protocol
.readListBegin();
197 THeaderProtocol
.prototype.readListEnd = function() {
198 return this.protocol
.readListEnd();
201 THeaderProtocol
.prototype.readSetBegin = function() {
202 return this.protocol
.readSetBegin();
205 THeaderProtocol
.prototype.readSetEnd = function() {
206 return this.protocol
.readSetEnd();
209 THeaderProtocol
.prototype.readBool = function() {
210 return this.protocol
.readBool();
213 THeaderProtocol
.prototype.readByte = function() {
214 return this.protocol
.readByte();
217 THeaderProtocol
.prototype.readI16 = function() {
218 return this.protocol
.readI16();
221 THeaderProtocol
.prototype.readI32 = function() {
222 return this.protocol
.readI32();
225 THeaderProtocol
.prototype.readI64 = function() {
226 return this.protocol
.readI64();
229 THeaderProtocol
.prototype.readDouble = function() {
230 return this.protocol
.readDouble();
233 THeaderProtocol
.prototype.readBinary = function() {
234 return this.protocol
.readBinary();
237 THeaderProtocol
.prototype.readString = function() {
238 return this.protocol
.readString();
241 THeaderProtocol
.prototype.getTransport = function() {
245 THeaderProtocol
.prototype.skip = function(type
) {
246 return this.protocol
.skip(type
);
249 THeaderProtocol
.prototype.setProtocol = function(subProtocolId
) {
250 var subProtocolId
= this.trans
.getProtocolId();
251 if (!ProtocolMap
[subProtocolId
]) {
252 throw new THeaderProtocolError('Headers not supported for protocol ' + subProtocolId
);
255 this.protocol
= new ProtocolMap
[subProtocolId
](this.trans
);