static long sizeOf(Mutation m) {
    if (m.getOperation() == Mutation.Op.DELETE) {
      return sizeOf(m.getKeySet());
    }
    long result = 0;
    for (Value v : m.getValues()) {
      switch (v.getType().getCode()) {
        case ARRAY:
          result += estimateArrayValue(v);
          break;
        case STRUCT:
          throw new IllegalArgumentException("Structs are not supported in mutation.");
        default:
          result += estimatePrimitiveValue(v);
      }
    }
    return result;
  }
@Test
  public void primitiveArrays() throws Exception {
    Mutation int64 =
        Mutation.newInsertOrUpdateBuilder("test")
            .set("one")
            .toInt64Array(new long[] {1L, 2L, 3L})
            .build();
    Mutation float32 =
        Mutation.newInsertOrUpdateBuilder("test")
            .set("one")
            .toFloat32Array(new float[] {1.0f, 2.0f})
            .build();
    Mutation float64 =
        Mutation.newInsertOrUpdateBuilder("test")
            .set("one")
            .toFloat64Array(new double[] {1., 2.})
            .build();
    Mutation bool =
        Mutation.newInsertOrUpdateBuilder("test")
            .set("one")
            .toBoolArray(new boolean[] {true, true, false, true})
            .build();
    Mutation numeric =
        Mutation.newInsertOrUpdateBuilder("test")
            .set("one")
            .toNumericArray(
                ImmutableList.of(
                    new BigDecimal("12345678901234567890.123456789"),
                    new BigDecimal("12345678901234567890123.1234567890123"),
                    new BigDecimal("123456789012345678901234.1234567890123456"),
                    new BigDecimal("1234567890123456789012345.1234567890123456789")))
            .build();
    Mutation pgNumeric =
        Mutation.newInsertOrUpdateBuilder("test")
            .set("one")
            .toPgNumericArray(
                ImmutableList.of(
                    "12345678901234567890.123456789",
                    "12345678901234567890123.1234567890123",
                    "123456789012345678901234.1234567890123456",
                    "1234567890123456789012345.1234567890123456789",
                    "NaN"))
            .build();

    Mutation json =
        Mutation.newInsertOrUpdateBuilder("test")
            .set("one")
            .toJsonArray(
                ImmutableList.of(
                    "{\"key1\":\"value1\", \"key2\":\"value2\"}",
                    "{\"key1\":\"value1\", \"key2\":20}"))
            .build();
    Mutation bytes =
        Mutation.newInsertOrUpdateBuilder("test")
            .set("bytes")
            .toBytesArray(
                ImmutableList.of(
                    ByteArray.copyFrom("some_bytes".getBytes(UTF_8)),
                    ByteArray.copyFrom("some_bytes".getBytes(UTF_8))))
            .build();
    Mutation jsonb =
        Mutation.newInsertOrUpdateBuilder("test")
            .set("one")
            .toPgJsonbArray(
                ImmutableList.of(
                    "{\"key123\":\"value123\", \"key321\":\"value321\"}",
                    "{\"key456\":\"value456\", \"key789\":600}"))
            .build();
    Mutation protoEnum =
        Mutation.newInsertOrUpdateBuilder("test")
            .set("one")
            .toProtoEnumArray(ImmutableList.of(1L, 2L, 3L), "customer.app.TestEnum")
            .build();
    Mutation protos =
        Mutation.newInsertOrUpdateBuilder("test")
            .set("bytes")
            .toProtoMessageArray(
                ImmutableList.of(
                    ByteArray.copyFrom("some_bytes".getBytes(UTF_8)),
                    ByteArray.copyFrom("some_bytes".getBytes(UTF_8))),
                "customer.app.TestMessage")
            .build();
    assertThat(MutationSizeEstimator.sizeOf(int64), is(24L));
    assertThat(MutationSizeEstimator.sizeOf(float32), is(8L));
    assertThat(MutationSizeEstimator.sizeOf(float64), is(16L));
    assertThat(MutationSizeEstimator.sizeOf(bool), is(4L));
    assertThat(MutationSizeEstimator.sizeOf(numeric), is(153L));
    assertThat(MutationSizeEstimator.sizeOf(pgNumeric), is(156L));
    assertThat(MutationSizeEstimator.sizeOf(json), is(62L));
    assertThat(MutationSizeEstimator.sizeOf(bytes), is(20L));
    assertThat(MutationSizeEstimator.sizeOf(jsonb), is(77L));
    assertThat(MutationSizeEstimator.sizeOf(protoEnum), is(24L));
    assertThat(MutationSizeEstimator.sizeOf(protos), is(20L));
  }