Examples of UnknownFieldSet


Examples of org.infinispan.protostream.UnknownFieldSet

         ((MessageMarshaller) marshaller).writeTo(this, value);
      } else {
         ((RawProtobufMarshaller) marshaller).writeTo(ctx, out, value);
      }
      if (value instanceof Message) {
         UnknownFieldSet unknownFieldSet = ((Message) value).getUnknownFieldSet();
         if (unknownFieldSet != null) {
            // TODO check that the unknown field set does not contains fields that have already been written or fields that are actually known already
            unknownFieldSet.writeTo(messageContext.out);
         }
      }
   }
View Full Code Here

Examples of org.infinispan.protostream.UnknownFieldSet

         ((MessageMarshaller) marshaller).writeTo(this, value);
      } else {
         ((RawProtobufMarshaller) marshaller).writeTo(ctx, out, value);
      }
      if (value instanceof Message) {
         UnknownFieldSet unknownFieldSet = ((Message) value).getUnknownFieldSet();
         if (unknownFieldSet != null) {
            // TODO check that the unknown field set does not contains fields that have already been written or fields that are actually known already
            unknownFieldSet.writeTo(messageContext.out);
         }
      }
   }
View Full Code Here

Examples of org.infinispan.protostream.UnknownFieldSet

      WriteMessageContext messageContext = writer.pushContext(fieldName, this, out);

      marshaller.writeTo(writer, value);

      if (value instanceof Message) {
         UnknownFieldSet unknownFieldSet = ((Message) value).getUnknownFieldSet();
         if (unknownFieldSet != null) {
            // validate that none of the unknown fields are also declared by the known descriptor
            for (Descriptors.FieldDescriptor fd : getFieldDescriptors()) {
               if (unknownFieldSet.hasTag(WireFormat.makeTag(fd.getNumber(), fd.getLiteType().getWireType()))) {
                  throw new IOException("Field " + fd.getFullName() + " is a known field so it is illegal to be present in the unknown field set");
               }
            }
            // write the unknown fields
            unknownFieldSet.writeTo(messageContext.out);
         }
      }

      UnknownFieldSet unknownFieldSet = value instanceof Message ? ((Message) value).getUnknownFieldSet() : null;

      // validate that all the required fields were written either by the marshaller or by the UnknownFieldSet
      for (Descriptors.FieldDescriptor fd : getFieldDescriptors()) {
         if (fd.isRequired() && !messageContext.isFieldMarked(fd.getNumber())
               && (unknownFieldSet == null || !unknownFieldSet.hasTag(WireFormat.makeTag(fd.getNumber(), fd.getLiteType().getWireType())))) {
            throw new IllegalStateException("Required field \"" + fd.getFullName()
                                                  + "\" should have been written by a calling a suitable method of "
                                                  + MessageMarshaller.ProtoStreamWriter.class.getName());
         }
      }
View Full Code Here

Examples of org.infinispan.protostream.UnknownFieldSet

   @Override
   public T unmarshall(String fieldName, Descriptors.FieldDescriptor fieldDescriptor, ProtoStreamReaderImpl reader, CodedInputStream in) throws IOException {
      final int expectedTag = WireFormat.makeTag(fieldDescriptor.getNumber(), WireFormat.WIRETYPE_VARINT);
      int enumValue;
      UnknownFieldSet unknownFieldSet = reader.getUnknownFieldSet();
      Object o = unknownFieldSet.consumeTag(expectedTag);
      if (o != null) {
         enumValue = ((Long) o).intValue();
      } else {
         while (true) {
            int tag = in.readTag();
            if (tag == 0) {
               return null;
            }
            if (tag == expectedTag) {
               enumValue = in.readEnum();
               break;
            }
            unknownFieldSet.readSingleField(tag, in);
         }
      }

      T decoded = enumMarshaller.decode(enumValue);

      if (decoded == null) {
         // the enum value was not recognized by the decoder so rather than discarding it we add it to the unknown
         unknownFieldSet.putVarintField(expectedTag, enumValue);
      }

      return decoded;
   }
View Full Code Here

