code: @Override
      public void writeMap(Map<Object, Object> map) {
          writeAMF3();
          buf.put(AMF3.TYPE_ARRAY);
          if (hasReference(map)) {
              putInteger(getReferenceId(map) << 1);
              return;
          }
          storeReference(map);
          // Search number of starting integer keys
          int count = 0;
          for (int i = 0; i < map.size(); i++) {
              try {
                  if (!map.containsKey(i)) {
                      break;
                  }
              } catch (ClassCastException err) {
                  // Map has non-number keys.
                  break;
              }
              count++;
          }
          amf3_mode += 1;
          if (count == map.size()) {
              // All integer keys starting from zero: serialize as regular array
              putInteger(count << 1 | 1);
              putString("");
              for (int i = 0; i < count; i++) {
                  Serializer.serialize(this, map.get(i));
              }
              amf3_mode -= 1;
              return;
          }
          putInteger(count << 1 | 1);
          // Serialize key-value pairs first
          for (Map.Entry<Object, Object> entry : map.entrySet()) {
              Object key = entry.getKey();
              if ((key instanceof Number) && !(key instanceof Float) && !(key instanceof Double) && ((Number) key).longValue() >= 0 && ((Number) key).longValue() < count) {
                  // Entry will be serialized later
                  continue;
              }
              putString(key.toString());
              Serializer.serialize(this, entry.getValue());
          }
          putString("");
          // Now serialize integer keys starting from zero
          for (int i = 0; i < count; i++) {
              Serializer.serialize(this, map.get(i));
          }
          amf3_mode -= 1;
      }
docs: {@inheritDoc}