Closed nazarhussain closed 9 years ago
I just tried another way:
packet = Base.new
packet.transaction_type = 1
io = File.open("test.bin", "w+")
packet.write(io)
packet2 = Base.new.read(io)
Its showing error:
/home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bindata-2.1.0/lib/bindata/io.rb:82:in `readbytes': End of file reached (EOFError)
from (eval):23:in `read_and_return_value'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bindata-2.1.0/lib/bindata/base_primitive.rb:124:in `do_read'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bindata-2.1.0/lib/bindata/struct.rb:131:in `block in do_read'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bindata-2.1.0/lib/bindata/struct.rb:131:in `each'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bindata-2.1.0/lib/bindata/struct.rb:131:in `do_read'
from /home/user/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bindata-2.1.0/lib/bindata/base.rb:146:in `read'
Please look into this.
Do you want :packet_type
to appear in the data stream? The "garbage" values are the ascii values for A l p h a
. If you want to use :packet_type
for annotation, use virtual
instead of string
.
io = File.open("test.bin", "w+")
io.write("foo")
io.read(3)
Yes this won't work. Either close and re-open the file, or call rewind
.
@dmendel You are awesome. I wonder how I didn't notice the values and pointed out these were ascii values.
I made 'packet_type' to virtual
and resolved the issue.
Hello,
I am building a complex packet architecture to work on a tcp connection. While writing a dummy script to behave like a physical hardware I noticed one thing, which is seems to a strange behavior.
Suppose I have these three Binary Records:
Now if I execute these lines of code:
I get following output:
As you can notice second packet which was built using
to_binary_s
from the first packet is having garbage values.Can you please guide me why I am facing this strange behavior.