use of org.infinispan.protostream.descriptors.FieldDescriptor in project protostream by infinispan.
the class ProtoStreamWriterImpl method writeLong.
@Override
public void writeLong(String fieldName, long value) throws IOException {
final FieldDescriptor fd = messageContext.getFieldByName(fieldName);
checkFieldWrite(fd);
switch(fd.getType()) {
case INT64:
messageContext.out.writeInt64(fd.getNumber(), value);
break;
case UINT64:
messageContext.out.writeUInt64(fd.getNumber(), value);
break;
case FIXED64:
messageContext.out.writeFixed64(fd.getNumber(), value);
break;
case SFIXED64:
messageContext.out.writeSFixed64(fd.getNumber(), value);
break;
case SINT64:
messageContext.out.writeSInt64(fd.getNumber(), value);
break;
default:
throw new IllegalArgumentException("The Protobuf declared field type is not compatible with the written type : " + fd.getFullName());
}
}
use of org.infinispan.protostream.descriptors.FieldDescriptor in project protostream by infinispan.
the class ProtoStreamWriterImpl method writeInt.
@Override
public void writeInt(String fieldName, Integer value) throws IOException {
final FieldDescriptor fd = messageContext.getFieldByName(fieldName);
checkFieldWrite(fd);
if (value == null) {
if (fd.isRequired()) {
throw new IllegalArgumentException("A required field cannot be null : " + fd.getFullName());
}
return;
}
switch(fd.getType()) {
case INT32:
messageContext.out.writeInt32(fd.getNumber(), value);
break;
case FIXED32:
messageContext.out.writeFixed32(fd.getNumber(), value);
break;
case UINT32:
messageContext.out.writeUInt32(fd.getNumber(), value);
break;
case SFIXED32:
messageContext.out.writeSFixed32(fd.getNumber(), value);
break;
case SINT32:
messageContext.out.writeSInt32(fd.getNumber(), value);
break;
default:
throw new IllegalArgumentException("The Protobuf declared field type is not compatible with the written type : " + fd.getFullName());
}
}
use of org.infinispan.protostream.descriptors.FieldDescriptor in project protostream by infinispan.
the class ProtoStreamWriterImpl method writeLong.
@Override
public void writeLong(String fieldName, Long value) throws IOException {
final FieldDescriptor fd = messageContext.getFieldByName(fieldName);
checkFieldWrite(fd);
if (value == null) {
if (fd.isRequired()) {
throw new IllegalArgumentException("A required field cannot be null : " + fd.getFullName());
}
return;
}
switch(fd.getType()) {
case INT64:
messageContext.out.writeInt64(fd.getNumber(), value);
break;
case UINT64:
messageContext.out.writeUInt64(fd.getNumber(), value);
break;
case FIXED64:
messageContext.out.writeFixed64(fd.getNumber(), value);
break;
case SFIXED64:
messageContext.out.writeSFixed64(fd.getNumber(), value);
break;
case SINT64:
messageContext.out.writeSInt64(fd.getNumber(), value);
break;
default:
throw new IllegalArgumentException("The Protobuf declared field type is not compatible with the written type : " + fd.getFullName());
}
}
use of org.infinispan.protostream.descriptors.FieldDescriptor in project protostream by infinispan.
the class ProtoStreamWriterImpl method writeArray.
@Override
public <E> void writeArray(String fieldName, E[] array, Class<? extends E> elementClass) throws IOException {
final FieldDescriptor fd = messageContext.getFieldByName(fieldName);
checkRepeatedFieldWrite(fd);
if (array == null) {
// a repeated field can never be flagged as required
return;
}
final TagWriter out = messageContext.out;
final int fieldNumber = fd.getNumber();
switch(fd.getType()) {
case GROUP:
for (Object t : array) {
validateElement(t, elementClass);
writeGroup(fd, t, elementClass);
}
break;
case MESSAGE:
for (Object t : array) {
validateElement(t, elementClass);
writeMessage(fd, t, elementClass);
}
break;
case ENUM:
for (Object t : array) {
validateElement(t, elementClass);
writeEnum(fd, (Enum) t);
}
break;
case DOUBLE:
validateElementClass(elementClass, Double.class);
for (Object value : array) {
validateElement(value, elementClass);
out.writeDouble(fieldNumber, (Double) value);
}
break;
case FLOAT:
validateElementClass(elementClass, Float.class);
for (Object value : array) {
validateElement(value, elementClass);
out.writeFloat(fieldNumber, (Float) value);
}
break;
case BOOL:
validateElementClass(elementClass, Boolean.class);
for (Object value : array) {
validateElement(value, elementClass);
out.writeBool(fieldNumber, (Boolean) value);
}
break;
case STRING:
validateElementClass(elementClass, String.class);
for (Object value : array) {
validateElement(value, elementClass);
out.writeString(fieldNumber, (String) value);
}
break;
case BYTES:
validateElementClass(elementClass, byte[].class);
for (Object value : array) {
validateElement(value, elementClass);
out.writeBytes(fieldNumber, (byte[]) value);
}
break;
case INT64:
validateElementClass(elementClass, Long.class);
for (Object value : array) {
validateElement(value, elementClass);
out.writeInt64(fieldNumber, (Long) value);
}
break;
case UINT64:
validateElementClass(elementClass, Long.class);
for (Object value : array) {
validateElement(value, elementClass);
out.writeUInt64(fieldNumber, (Long) value);
}
break;
case FIXED64:
validateElementClass(elementClass, Long.class);
for (Object value : array) {
validateElement(value, elementClass);
out.writeFixed64(fieldNumber, (Long) value);
}
break;
case SFIXED64:
validateElementClass(elementClass, Long.class);
for (Object value : array) {
validateElement(value, elementClass);
out.writeSFixed64(fieldNumber, (Long) value);
}
break;
case SINT64:
validateElementClass(elementClass, Long.class);
for (Object value : array) {
validateElement(value, elementClass);
out.writeSInt64(fieldNumber, (Long) value);
}
break;
case INT32:
validateElementClass(elementClass, Integer.class);
for (Object value : array) {
validateElement(value, elementClass);
out.writeInt32(fieldNumber, (Integer) value);
}
break;
case FIXED32:
validateElementClass(elementClass, Integer.class);
for (Object value : array) {
validateElement(value, elementClass);
out.writeFixed32(fieldNumber, (Integer) value);
}
break;
case UINT32:
validateElementClass(elementClass, Integer.class);
for (Object value : array) {
validateElement(value, elementClass);
out.writeUInt32(fieldNumber, (Integer) value);
}
break;
case SFIXED32:
validateElementClass(elementClass, Integer.class);
for (Object value : array) {
validateElement(value, elementClass);
out.writeSFixed32(fieldNumber, (Integer) value);
}
break;
case SINT32:
validateElementClass(elementClass, Integer.class);
for (Object value : array) {
validateElement(value, elementClass);
out.writeSInt32(fieldNumber, (Integer) value);
}
break;
default:
throw new IllegalArgumentException("The Protobuf declared field type is not compatible with the written type : " + fd.getFullName());
}
}
use of org.infinispan.protostream.descriptors.FieldDescriptor in project protostream by infinispan.
the class ProtoStreamWriterImpl method writeFloat.
@Override
public void writeFloat(String fieldName, Float value) throws IOException {
final FieldDescriptor fd = messageContext.getFieldByName(fieldName);
if (fd.getType() != Type.FLOAT) {
throw new IllegalArgumentException("The Protobuf declared field type is not compatible with the written type : " + fd.getFullName());
}
checkFieldWrite(fd);
if (value == null) {
if (fd.isRequired()) {
throw new IllegalArgumentException("A required field cannot be null : " + fd.getFullName());
}
return;
}
messageContext.out.writeFloat(fd.getNumber(), value);
}
Aggregations