Skip to content

Commit

Permalink
Merge pull request #242 from BallAerospace/dont_reformat_block_with_c…
Browse files Browse the repository at this point in the history
…onversion

closes #241. Don't reformat BLOCK data types with a conversion in Str…
  • Loading branch information
ryanmelt committed Dec 29, 2015
2 parents a6360d7 + 2bda7f8 commit 172cf79
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/cosmos/packets/structure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ def formatted(value_type = :RAW, indent = 0, buffer = @buffer)
string = ''
synchronize_allow_reads(true) do
@sorted_items.each do |item|
if item.data_type != :BLOCK
if (item.data_type != :BLOCK) ||
(item.data_type == :BLOCK and value_type != :RAW and
item.respond_to? :read_conversion and item.read_conversion)
string << "#{indent_string}#{item.name}: #{read_item(item, value_type, buffer)}\n"
else
value = read_item(item, value_type, buffer)
Expand Down
5 changes: 5 additions & 0 deletions spec/packets/packet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,14 @@ module Cosmos
i = p.get_item("TEST3")
i.read_conversion = GenericConversion.new("value / 2")
p.write("test3", 0x0406080A)
p.append_item("test4", 32, :BLOCK)
i = p.get_item("TEST4")
i.read_conversion = GenericConversion.new("value.to_s")
p.write("test4", "Test")
expect(p.formatted).to include("TEST1: [1, 2]")
expect(p.formatted).to include("TEST2: TRUE")
expect(p.formatted).to include("TEST3: #{0x02030405}")
expect(p.formatted).to include("TEST4: Test")
end
end

Expand Down

0 comments on commit 172cf79

Please sign in to comment.