Module: GrpcKit::Transport::Packable

Included in:
ClientTransport, ServerTransport
Defined in:
lib/grpc_kit/transport/packable.rb

Defined Under Namespace

Classes: Unpacker

Instance Method Summary collapse

Instance Method Details

#pack(data, compress = false) ⇒ String

Returns packed value.

Parameters:

  • data (String)
  • compress (Boolean) (defaults to: false)

Returns:

  • (String)

    packed value



9
10
11
12
# File 'lib/grpc_kit/transport/packable.rb', line 9

def pack(data, compress = false)
  c = compress ? 1 : 0
  [c, data.bytesize, data].pack('CNa*')
end

#unpack(data) ⇒ String

Parameters:

  • data (String)

Returns:

  • (String)


16
17
18
19
20
# File 'lib/grpc_kit/transport/packable.rb', line 16

def unpack(data)
  unpacker.feed(data) if data

  unpacker.read
end

#unpackerObject



22
23
24
# File 'lib/grpc_kit/transport/packable.rb', line 22

def unpacker
  @unpacker ||= Unpacker.new
end