Sha256: 0d681b302ac5e245a3c172592325c3fdf7a3713d35c614e55e19e90d1ee0acb4

Contents?: true

Size: 763 Bytes

Versions: 2

Compression:

Stored size: 763 Bytes

Contents

# frozen_string_literal: true

module GrpcKit
  module Transport
    class SendBuffer
      def initialize
        @buffer = nil
        @pos = 0
        @end_write = false
      end

      def write(data, last: false)
        end_write if last

        if @buffer
          @buffer << data
        else
          @buffer = data
        end

        data.size
      end

      def end_write
        @end_write = true
      end

      def end_write?
        @end_write
      end

      def read(size)
        if @buffer.nil?
          return false
        end

        data = @buffer.slice!(0, size)
        if !data.empty?
          data
        elsif end_write?
          nil # EOF
        else
          false # deferred
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grpc_kit-0.1.5 lib/grpc_kit/transport/send_buffer.rb
grpc_kit-0.1.4 lib/grpc_kit/transport/send_buffer.rb