blib/lib/Thrift/Protocol.pm

filter: Statementstmt 27.5% 64 / 232 Branchbran 0.0% 0 / 62 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 31.7% 20 / 63 Podpod 0.0% 0 / 43 totaltotal 20.7% 84 / 405 CC 33 SCAR 47.2
CC
33
Cov
22%
skipBinary
342.0
skip
272.0
new
2.0
CRAP 111.7
« gen-perl/ThriftTest/Types.pm ↑ Summary blib/lib/Thrift/SSLServerSocket.pm »
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 3 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 3 ▶use Thrift;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ▶use Thrift::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 3 ▶use Thrift::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 #
29 # Protocol exceptions
30 #
31 package Thrift::TProtocolException;
32 3 ▶use base('Thrift::TException');
Subroutine BEGIN: called CC=1 SCAR=0.0
33 3 ▶use version 0.77; our $VERSION = version->declare("$Thrift::VERSION");
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 3 ▶use constant UNKNOWN => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 3 ▶use constant INVALID_DATA => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 3 ▶use constant NEGATIVE_SIZE => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 3 ▶use constant SIZE_LIMIT => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 3 ▶use constant BAD_VERSION => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 3 ▶use constant NOT_IMPLEMENTED => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 3 ▶use constant DEPTH_LIMIT => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
44 0 my $classname = shift;
45  
46 0 my $self = $classname->SUPER::new();
47  
48 0 return bless($self,$classname);
49 }
50  
51 #
52 # Protocol base class module.
53 #
54 package Thrift::Protocol;
55 3 ▶use version 0.77; our $VERSION = version->declare("$Thrift::VERSION");
Subroutine BEGIN: called CC=1 SCAR=0.0
56  
57 21 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
58 21 my $classname = shift;
59 21 my $self = {};
60  
61 21 my $trans = shift;
62 21 $self->{trans}= $trans;
63  
64 21 return bless($self,$classname);
65 }
66  
67 sub getTransport
68 39 ▶{
Subroutine getTransport: called CC=1 SCAR=0.0
Pod undocumented
69 39 my $self = shift;
70  
71 39 return $self->{trans};
72 }
73  
74 #
75 # Writes the message header
76 #
77 # @param string $name Function name
78 # @param int $type message type TMessageType::CALL or TMessageType::REPLY
79 # @param int $seqid The sequence id of this message
80 #
81 sub writeMessageBegin
82 0 ▶{
Subroutine writeMessageBegin: not called CC=1 SCAR=6.9
Pod undocumented
83 0 my ($name, $type, $seqid);
84 0 die 'abstract';
85 }
86  
87 #
88 # Close the message
89 #
90 0 ▶sub writeMessageEnd {
Subroutine writeMessageEnd: not called CC=1 SCAR=6.9
Pod undocumented
91 0 die 'abstract';
92 }
93  
94 #
95 # Writes a struct header.
96 #
97 # @param string $name Struct name
98 # @throws TProtocolException on write error
99 # @return int How many bytes written
100 #
101 0 ▶sub writeStructBegin {
Subroutine writeStructBegin: not called CC=1 SCAR=6.9
Pod undocumented
102 0 my ($name);
103  
104 0 die 'abstract';
105 }
106  
107 #
108 # Close a struct.
109 #
110 # @throws TProtocolException on write error
111 # @return int How many bytes written
112 #
113 0 ▶sub writeStructEnd {
Subroutine writeStructEnd: not called CC=1 SCAR=6.9
Pod undocumented
114 0 die 'abstract';
115 }
116  
117 #
118 # Starts a field.
119 #
120 # @param string $name Field name
121 # @param int $type Field type
122 # @param int $fid Field id
123 # @throws TProtocolException on write error
124 # @return int How many bytes written
125 #
126 0 ▶sub writeFieldBegin {
Subroutine writeFieldBegin: not called CC=1 SCAR=6.9
Pod undocumented
127 0 my ($fieldName, $fieldType, $fieldId);
128  
129 0 die 'abstract';
130 }
131  
132 0 ▶sub writeFieldEnd {
Subroutine writeFieldEnd: not called CC=1 SCAR=6.9
Pod undocumented
133 0 die 'abstract';
134 }
135  
136 0 ▶sub writeFieldStop {
Subroutine writeFieldStop: not called CC=1 SCAR=6.9
Pod undocumented
137 0 die 'abstract';
138 }
139  
140 0 ▶sub writeMapBegin {
Subroutine writeMapBegin: not called CC=1 SCAR=6.9
Pod undocumented
141 0 my ($keyType, $valType, $size);
142  
143 0 die 'abstract';
144 }
145  
146 0 ▶sub writeMapEnd {
Subroutine writeMapEnd: not called CC=1 SCAR=6.9
Pod undocumented
147 0 die 'abstract';
148 }
149  
150 0 ▶sub writeListBegin {
Subroutine writeListBegin: not called CC=1 SCAR=6.9
Pod undocumented
151 0 my ($elemType, $size);
152 0 die 'abstract';
153 }
154  
155 0 ▶sub writeListEnd {
Subroutine writeListEnd: not called CC=1 SCAR=6.9
Pod undocumented
156 0 die 'abstract';
157 }
158  
159 0 ▶sub writeSetBegin {
Subroutine writeSetBegin: not called CC=1 SCAR=6.9
Pod undocumented
160 0 my ($elemType, $size);
161 0 die 'abstract';
162 }
163  
164 0 ▶sub writeSetEnd {
Subroutine writeSetEnd: not called CC=1 SCAR=6.9
Pod undocumented
165 0 die 'abstract';
166 }
167  
168 0 ▶sub writeBool {
Subroutine writeBool: not called CC=1 SCAR=6.9
Pod undocumented
169 0 my ($bool);
170 0 die 'abstract';
171 }
172  
173 0 ▶sub writeByte {
Subroutine writeByte: not called CC=1 SCAR=6.9
Pod undocumented
174 0 my ($byte);
175 0 die 'abstract';
176 }
177  
178 0 ▶sub writeI16 {
Subroutine writeI16: not called CC=1 SCAR=6.9
Pod undocumented
179 0 my ($i16);
180 0 die 'abstract';
181 }
182  
183 0 ▶sub writeI32 {
Subroutine writeI32: not called CC=1 SCAR=6.9
Pod undocumented
184 0 my ($i32);
185 0 die 'abstract';
186 }
187  
188 0 ▶sub writeI64 {
Subroutine writeI64: not called CC=1 SCAR=6.9
Pod undocumented
189 0 my ($i64);
190 0 die 'abstract';
191 }
192  
193 0 ▶sub writeDouble {
Subroutine writeDouble: not called CC=1 SCAR=6.9
Pod undocumented
194 0 my ($dub);
195 0 die 'abstract';
196 }
197  
198 sub writeString
199 0 ▶{
Subroutine writeString: not called CC=1 SCAR=6.9
Pod undocumented
200 0 my ($str);
201 0 die 'abstract';
202 }
203  
204 #
205 # Reads the message header
206 #
207 # @param string $name Function name
208 # @param int $type message type TMessageType::CALL or TMessageType::REPLY
209 # @parem int $seqid The sequence id of this message
210 #
211 sub readMessageBegin
212 0 ▶{
Subroutine readMessageBegin: not called CC=1 SCAR=6.9
Pod undocumented
213 0 my ($name, $type, $seqid);
214 0 die 'abstract';
215 }
216  
217 #
218 # Read the close of message
219 #
220 sub readMessageEnd
221 0 ▶{
Subroutine readMessageEnd: not called CC=1 SCAR=6.9
Pod undocumented
222 0 die 'abstract';
223 }
224  
225 sub readStructBegin
226 0 ▶{
Subroutine readStructBegin: not called CC=1 SCAR=6.9
Pod undocumented
227 0 my($name);
228  
229 0 die 'abstract';
230 }
231  
232 sub readStructEnd
233 0 ▶{
Subroutine readStructEnd: not called CC=1 SCAR=6.9
Pod undocumented
234 0 die 'abstract';
235 }
236  
237 sub readFieldBegin
238 0 ▶{
Subroutine readFieldBegin: not called CC=1 SCAR=6.9
Pod undocumented
239 0 my ($name, $fieldType, $fieldId);
240 0 die 'abstract';
241 }
242  
243 sub readFieldEnd
244 0 ▶{
Subroutine readFieldEnd: not called CC=1 SCAR=6.9
Pod undocumented
245 0 die 'abstract';
246 }
247  
248 sub readMapBegin
249 0 ▶{
Subroutine readMapBegin: not called CC=1 SCAR=6.9
Pod undocumented
250 0 my ($keyType, $valType, $size);
251 0 die 'abstract';
252 }
253  
254 sub readMapEnd
255 0 ▶{
Subroutine readMapEnd: not called CC=1 SCAR=6.9
Pod undocumented
256 0 die 'abstract';
257 }
258  
259 sub readListBegin
260 0 ▶{
Subroutine readListBegin: not called CC=1 SCAR=6.9
Pod undocumented
261 0 my ($elemType, $size);
262 0 die 'abstract';
263 }
264  
265 sub readListEnd
266 0 ▶{
Subroutine readListEnd: not called CC=1 SCAR=6.9
Pod undocumented
267 0 die 'abstract';
268 }
269  
270 sub readSetBegin
271 0 ▶{
Subroutine readSetBegin: not called CC=1 SCAR=6.9
Pod undocumented
272 0 my ($elemType, $size);
273 0 die 'abstract';
274 }
275  
276 sub readSetEnd
277 0 ▶{
Subroutine readSetEnd: not called CC=1 SCAR=6.9
Pod undocumented
278 0 die 'abstract';
279 }
280  
281 sub readBool
282 0 ▶{
Subroutine readBool: not called CC=1 SCAR=6.9
Pod undocumented
283 0 my ($bool);
284 0 die 'abstract';
285 }
286  
287 sub readByte
288 0 ▶{
Subroutine readByte: not called CC=1 SCAR=6.9
Pod undocumented
289 0 my ($byte);
290 0 die 'abstract';
291 }
292  
293 sub readI16
294 0 ▶{
Subroutine readI16: not called CC=1 SCAR=6.9
Pod undocumented
295 0 my ($i16);
296 0 die 'abstract';
297 }
298  
299 sub readI32
300 0 ▶{
Subroutine readI32: not called CC=1 SCAR=6.9
Pod undocumented
301 0 my ($i32);
302 0 die 'abstract';
303 }
304  
305 sub readI64
306 0 ▶{
Subroutine readI64: not called CC=1 SCAR=6.9
Pod undocumented
307 0 my ($i64);
308 0 die 'abstract';
309 }
310  
311 sub readDouble
312 0 ▶{
Subroutine readDouble: not called CC=1 SCAR=6.9
Pod undocumented
313 0 my ($dub);
314 0 die 'abstract';
315 }
316  
317 sub readString
318 0 ▶{
Subroutine readString: not called CC=1 SCAR=6.9
Pod undocumented
319 0 my ($str);
320 0 die 'abstract';
321 }
322  
323 #
324 # The skip function is a utility to parse over unrecognized data without
325 # causing corruption.
326 #
327 # @param TType $type What type is it
328 #
329 sub skip
330 0 ▶{
Subroutine skip: not called CC=16 SCAR=56.1
Pod undocumented
331 0 my $self = shift;
332 0 my $type = shift;
333  
334 0 my $ref;
335 my $result;
336 0 my $i;
337  
338 0 ▶ if($type == Thrift::TType::BOOL)
Branch: 11 branches
BranchTrueFalseTotal
if ($type == 2) { } 0 0 0
elsif ($type == 3) { } 0 0 0
elsif ($type == 6) { } 0 0 0
elsif ($type == 8) { } 0 0 0
elsif ($type == 10) { } 0 0 0
elsif ($type == 4) { } 0 0 0
elsif ($type == 11) { } 0 0 0
elsif ($type == 12) { } 0 0 0
elsif ($type == 13) { } 0 0 0
elsif ($type == 14) { } 0 0 0
elsif ($type == 15) { } 0 0 0
339 {
340 0 return $self->readBool(\$ref);
341 }
342 elsif($type == Thrift::TType::BYTE){
343 0 return $self->readByte(\$ref);
344 }
345 elsif($type == Thrift::TType::I16){
346 0 return $self->readI16(\$ref);
347 }
348 elsif($type == Thrift::TType::I32){
349 0 return $self->readI32(\$ref);
350 }
351 elsif($type == Thrift::TType::I64){
352 0 return $self->readI64(\$ref);
353 }
354 elsif($type == Thrift::TType::DOUBLE){
355 0 return $self->readDouble(\$ref);
356 }
357 elsif($type == Thrift::TType::STRING)
358 {
359 0 return $self->readString(\$ref);
360 }
361 elsif($type == Thrift::TType::STRUCT)
362 {
363 0 $result = $self->readStructBegin(\$ref);
364 0 while (1) {
365 0 my ($ftype,$fid);
366 0 $result += $self->readFieldBegin(\$ref, \$ftype, \$fid);
367 0 ▶ if ($ftype == Thrift::TType::STOP) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ftype == 0) 0 0 0
368 0 last;
369 }
370 0 $result += $self->skip($ftype);
371 0 $result += $self->readFieldEnd();
372 }
373 0 $result += $self->readStructEnd();
374 0 return $result;
375 }
376 elsif($type == Thrift::TType::MAP)
377 {
378 0 my($keyType,$valType,$size);
379 0 $result = $self->readMapBegin(\$keyType, \$valType, \$size);
380 0 ▶ for ($i = 0; $i < $size; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $size) 0 0 0
381 0 $result += $self->skip($keyType);
382 0 $result += $self->skip($valType);
383 }
384 0 $result += $self->readMapEnd();
385 0 return $result;
386 }
387 elsif($type == Thrift::TType::SET)
388 {
389 0 my ($elemType,$size);
390 0 $result = $self->readSetBegin(\$elemType, \$size);
391 0 ▶ for ($i = 0; $i < $size; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $size) 0 0 0
392 0 $result += $self->skip($elemType);
393 }
394 0 $result += $self->readSetEnd();
395 0 return $result;
396 }
397 elsif($type == Thrift::TType::LIST)
398 {
399 0 my ($elemType,$size);
400 0 $result = $self->readListBegin(\$elemType, \$size);
401 0 ▶ for ($i = 0; $i < $size; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $size) 0 0 0
402 0 $result += $self->skip($elemType);
403 }
404 0 $result += $self->readListEnd();
405 0 return $result;
406 }
407  
408 0 die Thrift::TProtocolException->new("Type $type not recognized --- corrupt data?",
409 Thrift::TProtocolException::INVALID_DATA);
410  
411 }
412  
413 #
414 # Utility for skipping binary data
415 #
416 # @param TTransport $itrans TTransport object
417 # @param int $type Field type
418 #
419 sub skipBinary
420 0 ▶{
Subroutine skipBinary: not called CC=18 SCAR=58.3
Pod undocumented
421 0 my $self = shift;
422 0 my $itrans = shift;
423 0 my $type = shift;
424  
425 0 ▶ if($type == Thrift::TType::BOOL)
Branch: 10 branches
BranchTrueFalseTotal
if ($type == 2) { } 0 0 0
elsif ($type == 3) { } 0 0 0
elsif ($type == 6) { } 0 0 0
elsif ($type == 8) { } 0 0 0
elsif ($type == 10) { } 0 0 0
elsif ($type == 4) { } 0 0 0
elsif ($type == 11) { } 0 0 0
elsif ($type == 12) { } 0 0 0
elsif ($type == 13) { } 0 0 0
elsif ($type == 14 or $type == 15) { } 0 0 0
426 {
427 0 return $itrans->readAll(1);
428 }
429 elsif($type == Thrift::TType::BYTE)
430 {
431 0 return $itrans->readAll(1);
432 }
433 elsif($type == Thrift::TType::I16)
434 {
435 0 return $itrans->readAll(2);
436 }
437 elsif($type == Thrift::TType::I32)
438 {
439 0 return $itrans->readAll(4);
440 }
441 elsif($type == Thrift::TType::I64)
442 {
443 0 return $itrans->readAll(8);
444 }
445 elsif($type == Thrift::TType::DOUBLE)
446 {
447 0 return $itrans->readAll(8);
448 }
449 elsif( $type == Thrift::TType::STRING )
450 {
451 0 my @len = unpack('N', $itrans->readAll(4));
452 0 my $len = $len[0];
453 0 ▶ if ($len > 0x7fffffff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 2147483647) 0 0 0
454 0 $len = 0 - (($len - 1) ^ 0xffffffff);
455 }
456 0 return 4 + $itrans->readAll($len);
457 }
458 elsif( $type == Thrift::TType::STRUCT )
459 {
460 0 my $result = 0;
461 0 while (1) {
462 0 my $ftype = 0;
463 0 my $fid = 0;
464 0 my $data = $itrans->readAll(1);
465 0 my @arr = unpack('c', $data);
466 0 $ftype = $arr[0];
467 0 ▶ if ($ftype == Thrift::TType::STOP) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ftype == 0) 0 0 0
468 0 last;
469 }
470 # I16 field id
471 0 $result += $itrans->readAll(2);
472 0 $result += $self->skipBinary($itrans, $ftype);
473 }
474 0 return $result;
475 }
476 elsif($type == Thrift::TType::MAP)
477 {
478 # Ktype
479 0 my $data = $itrans->readAll(1);
480 0 my @arr = unpack('c', $data);
481 0 my $ktype = $arr[0];
482 # Vtype
483 0 $data = $itrans->readAll(1);
484 0 @arr = unpack('c', $data);
485 0 my $vtype = $arr[0];
486 # Size
487 0 $data = $itrans->readAll(4);
488 0 @arr = unpack('N', $data);
489 0 my $size = $arr[0];
490 0 ▶ if ($size > 0x7fffffff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size > 2147483647) 0 0 0
491 0 $size = 0 - (($size - 1) ^ 0xffffffff);
492 }
493 0 my $result = 6;
494 0 ▶ for (my $i = 0; $i < $size; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $size) 0 0 0
495 0 $result += $self->skipBinary($itrans, $ktype);
496 0 $result += $self->skipBinary($itrans, $vtype);
497 }
498 0 return $result;
499 }
500 ▶ elsif($type == Thrift::TType::SET || $type == Thrift::TType::LIST)
Condition0%0/3
$type == 14 or $type == 15
l!l&&r!l&&!r
000
MC/DC0%0/2
$type == 14 or $type == 15
$type == 14 $type == 15
Truth table0%0/3
A or B
A= $type == 14B= $type == 15
ABresult
1X1
011
000
501 {
502 # Vtype
503 0 my $data = $itrans->readAll(1);
504 0 my @arr = unpack('c', $data);
505 0 my $vtype = $arr[0];
506 # Size
507 0 $data = $itrans->readAll(4);
508 0 @arr = unpack('N', $data);
509 0 my $size = $arr[0];
510 0 ▶ if ($size > 0x7fffffff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size > 2147483647) 0 0 0
511 0 $size = 0 - (($size - 1) ^ 0xffffffff);
512 }
513 0 my $result = 5;
514 0 ▶ for (my $i = 0; $i < $size; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $size) 0 0 0
515 0 $result += $self->skipBinary($itrans, $vtype);
516 }
517 0 return $result;
518 }
519  
520 0 die Thrift::TProtocolException->new("Type $type not recognized --- corrupt data?",
521 Thrift::TProtocolException::INVALID_DATA);
522 }
523  
524 #
525 # Protocol factory creates protocol objects from transports
526 #
527 package Thrift::TProtocolFactory;
528 3 ▶use version 0.77; our $VERSION = version->declare("$Thrift::VERSION");
Subroutine BEGIN: called CC=1 SCAR=0.0
529  
530 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
531 2 my $classname = shift;
532 2 my $self = {};
533  
534 2 return bless($self,$classname);
535 }
536  
537 #
538 # Build a protocol from the base transport
539 #
540 # @return TProtcol protocol
541 #
542 sub getProtocol
543 0 ▶{
Subroutine getProtocol: not called CC=1 SCAR=6.9
544 0 my ($trans);
545 0 die 'interface';
546 }
547  
548  
549 3 1;
« gen-perl/ThriftTest/Types.pm ↑ Summary blib/lib/Thrift/SSLServerSocket.pm »