/** {@inheritDoc} */
  @Override
  public BinaryObject buildEnum(String typeName, int ord) throws IgniteException {
    typeName = PortableContext.typeName(typeName);

    int typeId = portableCtx.typeId(typeName);

    updateMetadata(typeId, typeName, null, null, true);

    return new BinaryEnumObjectImpl(portableCtx, typeId, null, ord);
  }
  /** {@inheritDoc} */
  @Override
  public void updateMetadata(
      int typeId,
      String typeName,
      @Nullable String affKeyFieldName,
      Map<String, Integer> fieldTypeIds,
      boolean isEnum)
      throws BinaryObjectException {
    BinaryMetadata meta =
        new BinaryMetadata(typeId, typeName, fieldTypeIds, affKeyFieldName, null, isEnum);

    portableCtx.updateMetadata(typeId, meta);
  }
  /**
   * @param po Portable object.
   * @return Affinity key.
   */
  public Object affinityKey(BinaryObject po) {
    try {
      BinaryType meta = po.type();

      if (meta != null) {
        String affKeyFieldName = meta.affinityKeyFieldName();

        if (affKeyFieldName != null) return po.field(affKeyFieldName);
      } else if (po instanceof BinaryObjectEx) {
        int id = ((BinaryObjectEx) po).typeId();

        String affKeyFieldName = portableCtx.affinityKeyFieldName(id);

        if (affKeyFieldName != null) return po.field(affKeyFieldName);
      }
    } catch (BinaryObjectException e) {
      U.error(log, "Failed to get affinity field from portable object: " + po, e);
    }

    return po;
  }
  /** {@inheritDoc} */
  @Override
  public int typeId(String typeName) {
    if (portableCtx == null) return super.typeId(typeName);

    return portableCtx.typeId(typeName);
  }