class CFPropertyList::Binary

def string_to_binary(val)

Uniques and transforms a string value to binary format and adds it to the object table
def string_to_binary(val)
  saved_object_count = -1
  unless(@unique_table.has_key?(val)) then
    saved_object_count = @written_object_count
    @written_object_count += 1
    @unique_table[val] = saved_object_count
    utf16 = false
    val.each_byte do |b|
      if(b > 127) then
        utf16 = true
        break
      end
    end
    if(utf16) then
      bdata = Binary.type_bytes("6",Binary.charset_strlen(val,"UTF-8")) # 6 is 0110, unicode string (utf16be)
      val = Binary.charset_convert(val,"UTF-8","UTF-16BE")
      val.force_encoding("ASCII-8BIT") if val.respond_to?("encode")
      @object_table[saved_object_count] = bdata + val
    else
      bdata = Binary.type_bytes("5",val.bytesize) # 5 is 0101 which is an ASCII string (seems to be ASCII encoded)
      @object_table[saved_object_count] = bdata + val
    end
  else
    saved_object_count = @unique_table[val]
  end
  return saved_object_count
end