cdm/src/main/java/ucar/ma2/StructureDataDeep.java
static public int copyToArrayBB(StructureData sdata, ArrayStructureBB abb) {
    //StructureMembers sm = sdata.getStructureMembers();
    ByteBuffer bb = abb.getByteBuffer();
    int start = bb.limit();

    for (StructureMembers.Member wantMember : abb.getMembers()) {
      StructureMembers.Member m = sdata.findMember(wantMember.getName());
      assert m != null;
      assert m.getDataType() == wantMember.getDataType();

      DataType dtype = m.getDataType();
      //System.out.printf("do %s (%s) = %d%n", m.getName(), m.getDataType(), bb.position());
      if (m.isScalar()) {
        switch (dtype) {
          case STRING:
            bb.putInt(abb.addObjectToHeap(sdata.getScalarString(m)));
            break;
          case FLOAT:
            bb.putFloat(sdata.getScalarFloat(m));
            break;
          case DOUBLE:
            bb.putDouble(sdata.getScalarDouble(m));
            break;
          case INT:
          case UINT:
          case ENUM4:
            bb.putInt(sdata.getScalarInt(m));
            break;
          case SHORT:
          case USHORT:
          case ENUM2:
            bb.putShort(sdata.getScalarShort(m));
            break;
          case BYTE:
          case UBYTE:
          case ENUM1:
            bb.put(sdata.getScalarByte(m));
            break;
          case CHAR:
            bb.put((byte) sdata.getScalarChar(m));
            break;
          case LONG:
          case ULONG:
            bb.putLong(sdata.getScalarLong(m));
            break;
          case STRUCTURE:
            StructureData sd  = sdata.getScalarStructure(m);
            ArrayStructureBB out_abb = new ArrayStructureBB(sd.getStructureMembers(),
                    new int[]{1}, bb, 0);
            copyToArrayBB(sd, out_abb);
            break;
          default:
            throw new IllegalStateException("scalar " + dtype.toString());
            /* case BOOLEAN:
           break;
         case SEQUENCE:
           break;
         case OPAQUE:
           break; */
        }
      } else {
        int n = m.getSize();
        switch (dtype) {
          case STRING:
            String[] ss = sdata.getJavaArrayString(m);
            bb.putInt(abb.addObjectToHeap(ss)); // stored as String[] on the heap
            break;
          case FLOAT:
            float[] fdata = sdata.getJavaArrayFloat(m);
            for (int i = 0; i < n; i++)
              bb.putFloat(fdata[i]);
            break;
          case DOUBLE:
            double[] ddata = sdata.getJavaArrayDouble(m);
            for (int i = 0; i < n; i++)
              bb.putDouble(ddata[i]);
            break;
          case INT:
          case ENUM4:
            int[] idata = sdata.getJavaArrayInt(m);
            for (int i = 0; i < n; i++)
              bb.putInt(idata[i]);
            break;
          case SHORT:
          case ENUM2:
            short[] shdata = sdata.getJavaArrayShort(m);
            for (int i = 0; i < n; i++)
              bb.putShort(shdata[i]);
            break;
          case BYTE:
          case ENUM1:
            byte[] bdata = sdata.getJavaArrayByte(m);
            for (int i = 0; i < n; i++)
              bb.put(bdata[i]);
            break;
          case CHAR:
            char[] cdata = sdata.getJavaArrayChar(m);
            bb.put(IospHelper.convertCharToByte(cdata));
            break;
          case LONG:
            long[] ldata = sdata.getJavaArrayLong(m);
            for (int i = 0; i < n; i++)
              bb.putLong(ldata[i]);
            break;
          default:
            throw new IllegalStateException("array " + dtype.toString());
            /* case BOOLEAN:
          break;
         case OPAQUE:
          break;
        case STRUCTURE:
          break; // */
          case SEQUENCE:
            break; // skip
        }
      }
    }
    return bb.limit() - start;
  }
