def handle_response(type)
      # reads 14 bytes
      # length of "i3-ipc" + 4 bytes length + 4 bytes type
      buffer = read 14
      raise WrongMagicCode unless buffer[0, (MAGIC_STRING.length)] == MAGIC_STRING

      len, recv_type = buffer[6..-1].unpack("LL")
      raise WrongType unless recv_type == type

      answer = read len
      ::JSON.parse(answer)
    end
def handle_response(type)
      # reads 14 bytes
      # length of "i3-ipc" + 4 bytes length + 4 bytes type
      buffer = read 14
      raise WrongMagicCode unless buffer[0, (MAGIC_STRING.length)] == MAGIC_STRING

      len, recv_type = buffer[6..-1].unpack("LL")
      raise WrongType unless recv_type == type

      answer = read len
      ::JSON.parse(answer)
    end
Reads the reply from the socket
 and parses the returned json into a ruby object.

 Throws WrongMagicCode when magic word is wrong.
 Throws WrongType if returned type does not match expected.

 This is a bit duplicated code
  but I don't know a way to read the full send reply
  without knowing its length