Module: FFI::DRY::NetStructHelper

Defined in:
lib/ffi/dry.rb

Overview

A special helper for network packet structures that use big-endian or “network” byte-order. This helper generates read/write accessors that automatically call the appropriate byte conversion function, ntohs/ntohl for ‘reading’ a 16/32 bit field, and htons/htonl for writing to one.

NOTE this helper does not currently do anything special for 64-bit or higher values but this might be added at some point if the need arises.

NOTE unlike the StructHelper module, no special relevance is given to fields with a “:p_struct” option or defined with the p_struct DSL method. These are ignored and treated like any other field. A net struct generally doesn’t contain pointers into native memory anyway.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



430
431
432
433
# File 'lib/ffi/dry.rb', line 430

def self.included(base)
  base.instance_eval { include StructHelper }
  base.extend(ClassMethods)
end