Class: StructFu::Int16

Inherits:
Int show all
Defined in:
lib/packetfu/structfu.rb

Overview

Int16 is a two byte value.

Direct Known Subclasses

Int16be, Int16le

Instance Attribute Summary

Attributes inherited from Int

#default, #endian, #value, #width

Instance Method Summary collapse

Methods inherited from Int

#read, #to_f, #to_i

Methods inherited from Struct

#force_binary

Constructor Details

#initialize(v = nil, e = :big) ⇒ Int16

Returns a new instance of Int16.



113
114
115
116
# File 'lib/packetfu/structfu.rb', line 113

def initialize(v=nil, e=:big)
  super(v,e,w=2)
  @packstr = (self.e == :big) ? "n" : "v"
end

Instance Method Details

#to_sObject

Returns a two byte value as a packed string.



119
120
121
122
# File 'lib/packetfu/structfu.rb', line 119

def to_s
 @packstr = (self.e == :big) ? "n" : "v"
 [(self.v || self.d)].pack(@packstr)
end