Rev 30 | Blame | Compare with Previous | Last modification | View Log | RSS feed
# encoding: ascii-8bit## Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# KIND, either express or implied. See the License for the# specific language governing permissions and limitations# under the License.#module Thriftclass MemoryBufferTransport < BaseTransportGARBAGE_BUFFER_SIZE = 4*(2**10) # 4kB# If you pass a string to this, you should #dup that string# unless you want it to be modified by #read and #write#--# this behavior is no longer required. If you wish to change it# go ahead, just make sure the specs passdef initialize(buffer = nil)@buf = buffer || ''@index = 0enddef open?return trueenddef openenddef closeenddef peek@index < @buf.sizeend# this method does not use the passed object directly but copies itdef reset_buffer(new_buf = '')@buf.replace new_buf@index = 0enddef available@buf.length - @indexenddef read(len)data = @buf.slice(@index, len)@index += len@index = @buf.size if @index > @buf.sizeif @index >= GARBAGE_BUFFER_SIZE@buf = @buf.slice(@index..-1)@index = 0endif data.size < lenraise EOFError, "Not enough bytes remain in buffer"enddataenddef write(wbuf)@buf << wbufenddef flushenddef inspect_bufferout = []for idx in 0...(@buf.size)# if idx != 0# out << " "# endif idx == @indexout << ">"endout << @buf[idx].to_s(16)endout.join(" ")endendend