Examples of CodedInputStream


Examples of com.google.protobuf.CodedInputStream

      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

Examples of com.google.protobuf.CodedInputStream

    //read the PostScript
    //get length of PostScript
    int psLen = buffer.get(readSize - 1) & 0xff;
    ensureOrcFooter(file, path, psLen, buffer);
    int psOffset = readSize - 1 - psLen;
    CodedInputStream in = CodedInputStream.newInstance(buffer.array(),
      buffer.arrayOffset() + psOffset, psLen);
    OrcProto.PostScript ps = OrcProto.PostScript.parseFrom(in);

    checkOrcVersion(LOG, path, ps.getVersionList());
View Full Code Here

Examples of com.google.protobuf.CodedInputStream

    protected void processRequest(byte[] buf) throws IOException, InterruptedException {
      long totalRequestSize = buf.length;
      int offset = 0;
      // Here we read in the header.  We avoid having pb
      // do its default 4k allocation for CodedInputStream.  We force it to use backing array.
      CodedInputStream cis = CodedInputStream.newInstance(buf, offset, buf.length);
      int headerSize = cis.readRawVarint32();
      offset = cis.getTotalBytesRead();
      RequestHeader header = RequestHeader.newBuilder().mergeFrom(buf, offset, headerSize).build();
      offset += headerSize;
      int id = header.getCallId();
      if (LOG.isTraceEnabled()) {
        LOG.trace("RequestHeader " + TextFormat.shortDebugString(header) +
          " totalRequestSize: " + totalRequestSize + " bytes");
      }
      // Enforcing the call queue size, this triggers a retry in the client
      // This is a bit late to be doing this check - we have already read in the total request.
      if ((totalRequestSize + callQueueSize.get()) > maxQueueSize) {
        final Call callTooBig =
          new Call(id, this.service, null, null, null, null, this,
            responder, totalRequestSize, null);
        ByteArrayOutputStream responseBuffer = new ByteArrayOutputStream();
        setupResponse(responseBuffer, callTooBig, new CallQueueTooBigException(),
          "Call queue is full, is ipc.server.max.callqueue.size too small?");
        responder.doRespond(callTooBig);
        return;
      }
      MethodDescriptor md = null;
      Message param = null;
      CellScanner cellScanner = null;
      try {
        if (header.hasRequestParam() && header.getRequestParam()) {
          md = this.service.getDescriptorForType().findMethodByName(header.getMethodName());
          if (md == null) throw new UnsupportedOperationException(header.getMethodName());
          Builder builder = this.service.getRequestPrototype(md).newBuilderForType();
          // To read the varint, I need an inputstream; might as well be a CIS.
          cis = CodedInputStream.newInstance(buf, offset, buf.length);
          int paramSize = cis.readRawVarint32();
          offset += cis.getTotalBytesRead();
          if (builder != null) {
            param = builder.mergeFrom(buf, offset, paramSize).build();
          }
          offset += paramSize;
        }
View Full Code Here

Examples of com.google.protobuf.CodedInputStream

    protected void processRequest(byte[] buf) throws IOException, InterruptedException {
      long totalRequestSize = buf.length;
      int offset = 0;
      // Here we read in the header.  We avoid having pb
      // do its default 4k allocation for CodedInputStream.  We force it to use backing array.
      CodedInputStream cis = CodedInputStream.newInstance(buf, offset, buf.length);
      int headerSize = cis.readRawVarint32();
      offset = cis.getTotalBytesRead();
      RequestHeader header = RequestHeader.newBuilder().mergeFrom(buf, offset, headerSize).build();
      offset += headerSize;
      int id = header.getCallId();
      if (LOG.isTraceEnabled()) {
        LOG.trace("RequestHeader " + TextFormat.shortDebugString(header) +
          " totalRequestSize: " + totalRequestSize + " bytes");
      }
      // Enforcing the call queue size, this triggers a retry in the client
      // This is a bit late to be doing this check - we have already read in the total request.
      if ((totalRequestSize + callQueueSize.get()) > maxQueueSize) {
        final Call callTooBig =
          new Call(id, this.service, null, null, null, null, this,
            responder, totalRequestSize, null);
        ByteArrayOutputStream responseBuffer = new ByteArrayOutputStream();
        setupResponse(responseBuffer, callTooBig, new CallQueueTooBigException(),
          "Call queue is full, is ipc.server.max.callqueue.size too small?");
        responder.doRespond(callTooBig);
        return;
      }
      MethodDescriptor md = null;
      Message param = null;
      CellScanner cellScanner = null;
      try {
        if (header.hasRequestParam() && header.getRequestParam()) {
          md = this.service.getDescriptorForType().findMethodByName(header.getMethodName());
          if (md == null) throw new UnsupportedOperationException(header.getMethodName());
          Builder builder = this.service.getRequestPrototype(md).newBuilderForType();
          // To read the varint, I need an inputstream; might as well be a CIS.
          cis = CodedInputStream.newInstance(buf, offset, buf.length);
          int paramSize = cis.readRawVarint32();
          offset += cis.getTotalBytesRead();
          if (builder != null) {
            param = builder.mergeFrom(buf, offset, paramSize).build();
          }
          offset += paramSize;
        }
View Full Code Here

Examples of com.google.protobuf.CodedInputStream

   public void parse(TagHandler tagHandler, Descriptors.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

Examples of com.google.protobuf.CodedInputStream

   public void parse(TagHandler tagHandler, Descriptors.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

Examples of com.google.protobuf.CodedInputStream

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

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

Examples of com.google.protobuf.CodedInputStream

    @Test
    public void testTryWrite() throws IOException {
        Counter.Value v = Counter.Value.newBuilder().setValue(42).build();
        assertFalse(connection.tryWrite(v));

        CodedInputStream in = CodedInputStream.newInstance(channel.lastWrites.get(0));
        int length = in.readRawLittleEndian32();
        assertEquals(length, channel.lastWrites.get(0).length - 4);
        Counter.Value w = Counter.Value.parseFrom(in);
        assertEquals(v, w);
        assertTrue(in.isAtEnd());
        channel.clear();

        channel.numBytesToAccept = 3;
        assertTrue(connection.tryWrite(v));
        channel.numBytesToAccept = -1;
View Full Code Here

Examples of com.google.protobuf.CodedInputStream

   public void parse(TagHandler tagHandler, Descriptors.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

Examples of com.google.protobuf.CodedInputStream

   public void parse(TagHandler tagHandler, Descriptors.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
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.