Sha256: fd5b55aa484dbac6fef1c6fee1d909f2f315e2c5e18529cacc4dc1f27b1690dd

Contents?: true

Size: 1.21 KB

Versions: 8

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module GrpcKit
  module Session
    class SendBuffer
      def initialize
        @buffer = ''.b
        @end_write = false
        @deferred_read = false
      end

      # @param data [String]
      # @param last [Boolean]
      # @return [void]
      def write(data, last: false)
        end_write if last
        @buffer << data
      end

      # @return [Boolean]
      def need_resume?
        @deferred_read
      end

      # @return [void]
      def end_write
        @end_write = true
      end

      # @return [Boolean]
      def end_write?
        @end_write
      end

      # @param size [Integer,nil]
      # @return [nil,DS9::ERR_DEFERRED,String]
      def read(size = nil)
        if @buffer.empty?
          if end_write?
            @deferred_read = false
            return nil # EOF
          end

          @deferred_read = true
          return DS9::ERR_DEFERRED
        end

        if size.nil? || @buffer.bytesize < size
          buf = @buffer
          @buffer = ''.b
          buf
        else
          @buffer.freeze
          rbuf = @buffer.byteslice(0, size)
          @buffer = @buffer.byteslice(size, @buffer.bytesize)
          rbuf
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
grpc_kit-0.2.1 lib/grpc_kit/session/send_buffer.rb
grpc_kit-0.2.0 lib/grpc_kit/session/send_buffer.rb
grpc_kit-0.1.14 lib/grpc_kit/session/send_buffer.rb
grpc_kit-0.1.13 lib/grpc_kit/session/send_buffer.rb
grpc_kit-0.1.12 lib/grpc_kit/session/send_buffer.rb
grpc_kit-0.1.11 lib/grpc_kit/session/send_buffer.rb
grpc_kit-0.1.10 lib/grpc_kit/session/send_buffer.rb
grpc_kit-0.1.9 lib/grpc_kit/session/send_buffer.rb