| line | stmt | bran | cond | sub | pod | time | code | 
| 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 |  |  | 3 |  | 1435 | use 5.10.0; | 
|  | 3 |  |  |  |  | 12 |  | 
| 21 | 3 |  |  | 3 |  | 19 | use strict; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 81 |  | 
| 22 | 3 |  |  | 3 |  | 17 | use warnings; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 87 |  | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 3 |  |  | 3 |  | 17 | use Thrift; | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 95 |  | 
| 25 | 3 |  |  | 3 |  | 754 | use Thrift::Transport; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 110 |  | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | package Thrift::MemoryBuffer; | 
| 28 | 3 |  |  | 3 |  | 20 | use base('Thrift::Transport'); | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 315 |  | 
| 29 | 3 |  |  | 3 |  | 20 | use version 0.77; our $VERSION = version->declare("$Thrift::VERSION"); | 
|  | 3 |  |  |  |  | 41 |  | 
|  | 3 |  |  |  |  | 16 |  | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | sub new | 
| 32 |  |  |  |  |  |  | { | 
| 33 | 7 |  |  | 7 | 0 | 292 | my $classname = shift; | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 7 |  | 100 |  |  | 37 | my $bufferSize= shift || 1024; | 
| 36 |  |  |  |  |  |  |  | 
| 37 | 7 |  |  |  |  | 30 | my $self = { | 
| 38 |  |  |  |  |  |  | buffer     => '', | 
| 39 |  |  |  |  |  |  | bufferSize => $bufferSize, | 
| 40 |  |  |  |  |  |  | wPos       => 0, | 
| 41 |  |  |  |  |  |  | rPos       => 0, | 
| 42 |  |  |  |  |  |  | }; | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 7 |  |  |  |  | 23 | return bless($self,$classname); | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | sub isOpen | 
| 48 |  |  |  |  |  |  | { | 
| 49 | 0 |  |  | 0 | 0 | 0 | return 1; | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | sub open | 
| 53 |  |  |  | 2 | 0 |  | { | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | sub close | 
| 58 |  |  |  | 0 | 0 |  | { | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | sub peek | 
| 63 |  |  |  |  |  |  | { | 
| 64 | 0 |  |  | 0 | 0 | 0 | my $self = shift; | 
| 65 | 0 |  |  |  |  | 0 | return($self->{rPos} < $self->{wPos}); | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | sub getBuffer | 
| 70 |  |  |  |  |  |  | { | 
| 71 | 4 |  |  | 4 | 0 | 92 | my $self = shift; | 
| 72 | 4 |  |  |  |  | 75 | return $self->{buffer}; | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | sub resetBuffer | 
| 76 |  |  |  |  |  |  | { | 
| 77 | 2 |  |  | 2 | 0 | 12 | my $self = shift; | 
| 78 |  |  |  |  |  |  |  | 
| 79 | 2 |  | 50 |  |  | 11 | my $new_buffer  = shift || ''; | 
| 80 |  |  |  |  |  |  |  | 
| 81 | 2 |  |  |  |  | 7 | $self->{buffer}     = $new_buffer; | 
| 82 | 2 |  |  |  |  | 6 | $self->{bufferSize} = length($new_buffer); | 
| 83 | 2 |  |  |  |  | 4 | $self->{wPos}       = length($new_buffer); | 
| 84 | 2 |  |  |  |  | 6 | $self->{rPos}       = 0; | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | sub available | 
| 88 |  |  |  |  |  |  | { | 
| 89 | 0 |  |  | 0 | 0 | 0 | my $self = shift; | 
| 90 | 0 |  |  |  |  | 0 | return ($self->{wPos} - $self->{rPos}); | 
| 91 |  |  |  |  |  |  | } | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | sub read | 
| 94 |  |  |  |  |  |  | { | 
| 95 | 222 |  |  | 222 | 0 | 281 | my $self = shift; | 
| 96 | 222 |  |  |  |  | 284 | my $len  = shift; | 
| 97 | 222 |  |  |  |  | 297 | my $ret; | 
| 98 |  |  |  |  |  |  |  | 
| 99 | 222 |  |  |  |  | 330 | my $avail = ($self->{wPos} - $self->{rPos}); | 
| 100 | 222 | 50 |  |  |  | 363 | return '' if $avail == 0; | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | #how much to give | 
| 103 | 222 |  |  |  |  | 273 | my $give = $len; | 
| 104 | 222 | 50 |  |  |  | 351 | $give = $avail if $avail < $len; | 
| 105 |  |  |  |  |  |  |  | 
| 106 | 222 |  |  |  |  | 386 | $ret = substr($self->{buffer},$self->{rPos},$give); | 
| 107 |  |  |  |  |  |  |  | 
| 108 | 222 |  |  |  |  | 295 | $self->{rPos} += $give; | 
| 109 |  |  |  |  |  |  |  | 
| 110 | 222 |  |  |  |  | 637 | return $ret; | 
| 111 |  |  |  |  |  |  | } | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | sub readAll | 
| 114 |  |  |  |  |  |  | { | 
| 115 | 223 |  |  | 223 | 0 | 286 | my $self = shift; | 
| 116 | 223 |  |  |  |  | 282 | my $len  = shift; | 
| 117 |  |  |  |  |  |  |  | 
| 118 | 223 |  |  |  |  | 345 | my $avail = ($self->{wPos} - $self->{rPos}); | 
| 119 | 223 | 100 |  |  |  | 423 | if ($avail < $len) { | 
| 120 | 1 |  |  |  |  | 8 | die Thrift::TTransportException->new("Attempt to readAll($len) found only $avail available", | 
| 121 |  |  |  |  |  |  | Thrift::TTransportException::END_OF_FILE); | 
| 122 |  |  |  |  |  |  | } | 
| 123 |  |  |  |  |  |  |  | 
| 124 | 222 |  |  |  |  | 304 | my $data = ''; | 
| 125 | 222 |  |  |  |  | 264 | my $got = 0; | 
| 126 |  |  |  |  |  |  |  | 
| 127 | 222 |  |  |  |  | 403 | while (($got = length($data)) < $len) { | 
| 128 | 222 |  |  |  |  | 385 | $data .= $self->read($len - $got); | 
| 129 |  |  |  |  |  |  | } | 
| 130 |  |  |  |  |  |  |  | 
| 131 | 222 |  |  |  |  | 621 | return $data; | 
| 132 |  |  |  |  |  |  | } | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | sub write | 
| 135 |  |  |  |  |  |  | { | 
| 136 | 226 |  |  | 226 | 0 | 312 | my $self = shift; | 
| 137 | 226 |  |  |  |  | 294 | my $buf  = shift; | 
| 138 |  |  |  |  |  |  |  | 
| 139 | 226 |  |  |  |  | 351 | $self->{buffer} .= $buf; | 
| 140 | 226 |  |  |  |  | 372 | $self->{wPos}   += length($buf); | 
| 141 |  |  |  |  |  |  | } | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | sub flush | 
| 144 |  |  |  | 26 | 0 |  | { | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | } | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | 1; |