Module: CTypes
- Extended by:
- Helpers
- Defined in:
- lib/ctypes.rb,
lib/ctypes/int.rb,
lib/ctypes/pad.rb,
lib/ctypes/enum.rb,
lib/ctypes/type.rb,
lib/ctypes/array.rb,
lib/ctypes/union.rb,
lib/ctypes/bitmap.rb,
lib/ctypes/string.rb,
lib/ctypes/struct.rb,
lib/ctypes/helpers.rb,
lib/ctypes/version.rb,
lib/ctypes/bitfield.rb,
lib/ctypes/exporter.rb,
lib/ctypes/importers.rb,
lib/ctypes/terminated.rb,
lib/ctypes/enum/builder.rb,
lib/ctypes/union/builder.rb,
lib/ctypes/struct/builder.rb,
lib/ctypes/bitfield/builder.rb,
lib/ctypes/importers/castxml.rb,
lib/ctypes/missing_bytes_error.rb,
lib/ctypes/pretty_print_helpers.rb,
lib/ctypes/importers/castxml/loader.rb
Overview
SPDX-FileCopyrightText: 2025 Cisco SPDX-License-Identifier: MIT
Defined Under Namespace
Modules: Helpers, Importers, PrettyPrintHelpers, Type Classes: Array, Bitfield, Bitmap, Enum, Error, Exporter, Int, MissingBytesError, Pad, String, Struct, Terminated, TerminatorNotFoundError, TruncatedValueError, Union, UnknownAttributeError, UnknownFieldError, UnknownMemberError
Constant Summary collapse
- Endian =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Dry::Types["coercible.symbol"].enum(*%i[big little])
- UInt8 =
base type for unsiged 8-bit integers
Int.new(bits: 8, signed: false, format: "C", desc: "uint8")
- UInt16 =
base type for unsiged 16-bit integers
Int.new(bits: 16, signed: false, format: "S", desc: "uint16")
- UInt32 =
base type for unsiged 32-bit integers
Int.new(bits: 32, signed: false, format: "L", desc: "uint32")
- UInt64 =
base type for unsiged 64-bit integers
Int.new(bits: 64, signed: false, format: "Q", desc: "uint64")
- Int8 =
base type for siged 8-bit integers
Int.new(bits: 8, signed: true, format: "c", desc: "int8")
- Int16 =
base type for siged 16-bit integers
Int.new(bits: 16, signed: true, format: "s", desc: "int16")
- Int32 =
base type for siged 32-bit integers
Int.new(bits: 32, signed: true, format: "l", desc: "int32")
- Int64 =
base type for siged 64-bit integers
Int.new(bits: 64, signed: true, format: "q", desc: "int64")
- VERSION =
"0.3.0"
Class Method Summary collapse
-
.default_endian ⇒ Object
get the default endian for the system; defaults to native endian.
-
.default_endian=(value) ⇒ Object
set the endian for any datatype that does not have an explicit endian set.
-
.host_endian ⇒ Object
get the endian of the system this code is running on.
- .type_lookup ⇒ Object private
-
.using_type_lookup(lookup) ⇒ Object
set a unknown type lookup method to use in the layout blocks of ‘Ctypes::Struct` and `CTypes::Union`.
Methods included from Helpers
array, bitfield, bitmap, enum, string, struct, union
Class Method Details
.default_endian ⇒ Object
get the default endian for the system; defaults to native endian
67 68 69 |
# File 'lib/ctypes.rb', line 67 def self.default_endian @endian ||= host_endian end |
.default_endian=(value) ⇒ Object
set the endian for any datatype that does not have an explicit endian set
62 63 64 |
# File 'lib/ctypes.rb', line 62 def self.default_endian=(value) @endian = Endian[value] end |
.host_endian ⇒ Object
get the endian of the system this code is running on
72 73 74 |
# File 'lib/ctypes.rb', line 72 def self.host_endian @host_endian ||= ("\xde\xad".unpack1("S") == 0xDEAD) ? :big : :little end |
.type_lookup ⇒ 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.
97 98 99 |
# File 'lib/ctypes.rb', line 97 def self.type_lookup # :nodoc: @type_lookup && @type_lookup[-1] end |
.using_type_lookup(lookup) ⇒ Object
set a unknown type lookup method to use in the layout blocks of ‘Ctypes::Struct` and `CTypes::Union`.
Note: the current implementation is not thread-safe.
88 89 90 91 92 93 94 |
# File 'lib/ctypes.rb', line 88 def self.using_type_lookup(lookup) @type_lookup ||= [] @type_lookup.push(lookup) yield ensure @type_lookup.pop end |