Ejemplo n.º 1
0
    @SuppressWarnings("unchecked")
    @Override
    protected void _writeTo(SerializationContext ctx, Object inst, BinaryOutput dst)
        throws IOException, IllegalArgumentException, IllegalAccessException {
      try {
        final Object[] ar = (Object[]) _field.get(inst);
        if (ar == null) return;

        for (int i = 0; i < ar.length; i++) {
          if (ar[i] == null) continue;
          else if (_component_type_ba != null) {
            _component_type_ba.writeTo(ctx, ar[i], dst);
          } else {
            _ba_fac.getBinaryAccessor(ar[i].getClass()).writeTo(ctx, ar[i], dst);
          }
        }
        //				if (_fields_type_ba == null) {
        //					final BinaryAccessor ba = _ba_fac.getBinaryAccessor(obj.getClass());
        //					ba.writeTo(ctx, obj, dst);
        //				} else {
        //					_fields_type_ba.writeTo(ctx, obj, dst);
        //				}
        //				for (int i = 0; i < ar.length; _component_type_ba.writeTo(ctx, ar[i++], dst));
      } catch (Exception e) {
        throw new IOException(e);
      }
    }
Ejemplo n.º 2
0
    @SuppressWarnings("unchecked")
    @Override
    protected void _readFrom(SerializationContext ctx, Object inst, BinaryInput src)
        throws IOException, IllegalArgumentException, IllegalAccessException {
      try {
        final int size = _size_ind.getArraySize(src, inst, _field);
        Object ar = _field.get(inst);
        if (ar == null || Array.getLength(ar) != size)
          ar = Array.newInstance(_component_type, size);

        for (int i = 0; i < size; i++) {
          Object component_inst = _component_instor.getConcreteClassInstance(inst, inst, _field);
          if (component_inst == null) {
            Array.set(ar, i, null);
          } else if (_component_type_ba != null) {
            Array.set(ar, i, _component_type_ba.readFrom(ctx, component_inst, src));
          } else {
            Array.set(
                ar,
                i,
                _ba_fac
                    .getBinaryAccessor(component_inst.getClass())
                    .readFrom(ctx, component_inst, src));
          }
        }
        _field.set(inst, ar);
      } catch (Exception e) {
        throw new IOException(e);
      }
    }