private static void marshall()

in DynamoDbEncryption/runtimes/java/src/main/sdkv1/com/amazonaws/services/dynamodbv2/datamodeling/internal/AttributeValueMarshaller.java [81:154]


  private static void marshall(
    final AttributeValue attributeValue,
    final DataOutputStream out
  ) throws IOException {
    if (attributeValue.getB() != null) {
      out.writeChar('b');
      writeBytes(attributeValue.getB(), out);
    } else if (attributeValue.getBS() != null) {
      out.writeChar('B');
      writeBytesList(attributeValue.getBS(), out);
    } else if (attributeValue.getN() != null) {
      out.writeChar('n');
      writeString(trimZeros(attributeValue.getN()), out);
    } else if (attributeValue.getNS() != null) {
      out.writeChar('N');

      final List<String> ns = new ArrayList<String>(
        attributeValue.getNS().size()
      );
      for (final String n : attributeValue.getNS()) {
        ns.add(trimZeros(n));
      }
      writeStringList(ns, out);
    } else if (attributeValue.getS() != null) {
      out.writeChar('s');
      writeString(attributeValue.getS(), out);
    } else if (attributeValue.getSS() != null) {
      out.writeChar('S');
      writeStringList(attributeValue.getSS(), out);
    } else if (attributeValue.getBOOL() != null) {
      out.writeChar('?');
      out.writeByte((attributeValue.getBOOL() ? TRUE_FLAG : FALSE_FLAG));
    } else if (Boolean.TRUE.equals(attributeValue.getNULL())) {
      out.writeChar('\0');
    } else if (attributeValue.getL() != null) {
      final List<AttributeValue> l = attributeValue.getL();
      out.writeChar('L');
      out.writeInt(l.size());
      for (final AttributeValue attr : l) {
        if (attr == null) {
          throw new NullPointerException(
            "Encountered null list entry value while marshalling attribute value " +
            attributeValue
          );
        }
        marshall(attr, out);
      }
    } else if (attributeValue.getM() != null) {
      final Map<String, AttributeValue> m = attributeValue.getM();
      final List<String> mKeys = new ArrayList<String>(m.keySet());
      Collections.sort(mKeys);
      out.writeChar('M');
      out.writeInt(m.size());
      for (final String mKey : mKeys) {
        marshall(new AttributeValue().withS(mKey), out);

        final AttributeValue mValue = m.get(mKey);

        if (mValue == null) {
          throw new NullPointerException(
            "Encountered null map value for key " +
            mKey +
            " while marshalling attribute value " +
            attributeValue
          );
        }
        marshall(mValue, out);
      }
    } else {
      throw new IllegalArgumentException(
        "A seemingly empty AttributeValue is indicative of invalid input or potential errors"
      );
    }
  }