Package com.google.protobuf

Examples of com.google.protobuf.CodedInputStream$SkippedDataSink


    PackChunk.Members members = new PackChunk.Members();
    members.setChunkKey(key);

    // Its too slow to convert using the standard code, as copies
    // are made. Instead find offsets in the stream and use that.
    CodedInputStream in = CodedInputStream.newInstance(raw);
    try {
      int tag = in.readTag();
      for (;;) {
        switch (WireFormat.getTagFieldNumber(tag)) {
        case 0:
          return members;
        case 1: {
          int cnt = in.readRawVarint32();
          int ptr = in.getTotalBytesRead();
          members.setChunkData(raw, ptr, cnt);
          in.skipRawBytes(cnt);
          tag = in.readTag();
          if (WireFormat.getTagFieldNumber(tag) != 2)
            continue;
        }
        //$FALL-THROUGH$
        case 2: {
          int cnt = in.readRawVarint32();
          int ptr = in.getTotalBytesRead();
          members.setChunkIndex(raw, ptr, cnt);
          in.skipRawBytes(cnt);
          tag = in.readTag();
          if (WireFormat.getTagFieldNumber(tag) != 3)
            continue;
        }
        //$FALL-THROUGH$
        case 3: {
          int cnt = in.readRawVarint32();
          int oldLimit = in.pushLimit(cnt);
          members.setMeta(ChunkMeta.parseFrom(in));
          in.popLimit(oldLimit);
          tag = in.readTag();
          continue;
        }
        default:
          in.skipField(tag);
        }
      }
    } catch (IOException err) {
      throw new RuntimeException("Cannot decode chunk", err);
    }
View Full Code Here


      user.setAddresses(Collections.singletonList(new Address("Old Street", "XYZ42")));

      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);
View Full Code Here

      user.setAddresses(Collections.singletonList(new Address("Old Street", "XYZ42")));

      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);
