Class: MemoryIO::Types::Clang::CStr Private

Inherits:
Type
  • Object
show all
Defined in:
lib/memory_io/types/clang/c_str.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A null-terminated string.

Constant Summary

Constants inherited from Type

Type::SIZE_T

Class Method Summary collapse

Methods inherited from Type

find, keep_pos, read_size_t, register, write_size_t

Class Method Details

.read(stream) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns String without null byte.

Returns:

  • (String)

    String without null byte.



19
20
21
22
23
24
25
26
27
28
# File 'lib/memory_io/types/clang/c_str.rb', line 19

def self.read(stream)
  ret = +''
  loop do
    c = stream.read(1)
    break if c.nil? || c == '' || c == "\x00"

    ret << c
  end
  ret
end

.write(stream, val) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • val (String)

    A null byte would be appended if val not ends with null byte.



34
35
36
37
38
# File 'lib/memory_io/types/clang/c_str.rb', line 34

def self.write(stream, val)
  val = val.to_s
  val += "\x00" unless val.end_with?("\x00")
  stream.write(val)
end