static public int copyToArrayBB(StructureData sdata, ArrayStructureBB abb) {
    //StructureMembers sm = sdata.getStructureMembers();
    ByteBuffer bb = abb.getByteBuffer();
    int start = bb.limit();

    for (StructureMembers.Member wantMember : abb.getMembers()) {
      StructureMembers.Member m = sdata.findMember(wantMember.getName());
      assert m != null;
      assert m.getDataType() == wantMember.getDataType();

      DataType dtype = m.getDataType();
      //System.out.printf("do %s (%s) = %d%n", m.getName(), m.getDataType(), bb.position());
      if (m.isScalar()) {
        switch (dtype) {
          case STRING:
            bb.putInt(abb.addObjectToHeap(sdata.getScalarString(m)));
            break;
          case FLOAT:
            bb.putFloat(sdata.getScalarFloat(m));
            break;
          case DOUBLE:
            bb.putDouble(sdata.getScalarDouble(m));
            break;
          case INT:
          case UINT:
          case ENUM4:
            bb.putInt(sdata.getScalarInt(m));
            break;
          case SHORT:
          case USHORT:
          case ENUM2:
            bb.putShort(sdata.getScalarShort(m));
            break;
          case BYTE:
          case UBYTE:
          case ENUM1:
            bb.put(sdata.getScalarByte(m));
            break;
          case CHAR:
            bb.put((byte) sdata.getScalarChar(m));
            break;
          case LONG:
          case ULONG:
            bb.putLong(sdata.getScalarLong(m));
            break;
          case STRUCTURE:
            StructureData sd  = sdata.getScalarStructure(m);
            ArrayStructureBB out_abb = new ArrayStructureBB(sd.getStructureMembers(),
                    new int[]{1}, bb, 0);
            copyToArrayBB(sd, out_abb);
            break;
          default:
            throw new IllegalStateException("scalar " + dtype.toString());
            /* case BOOLEAN:
           break;
         case SEQUENCE:
           break;
         case OPAQUE:
           break; */
        }
      } else {
        int n = m.getSize();
        switch (dtype) {
          case STRING:
            String[] ss = sdata.getJavaArrayString(m);
            bb.putInt(abb.addObjectToHeap(ss)); // stored as String[] on the heap
            break;
          case FLOAT:
            float[] fdata = sdata.getJavaArrayFloat(m);
            for (int i = 0; i < n; i++)
              bb.putFloat(fdata[i]);
            break;
          case DOUBLE:
            double[] ddata = sdata.getJavaArrayDouble(m);
            for (int i = 0; i < n; i++)
              bb.putDouble(ddata[i]);
            break;
          case INT:
          case ENUM4:
            int[] idata = sdata.getJavaArrayInt(m);
            for (int i = 0; i < n; i++)
              bb.putInt(idata[i]);
            break;
          case SHORT:
          case ENUM2:
            short[] shdata = sdata.getJavaArrayShort(m);
            for (int i = 0; i < n; i++)
              bb.putShort(shdata[i]);
            break;
          case BYTE:
          case ENUM1:
            byte[] bdata = sdata.getJavaArrayByte(m);
            for (int i = 0; i < n; i++)
              bb.put(bdata[i]);
            break;
          case CHAR:
            char[] cdata = sdata.getJavaArrayChar(m);
            bb.put(IospHelper.convertCharToByte(cdata));
            break;
          case LONG:
            long[] ldata = sdata.getJavaArrayLong(m);
            for (int i = 0; i < n; i++)
              bb.putLong(ldata[i]);
            break;
          default:
            throw new IllegalStateException("array " + dtype.toString());
            /* case BOOLEAN:
          break;
         case OPAQUE:
          break;
        case STRUCTURE:
          break; // */
          case SEQUENCE:
            break; // skip
        }
      }
    }
    return bb.limit() - start;
  }
Make deep copy from a StructureData into the given ArrayStructureBB
@param sdata    original data from here
@param abb      copy data into this ArrayStructureBB, starting from wherever the ByteBuffer current position is
@return number of bytes copied