Package org.infinispan.protostream.descriptors

Examples of org.infinispan.protostream.descriptors.FieldDescriptor


      writeDouble(fieldName, value.doubleValue());
   }

   @Override
   public void writeFloat(String fieldName, float value) throws IOException {
      FieldDescriptor fd = messageContext.marshallerDelegate.getFieldsByName().get(fieldName);

      checkFieldWrite(fd, false);

      switch (fd.getType()) {
         case FLOAT:
            messageContext.out.writeFloat(fd.getNumber(), value);
            break;
         default:
            throw new IllegalArgumentException("The declared field type is not compatible with the written type : " + fieldName);
      }
   }
View Full Code Here


      }
   }

   @Override
   public void writeFloat(String fieldName, Float value) throws IOException {
      FieldDescriptor fd = messageContext.marshallerDelegate.getFieldsByName().get(fieldName);

      if (value == null) {
         if (fd.isRequired()) {
            throw new IllegalArgumentException("A required field cannot be null : " + fieldName);
         }
         return;
      }
View Full Code Here

      writeFloat(fieldName, value.floatValue());
   }

   @Override
   public void writeBoolean(String fieldName, boolean value) throws IOException {
      FieldDescriptor fd = messageContext.marshallerDelegate.getFieldsByName().get(fieldName);

      checkFieldWrite(fd, false);

      switch (fd.getType()) {
         case BOOL:
            messageContext.out.writeBool(fd.getNumber(), value);
            break;
         default:
            throw new IllegalArgumentException("The declared field type is not compatible with the written type : " + fieldName);
      }
   }
View Full Code Here

      }
   }

   @Override
   public void writeBoolean(String fieldName, Boolean value) throws IOException {
      FieldDescriptor fd = messageContext.marshallerDelegate.getFieldsByName().get(fieldName);

      if (value == null) {
         if (fd.isRequired()) {
            throw new IllegalArgumentException("A required field cannot be null : " + fieldName);
         }
         return;
      }
View Full Code Here

      }
   }

   @Override
   public void writeString(String fieldName, String value) throws IOException {
      FieldDescriptor fd = messageContext.marshallerDelegate.getFieldsByName().get(fieldName);

      if (value == null) {
         if (fd.isRequired()) {
            throw new IllegalArgumentException("A required field cannot be null : " + fieldName);
         }
         return;
      }

      checkFieldWrite(fd, false);

      if (fd.getType() != Type.STRING) {
         throw new IllegalArgumentException("Declared field type is not of type String : " + fieldName);
      }

      //TODO this is a big performance problem due to usage of the notoriously inefficient String.getBytes in CodedOutputStream.writeStringNoTag
      messageContext.out.writeString(fd.getNumber(), value);
   }
View Full Code Here

      messageContext.out.writeString(fd.getNumber(), value);
   }

   @Override
   public void writeBytes(String fieldName, byte[] value) throws IOException {
      FieldDescriptor fd = messageContext.marshallerDelegate.getFieldsByName().get(fieldName);

      if (value == null) {
         if (fd.isRequired()) {
            throw new IllegalArgumentException("A required field cannot be null : " + fieldName);
         }
         return;
      }

      checkFieldWrite(fd, false);

      if (fd.getType() != Type.BYTES) {
         throw new IllegalArgumentException("Declared field type is not of type byte[] : " + fieldName);
      }

      messageContext.out.writeTag(fd.getNumber(), WireFormat.WIRETYPE_LENGTH_DELIMITED);
      messageContext.out.writeRawVarint32(value.length);
      messageContext.out.writeRawBytes(value);
   }
View Full Code Here

      messageContext.out.writeRawBytes(value);
   }

   @Override
   public <E> void writeObject(String fieldName, E value, Class<? extends E> clazz) throws IOException {
      FieldDescriptor fd = messageContext.marshallerDelegate.getFieldsByName().get(fieldName);

      if (value == null) {
         if (fd.isRequired()) {
            throw new IllegalArgumentException("A required field cannot be null : " + fieldName);
         }
         return;
      }

      checkFieldWrite(fd, false);

      if (fd.getType() == Type.GROUP) {
         writeGroup(fieldName, fd, value, clazz);
      } else if (fd.getType() == Type.MESSAGE) {
         writeMessage(fieldName, fd, value, clazz);
      } else if (fd.getType() == Type.ENUM) {
         writeEnum(fieldName, fd, (Enum) value);
      } else {
         throw new IllegalArgumentException("Declared field type is not a message or an enum : " + fieldName);
      }
   }
View Full Code Here

      marshallerDelegate.marshall(fieldName, fd, value, this, messageContext.out);
   }

   @Override
   public <E> void writeCollection(String fieldName, Collection<? super E> collection, Class<E> elementClass) throws IOException {
      FieldDescriptor fd = messageContext.marshallerDelegate.getFieldsByName().get(fieldName);

      if (collection == null) {
         // a repeated field is never flagged as required
         return;
      }

      checkFieldWrite(fd, true);

      if (fd.getType() == Type.GROUP) {
         for (Object t : collection) {
            writeGroup(fieldName, fd, t, elementClass);
         }
      } else if (fd.getType() == Type.MESSAGE) {
         for (Object t : collection) {
            writeMessage(fieldName, fd, t, elementClass);
         }
      } else if (fd.getType() == Type.ENUM) {
         for (Object t : collection) {
            writeEnum(fieldName, fd, (Enum) t);
         }
      } else {
         writePrimitiveCollection(fd, collection, elementClass);
View Full Code Here

      }
   }

   @Override
   public <E> void writeArray(String fieldName, E[] array, Class<? extends E> elementClass) throws IOException {
      FieldDescriptor fd = messageContext.marshallerDelegate.getFieldsByName().get(fieldName);

      if (array == null) {
         // a repeated field is never flagged as required
         return;
      }

      checkFieldWrite(fd, true);

      if (fd.getType() == Type.GROUP) {
         for (Object t : array) {
            writeGroup(fieldName, fd, t, elementClass);
         }
      } else if (fd.getType() == Type.MESSAGE) {
         for (Object t : array) {
            writeMessage(fieldName, fd, t, elementClass);
         }
      } else if (fd.getType() == Type.ENUM) {
         for (Object t : array) {
            writeEnum(fieldName, fd, (Enum) t);
         }
      } else {
         writePrimitiveCollection(fd, Arrays.asList(array), elementClass);   //todo [anistor] optimize away the Arrays.asList( )
View Full Code Here

      out.flush();
   }

   @Override
   public void writeInt(String fieldName, Integer value) throws IOException {
      FieldDescriptor fd = messageContext.marshallerDelegate.getFieldsByName().get(fieldName);

      if (value == null) {
         if (fd.isRequired()) {
            throw new IllegalArgumentException("A required field cannot be null : " + fieldName);
         }
         return;
      }
View Full Code Here

TOP

Related Classes of org.infinispan.protostream.descriptors.FieldDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.