]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/perl/lib/Thrift/MemoryBuffer.pm
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
25 use Thrift
::Transport
;
27 package Thrift
::MemoryBuffer
;
28 use base
('Thrift::Transport');
29 use version
0.77; our $VERSION = version-
>declare("$Thrift::VERSION");
33 my $classname = shift;
35 my $bufferSize= shift || 1024;
39 bufferSize
=> $bufferSize,
44 return bless($self,$classname);
65 return($self->{rPos
} < $self->{wPos
});
72 return $self->{buffer
};
79 my $new_buffer = shift || '';
81 $self->{buffer
} = $new_buffer;
82 $self->{bufferSize
} = length($new_buffer);
83 $self->{wPos
} = length($new_buffer);
90 return ($self->{wPos
} - $self->{rPos
});
99 my $avail = ($self->{wPos
} - $self->{rPos
});
100 return '' if $avail == 0;
104 $give = $avail if $avail < $len;
106 $ret = substr($self->{buffer
},$self->{rPos
},$give);
108 $self->{rPos
} += $give;
118 my $avail = ($self->{wPos
} - $self->{rPos
});
120 die TTransportException-
>new("Attempt to readAll($len) found only $avail available",
121 Thrift
::TTransportException
::END_OF_FILE
);
127 while (($got = length($data)) < $len) {
128 $data .= $self->read($len - $got);
139 $self->{buffer
} .= $buf;
140 $self->{wPos
} += length($buf);