Class: F4R::Definition::RecordHeader

Inherits:
BinData::Record
  • Object
show all
Defined in:
lib/f4r.rb

Overview

Record header

| Bit | Value       | Description           |
|-----+-------------+-----------------------|
|   7 | 0           | Normal Header         |
|   6 | 0 or 1      | Message Type:         |
|     |             | 1: Definition         |
|     |             | 2: Data               |
|   5 | 0 (default) | Message Type Specific |
|   4 | 0           | Reserved              |
| 0-3 | 0-15        | Local Message Type    |

Instance Method Summary collapse

Instance Method Details

#compressed?Boolean

Returns:

  • (Boolean)


879
880
881
# File 'lib/f4r.rb', line 879

def compressed?
  normal.snapshot == 1
end

#for_new_definition?Boolean

Returns:

  • (Boolean)


886
887
888
# File 'lib/f4r.rb', line 886

def for_new_definition?
  normal.snapshot.zero? && message_type.snapshot == 1
end

#read(io) ⇒ Object

Serves as first place for validating data.

Parameters:

  • io (IO)


857
858
859
860
861
862
863
864
865
# File 'lib/f4r.rb', line 857

def read(io)
  super

  if compressed?
    Log.error "Compressed Timestamp Headers are not supported. #{inspect}"
  end

  Log.decode [self.class, __method__], to_log_s
end

#to_log_sString

Header format for log output

@example:

record_{data}_header: N: 0 MT: 1 DDF: 0 R: 0 LMT: 6

Returns:

  • (String)


898
899
900
901
902
903
904
905
906
907
908
# File 'lib/f4r.rb', line 898

def to_log_s
  {
    "#{message_type.snapshot.zero? ? 'record_data' : 'record'}_header" => [
      ('%-8s' % "N:  #{normal.snapshot}"),
      ('%-8s' % "MT: #{message_type.snapshot}"),
      ('%-8s' % "DDF:#{developer_data_flag.snapshot}"),
      ('%-8s' % "R:  #{reserved.snapshot}"),
      ('%-8s' % "LMT:#{local_message_type.snapshot}"),
    ].join(' ')
  }
end

#write(io) ⇒ Object

Parameters:

  • io (io)


870
871
872
873
874
# File 'lib/f4r.rb', line 870

def write(io)
  super

  Log.encode [self.class, __method__], to_log_s
end

#write_data_header(io, record) ⇒ Object

Helper method for writing data headers

Parameters:



916
917
918
919
920
921
922
# File 'lib/f4r.rb', line 916

def write_data_header(io, record)
  data_header = self.new
  data_header.normal = 0
  data_header.message_type = 0
  data_header.local_message_type = record[:local_message_number]
  data_header.write(io)
end