Class: BitGirder::Event::Testing::TestCodec

Inherits:
BitGirderClass
  • Object
show all
Includes:
Io
Defined in:
lib/bitgirder/event/testing.rb

Constant Summary

Constants included from Io

Io::ORDER_BIG_ENDIAN, Io::ORDER_LITTLE_ENDIAN

Constants included from Core

Core::ENV_BITGIRDER_DEBUG, Core::EXIT_FAILURE, Core::EXIT_SUCCESS

Instance Method Summary collapse

Methods included from Io

as_encoded, as_json, as_read_src, as_write_dest, can_connect?, debug_kill, debug_wait2, digest_file, dump_json, dump_yaml, enc_utf8, ensure_dir, ensure_dirs, ensure_parent, ensure_wiped, file_exists, first_line, fsize, fu, int_to_byte_array, is_executable, load_json, load_yaml, mktmpdir, open_tempfile, parse_json, read_full, slurp, slurp_io, strict_decode64, strict_encode64, which, write_file

Instance Method Details

#decode_event(io, len) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/bitgirder/event/testing.rb', line 61

def decode_event( io, len )
 
    ev_buf_len = len - 4

    case cd = @conv.read_int32( io.read( 4 ) )
    when Int32Event::TYPE_CODE
        Int32Event.from_i( @conv.read_int32( io.read( 4 ) ) )
    when BufferEvent::TYPE_CODE
        BufferEvent.new( Io.read_full( io, ev_buf_len ) )
    else raise sprintf( "Unexpected type code: %04x", cd )
    end
end

#encode_event(ev, io) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/bitgirder/event/testing.rb', line 44

def encode_event( ev, io )

    if ev.is_a?( DelayEvent )
        sleep( ev.delay )
        ev = ev.event
    end

    io.write( @conv.write_int32( ev.class::TYPE_CODE ) )

    case ev
    when Int32Event then io.write( @conv.write_int32( ev.i ) )
    when BufferEvent then io.write( ev.buf )
    else raise TypeError.new( "Unrecognized event: #{ev.class}" )
    end
end