diff --git a/lib/X11/encode.rb b/lib/X11/encode.rb index a4085ea..f05f2f1 100644 --- a/lib/X11/encode.rb +++ b/lib/X11/encode.rb @@ -5,10 +5,28 @@ # # EXAMPLE: # Int8.call(255) => "\xFF" -# String8.call("hello") => "hxello\u0000\u0000\u0000" +# String8.call("hello") => "hello" module X11 module Encode + + # List.of(Foo) + # In this document the List.of notation strictly means some number of + # repetitions of the FOO encoding; the actual length of the list is encoded + # elsewhere + + class List + class << self + def of(type) + lambda do |data| + # X11 has other List.of(Foo) for different data types right now + # will just throw an error until we've implemented them all. + throw "dont know how to handle this yet" + end + end + end + end + # Takes an object and uses Array#pack to # convert it into binary data def self.pack(a) @@ -19,12 +37,15 @@ module X11 # For instance, C gives C<"Hello\0\0\0">. def self.pad(x); x + "\0"*(-x.length & 3); end + # Primitive Types Int8 = pack("c") Int16 = pack("s") Int32 = pack("l") Uint8 = pack("C") Uint16 = pack("S") Uint32 = pack("L") - String8 = lambda {|a| pad(a)} + + # LISTofFOO + String8 = lambda{|x| self.pad(x)} # equivalent to List.of(Uint8) /w padding end end diff --git a/lib/X11/packet.rb b/lib/X11/packet.rb index 7a0bf1c..88cab77 100644 --- a/lib/X11/packet.rb +++ b/lib/X11/packet.rb @@ -83,7 +83,7 @@ module X11 field :protocol_minor_version, Uint16 length :auth_proto_name, Uint16 length :auth_proto_data, Uint16 - unused 1 + unused 2 field :auth_proto_name, String8 field :auth_proto_data, String8 end