writeBoolean(fieldName, value.booleanValue());
}
private void writePrimitiveCollection(FieldDescriptor fd, Collection<?> collection, Class elementClass) throws IOException {
CodedOutputStream out = messageContext.out;
int fieldNumber = fd.getNumber();
Type type = fd.getType();
switch (type) {
case DOUBLE:
for (Object value : collection) { //todo check (value != null && value.getClass() == elementClass)
out.writeDouble(fieldNumber, (Double) value);
}
break;
case FLOAT:
for (Object value : collection) {
out.writeFloat(fieldNumber, (Float) value);
}
break;
case BOOL:
for (Object value : collection) {
out.writeBool(fieldNumber, (Boolean) value);
}
break;
case STRING:
for (Object value : collection) {
out.writeString(fieldNumber, (String) value);
}
break;
case BYTES:
for (Object value : collection) {
if (value instanceof byte[]) {
value = ByteString.copyFrom((byte[]) value);
}
out.writeBytes(fieldNumber, (ByteString) value);
}
break;
case INT64:
for (Object value : collection) {
out.writeInt64(fieldNumber, (Long) value);
}
break;
case UINT64:
for (Object value : collection) {
out.writeUInt64(fieldNumber, (Long) value);
}
break;
case FIXED64:
for (Object value : collection) {
out.writeFixed64(fieldNumber, (Long) value);
}
break;
case SFIXED64:
for (Object value : collection) {
out.writeSFixed64(fieldNumber, (Long) value);
}
break;
case SINT64:
for (Object value : collection) {
out.writeSInt64(fieldNumber, (Long) value);
}
break;
case INT32:
for (Object value : collection) {
out.writeInt32(fieldNumber, (Integer) value);
}
break;
case FIXED32:
for (Object value : collection) {
out.writeFixed32(fieldNumber, (Integer) value);
}
break;
case UINT32:
for (Object value : collection) {
out.writeUInt32(fieldNumber, (Integer) value);
}
break;
case SFIXED32:
for (Object value : collection) {
out.writeSFixed32(fieldNumber, (Integer) value);
}
break;
case SINT32:
for (Object value : collection) {
out.writeSInt32(fieldNumber, (Integer) value);
}
break;
default:
throw new IllegalStateException("Unexpected field type : " + type);
}