View Full Code Here

    ByteBuffer buffer = ByteBuffer.allocate(readSize);
    InStream.read(file, size - readSize, buffer.array(), buffer.arrayOffset() + buffer.position(),
        buffer.remaining());
    int psLen = buffer.get(readSize - 1);
    int psOffset = readSize - 1 - psLen;
    CodedInputStream in = CodedInputStream.newInstance(buffer.array(),
      buffer.arrayOffset() + psOffset, psLen);
    OrcProto.PostScript ps = OrcProto.PostScript.parseFrom(in);
    int footerSize = (int) ps.getFooterLength();
    bufferSize = (int) ps.getCompressionBlockSize();
    switch (ps.getCompression()) {
View Full Code Here

   public void parse(TagHandler tagHandler, Descriptors.Descriptor messageDescriptor, byte[] input) throws IOException {
      if (messageDescriptor == null) {
         throw new IllegalArgumentException("messageDescriptor cannot be null");
      }
      ByteArrayInputStream bais = new ByteArrayInputStream(input);
      CodedInputStream in = CodedInputStream.newInstance(bais);

      parse(tagHandler, messageDescriptor, in);
   }
View Full Code Here

      return fromWrappedByteArray(ctx, bytes, 0, bytes.length);
   }

   public static Object fromWrappedByteArray(SerializationContext ctx, byte[] bytes, int offset, int length) throws IOException {
      ByteArrayInputStream bais = new ByteArrayInputStream(bytes, offset, length);
      CodedInputStream in = CodedInputStream.newInstance(bais);

      String descriptorFullName = null;
      int enumValue = -1;
      byte[] messageBytes = null;
      Object value = null;
      int readTags = 0;

      int tag;
      while ((tag = in.readTag()) != 0) {
         readTags++;
         switch (tag) {
            case wrappedDescriptorFullName << 3 | WireFormat.WIRETYPE_LENGTH_DELIMITED:
               descriptorFullName = in.readString();
               break;
            case wrappedEnum << 3 | WireFormat.WIRETYPE_VARINT:
               enumValue = in.readEnum();
               break;
            case wrappedMessageBytes << 3 | WireFormat.WIRETYPE_LENGTH_DELIMITED:
               messageBytes = in.readBytes().toByteArray();
               break;
            case wrappedString << 3 | WireFormat.WIRETYPE_LENGTH_DELIMITED:
               value = in.readString();
               break;
            case wrappedBytes << 3 | WireFormat.WIRETYPE_LENGTH_DELIMITED:
               value = in.readBytes().toByteArray();
               break;
            case wrappedBool << 3 | WireFormat.WIRETYPE_VARINT:
               value = in.readBool();
               break;
            case wrappedDouble << 3 | WireFormat.WIRETYPE_FIXED64:
               value = in.readDouble();
               break;
            case wrappedFloat << 3 | WireFormat.WIRETYPE_FIXED32:
               value = in.readFloat();
               break;
            case wrappedFixed32 << 3 | WireFormat.WIRETYPE_FIXED32:
               value = in.readFixed32();
               break;
            case wrappedSFixed32 << 3 | WireFormat.WIRETYPE_FIXED32:
               value = in.readSFixed32();
               break;
            case wrappedFixed64 << 3 | WireFormat.WIRETYPE_FIXED64:
               value = in.readFixed64();
               break;
            case wrappedSFixed64 << 3 | WireFormat.WIRETYPE_FIXED64:
               value = in.readSFixed64();
               break;
            case wrappedInt64 << 3 | WireFormat.WIRETYPE_VARINT:
               value = in.readInt64();
               break;
            case wrappedUInt64 << 3 | WireFormat.WIRETYPE_VARINT:
               value = in.readUInt64();
               break;
            case wrappedSInt64 << 3 | WireFormat.WIRETYPE_VARINT:
               value = in.readSInt64();
               break;
            case wrappedInt32 << 3 | WireFormat.WIRETYPE_VARINT:
               value = in.readInt32();
               break;
            case wrappedUInt32 << 3 | WireFormat.WIRETYPE_VARINT:
               value = in.readUInt32();
               break;
            case wrappedSInt32 << 3 | WireFormat.WIRETYPE_VARINT:
               value = in.readSInt32();
               break;
            default:
               throw new IllegalStateException("Unexpected tag : " + tag);
         }
      }

      if (value != null) {
         if (readTags == 1) {
            return value;
         }
         throw new IOException("Invalid message encoding.");
      }

      if (descriptorFullName == null || readTags != 2) {
         throw new IOException("Invalid message encoding.");
      }

      if (messageBytes != null) {
         MessageMarshaller marshaller = ctx.getMarshaller(descriptorFullName);
         ByteArrayInputStream bais2 = new ByteArrayInputStream(messageBytes);
         CodedInputStream in2 = CodedInputStream.newInstance(bais2);
         ProtobufReaderImpl reader = new ProtobufReaderImpl(ctx);
         return reader.read(in2, marshaller);
      } else {
         EnumEncoder<? extends Enum> enumEncoder = ctx.getEnumEncoder(descriptorFullName);
         return enumEncoder.decode(enumValue);
View Full Code Here

      //todo validate type is compatible with readObject
      int expectedTag = WireFormat.makeTag(fd.getNumber(), fd.getLiteType().getWireType());
      Object o = messageContext.unknownFieldSet.consumeTag(expectedTag);
      if (o != null) {
         ByteString byteString = (ByteString) o;
         CodedInputStream codedInputStream = byteString.newCodedInput();
         return readObject(fd, clazz, codedInputStream, byteString.size());
      }

      while (true) {
         int tag = messageContext.in.readTag();
View Full Code Here

         Object o = messageContext.unknownFieldSet.consumeTag(expectedTag);
         if (o == null) {
            break;
         }
         ByteString byteString = (ByteString) o;
         CodedInputStream codedInputStream = byteString.newCodedInput();
         collection.add(readObject(fd, clazz, codedInputStream, byteString.size()));
      }

      while (true) {
         int tag = messageContext.in.readTag();
View Full Code Here

   public void parse(TagHandler tagHandler, Descriptor messageDescriptor, InputStream input) throws IOException {
      if (messageDescriptor == null) {
         throw new IllegalArgumentException("messageDescriptor cannot be null");
      }
      CodedInputStream in = CodedInputStream.newInstance(input);

      parseInternal(tagHandler, messageDescriptor, in);
   }
View Full Code Here

   public void parse(TagHandler tagHandler, Descriptor messageDescriptor, byte[] buf, int off, int len) throws IOException {
      if (messageDescriptor == null) {
         throw new IllegalArgumentException("messageDescriptor cannot be null");
      }
      CodedInputStream in = CodedInputStream.newInstance(buf, off, len);

      parseInternal(tagHandler, messageDescriptor, in);
   }
View Full Code Here

TOP

Related Classes of com.google.protobuf.CodedInputStream$SkippedDataSink

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.