Examples of org.infinispan.protostream.UnknownFieldSet

      byte[] bytes = ProtobufUtil.toByteArray(ctx, user);

      ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
      CodedInputStream codedInputStream = CodedInputStream.newInstance(bais);
      UnknownFieldSet unknownFieldSet = new UnknownFieldSetImpl();
      unknownFieldSet.readAllFields(codedInputStream);

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      CodedOutputStream out = CodedOutputStream.newInstance(baos);
      unknownFieldSet.writeTo(out);
      byte[] bytes2 = baos.toByteArray();

      assertArrayEquals(bytes, bytes2);
   }
View Full Code Here

Examples of org.infinispan.protostream.UnknownFieldSet

      byte[] bytes = ProtobufUtil.toByteArray(ctx, user);

      ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
      CodedInputStream codedInputStream = CodedInputStream.newInstance(bais);
      UnknownFieldSet unknownFieldSet = new UnknownFieldSetImpl();
      unknownFieldSet.readAllFields(codedInputStream);

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      CodedOutputStream out = CodedOutputStream.newInstance(baos);
      unknownFieldSet.writeTo(out);
      byte[] bytes2 = baos.toByteArray();

      assertArrayEquals(bytes, bytes2);
   }
View Full Code Here

Examples of org.infinispan.protostream.UnknownFieldSet

   }

   private void marshall(Object value, MessageMarshaller marshaller) throws IOException {
      marshaller.writeTo(this, value);
      if (value instanceof Message) {
         UnknownFieldSet unknownFieldSet = ((Message) value).getUnknownFieldSet();
         if (unknownFieldSet != null) {
            // TODO check that the unknown field set does not contains fields that have already been written or fields that are actually known already
            unknownFieldSet.writeTo(messageContext.out);
         }
      }
   }
View Full Code Here

Examples of org.infinispan.protostream.UnknownFieldSet

   @Override
   public T unmarshall(String fieldName, FieldDescriptor fieldDescriptor, ProtoStreamReaderImpl reader, CodedInputStream in) throws IOException {
      final int expectedTag = WireFormat.makeTag(fieldDescriptor.getNumber(), WireFormat.WIRETYPE_VARINT);
      int enumValue;
      UnknownFieldSet unknownFieldSet = reader.getUnknownFieldSet();
      Object o = unknownFieldSet.consumeTag(expectedTag);
      if (o != null) {
         enumValue = ((Long) o).intValue();
      } else {
         while (true) {
            int tag = in.readTag();
            if (tag == 0) {
               return null;
            }
            if (tag == expectedTag) {
               enumValue = in.readEnum();
               break;
            }
            unknownFieldSet.readSingleField(tag, in);
         }
      }

      T decoded = enumMarshaller.decode(enumValue);

      if (decoded == null) {
         // the enum value was not recognized by the decoder so rather than discarding it we add it to the unknown
         unknownFieldSet.putVarintField(expectedTag, enumValue);
      }

      return decoded;
   }
View Full Code Here

Examples of org.infinispan.protostream.UnknownFieldSet

      WriteMessageContext messageContext = writer.pushContext(fieldName, this, out);

      marshaller.writeTo(writer, value);

      if (value instanceof Message) {
         UnknownFieldSet unknownFieldSet = ((Message) value).getUnknownFieldSet();
         if (unknownFieldSet != null) {
            // validate that none of the unknown fields are also declared by the known descriptor
            for (FieldDescriptor fd : getFieldDescriptors()) {
               if (unknownFieldSet.hasTag(WireFormat.makeTag(fd.getNumber(), fd.getType().getWireType()))) {
                  throw new IOException("Field " + fd.getFullName() + " is a known field so it is illegal to be present in the unknown field set");
               }
            }
            // write the unknown fields
            unknownFieldSet.writeTo(messageContext.out);
         }
      }

      UnknownFieldSet unknownFieldSet = value instanceof Message ? ((Message) value).getUnknownFieldSet() : null;

      // validate that all the required fields were written either by the marshaller or by the UnknownFieldSet
      for (FieldDescriptor fd : getFieldDescriptors()) {
         if (fd.isRequired() && !messageContext.isFieldMarked(fd.getNumber())
               && (unknownFieldSet == null || !unknownFieldSet.hasTag(WireFormat.makeTag(fd.getNumber(), fd.getType().getWireType())))) {
            throw new IllegalStateException("Required field \"" + fd.getFullName()
                                                  + "\" should have been written by a calling a suitable method of "
                                                  + MessageMarshaller.ProtoStreamWriter.class.getName());
         }
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.