Java 类com.google.protobuf.CodedInputStream 实例源码

项目:sstore-soft    文件:ProtoConnectionTest.java   
@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;
    assertFalse(connection.writeAvailable());
    assertEquals(2, channel.lastWrites.size());
}
项目:xrpc    文件:Example.java   
private static FullHttpResponse getDino(XrpcRequest request, List<Dino> dinos) {
  try {
    DinoGetRequest getRequest =
        DinoGetRequest.parseFrom(CodedInputStream.newInstance(request.getData().nioBuffer()));
    Optional<Dino> dinoOptional =
        dinos.stream().filter(xs -> xs.getName().equals(getRequest.getName())).findFirst();

    if (dinoOptional.isPresent()) {
      DinoGetReply getReply = DinoGetReply.newBuilder().setDino(dinoOptional.get()).build();
      ByteBuf resp = request.getByteBuf();
      resp.ensureWritable(CodedOutputStream.computeMessageSizeNoTag(getReply), true);
      getReply.writeTo(new ByteBufOutputStream(resp));

      return Recipes.newResponse(
          HttpResponseStatus.OK,
          request.getByteBuf().writeBytes(resp),
          Recipes.ContentType.Application_Octet_Stream);
    }

  } catch (IOException e) {
    return Recipes.newResponseBadRequest("Malformed GetDino Request: " + e.getMessage());
  }

  return Recipes.newResponseOk("Dino not Found");
}
项目:xrpc    文件:Example.java   
private static HttpResponse setDino(XrpcRequest request, List<Dino> dinos) {
  try {

    Optional<DinoSetRequest> setRequest =
        Optional.of(
            DinoSetRequest.parseFrom(
                CodedInputStream.newInstance(request.getData().nioBuffer())));
    setRequest.ifPresent(req -> dinos.add(req.getDino()));

    return Recipes.newResponse(
        HttpResponseStatus.OK,
        request
            .getByteBuf()
            .writeBytes(DinoSetReply.newBuilder().setResponseCode("OK").build().toByteArray()),
        Recipes.ContentType.Application_Octet_Stream);
  } catch (IOException e) {
    return Recipes.newResponseBadRequest("Malformed SetDino Request: " + e.getMessage());
  }
}
项目:MooProject    文件:Varint32FrameDecoder.java   
protected void decode(ChannelHandlerContext paramChannelHandlerContext, ByteBuf paramByteBuf, List<Object> paramList)
        throws Exception {
    paramByteBuf.markReaderIndex();
    byte[] arrayOfByte = new byte[5];
    for(int i = 0; i < arrayOfByte.length; i++) {
        if(!paramByteBuf.isReadable()) {
            paramByteBuf.resetReaderIndex();
            return;
        }
        arrayOfByte[i] = paramByteBuf.readByte();
        if(arrayOfByte[i] >= 0) {
            int j = CodedInputStream.newInstance(arrayOfByte, 0, i + 1).readRawVarint32();
            if(j < 0) {
                throw new CorruptedFrameException("negative length: " + j);
            }
            if(paramByteBuf.readableBytes() < j) {
                paramByteBuf.resetReaderIndex();
                return;
            }
            paramList.add(paramByteBuf.readBytes(j));
            return;
        }
    }
    throw new CorruptedFrameException("length wider than 32-bit");
}
项目:MooProject    文件:ProtobufVarint32FrameDecoder.java   
protected void decode(ChannelHandlerContext paramChannelHandlerContext, ByteBuf paramByteBuf, List<Object> paramList)
        throws Exception {
    paramByteBuf.markReaderIndex();
    byte[] arrayOfByte = new byte[5];
    for(int i = 0; i < arrayOfByte.length; i++) {
        if(!paramByteBuf.isReadable()) {
            paramByteBuf.resetReaderIndex();
            return;
        }
        arrayOfByte[i] = paramByteBuf.readByte();
        if(arrayOfByte[i] >= 0) {
            int j = CodedInputStream.newInstance(arrayOfByte, 0, i + 1).readRawVarint32();
            if(j < 0) {
                throw new CorruptedFrameException("negative length: " + j);
            }
            if(paramByteBuf.readableBytes() < j) {
                paramByteBuf.resetReaderIndex();
                return;
            }
            paramList.add(paramByteBuf.readBytes(j));
            return;
        }
    }
    throw new CorruptedFrameException("length wider than 32-bit");
}
项目:Cobweb    文件:ProcessDataProto.java   
public Builder mergeFrom(
    com.google.protobuf.CodedInputStream input,
    com.google.protobuf.ExtensionRegistryLite extensionRegistry)
    throws java.io.IOException {
  ProcessDataProto.ProcessData parsedMessage = null;
  try {
    parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
  } catch (com.google.protobuf.InvalidProtocolBufferException e) {
    parsedMessage = (ProcessDataProto.ProcessData) e.getUnfinishedMessage();
    throw e.unwrapIOException();
  } finally {
    if (parsedMessage != null) {
      mergeFrom(parsedMessage);
    }
  }
  return this;
}
项目:s-store    文件:ProtoConnectionTest.java   
@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;
    assertFalse(connection.writeAvailable());
    assertEquals(2, channel.lastWrites.size());
}
项目:calcite-avatica    文件:ProtobufTranslationImpl.java   
@Override public Request parseRequest(byte[] bytes) throws IOException {
  ByteString byteString = UnsafeByteOperations.unsafeWrap(bytes);
  CodedInputStream inputStream = byteString.newCodedInput();
  // Enable aliasing to avoid an extra copy to get at the serialized Request inside of the
  // WireMessage.
  inputStream.enableAliasing(true);
  WireMessage wireMsg = WireMessage.parseFrom(inputStream);

  String serializedMessageClassName = wireMsg.getName();

  try {
    RequestTranslator translator = getParserForRequest(serializedMessageClassName);

    // The ByteString should be logical offsets into the original byte array
    return translator.transform(wireMsg.getWrappedMessage());
  } catch (RuntimeException e) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Failed to parse request message '{}'", TextFormat.shortDebugString(wireMsg));
    }
    throw e;
  }
}
项目:calcite-avatica    文件:ProtobufTranslationImpl.java   
@Override public Response parseResponse(byte[] bytes) throws IOException {
  ByteString byteString = UnsafeByteOperations.unsafeWrap(bytes);
  CodedInputStream inputStream = byteString.newCodedInput();
  // Enable aliasing to avoid an extra copy to get at the serialized Response inside of the
  // WireMessage.
  inputStream.enableAliasing(true);
  WireMessage wireMsg = WireMessage.parseFrom(inputStream);

  String serializedMessageClassName = wireMsg.getName();
  try {
    ResponseTranslator translator = getParserForResponse(serializedMessageClassName);

    return translator.transform(wireMsg.getWrappedMessage());
  } catch (RuntimeException e) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Failed to parse response message '{}'", TextFormat.shortDebugString(wireMsg));
    }
    throw e;
  }
}
项目:sctalk    文件:IMPacketDispatcher.java   
/**
     * @param commandId
     * @param buffer
     *
     * 有没有更加优雅的方式
     */
    public static void loginPacketDispatcher(int commandId,CodedInputStream buffer){
        try {
        switch (commandId) {
//            case IMBaseDefine.LoginCmdID.CID_LOGIN_RES_USERLOGIN_VALUE :
//                IMLogin.IMLoginRes  imLoginRes = IMLogin.IMLoginRes.parseFrom(buffer);
//                IMLoginManager.instance().onRepMsgServerLogin(imLoginRes);
//                return;

            case IMBaseDefine.LoginCmdID.CID_LOGIN_RES_LOGINOUT_VALUE:
                IMLogin.IMLogoutRsp imLogoutRsp = IMLogin.IMLogoutRsp.parseFrom(buffer);
                IMLoginManager.instance().onRepLoginOut(imLogoutRsp);
                return;

            case IMBaseDefine.LoginCmdID.CID_LOGIN_KICK_USER_VALUE:
                IMLogin.IMKickUser imKickUser = IMLogin.IMKickUser.parseFrom(buffer);
                IMLoginManager.instance().onKickout(imKickUser);
            }
        } catch (IOException e) {
            logger.e("loginPacketDispatcher# error,cid:%d",commandId);
        }
    }
项目:aliyun-oss-hadoop-fs    文件:BlockListAsLongs.java   
public static BlockListAsLongs readFrom(InputStream is) throws IOException {
  CodedInputStream cis = CodedInputStream.newInstance(is);
  int numBlocks = -1;
  ByteString blocksBuf = null;
  while (!cis.isAtEnd()) {
    int tag = cis.readTag();
    int field = WireFormat.getTagFieldNumber(tag);
    switch(field) {
      case 0:
        break;
      case 1:
        numBlocks = (int)cis.readInt32();
        break;
      case 2:
        blocksBuf = cis.readBytes();
        break;
      default:
        cis.skipField(tag);
        break;
    }
  }
  if (numBlocks != -1 && blocksBuf != null) {
    return decodeBuffer(numBlocks, blocksBuf);
  }
  return null;
}
项目:aliyun-oss-hadoop-fs    文件:FSImageLoader.java   
private static byte[][] loadINodeSection(InputStream in)
        throws IOException {
  FsImageProto.INodeSection s = FsImageProto.INodeSection
      .parseDelimitedFrom(in);
  LOG.info("Loading " + s.getNumInodes() + " inodes.");
  final byte[][] inodes = new byte[(int) s.getNumInodes()][];

  for (int i = 0; i < s.getNumInodes(); ++i) {
    int size = CodedInputStream.readRawVarint32(in.read(), in);
    byte[] bytes = new byte[size];
    IOUtils.readFully(in, bytes, 0, size);
    inodes[i] = bytes;
  }
  LOG.debug("Sorting inodes");
  Arrays.sort(inodes, INODE_BYTES_COMPARATOR);
  LOG.debug("Finished sorting inodes");
  return inodes;
}
项目:big-c    文件:FSImageLoader.java   
private static byte[][] loadINodeSection(InputStream in)
        throws IOException {
  FsImageProto.INodeSection s = FsImageProto.INodeSection
      .parseDelimitedFrom(in);
  LOG.info("Loading " + s.getNumInodes() + " inodes.");
  final byte[][] inodes = new byte[(int) s.getNumInodes()][];

  for (int i = 0; i < s.getNumInodes(); ++i) {
    int size = CodedInputStream.readRawVarint32(in.read(), in);
    byte[] bytes = new byte[size];
    IOUtils.readFully(in, bytes, 0, size);
    inodes[i] = bytes;
  }
  LOG.debug("Sorting inodes");
  Arrays.sort(inodes, INODE_BYTES_COMPARATOR);
  LOG.debug("Finished sorting inodes");
  return inodes;
}
项目:hadoop-2.6.0-cdh5.4.3    文件:FSImageLoader.java   
private static byte[][] loadINodeSection(InputStream in)
        throws IOException {
  FsImageProto.INodeSection s = FsImageProto.INodeSection
      .parseDelimitedFrom(in);
  LOG.info("Loading " + s.getNumInodes() + " inodes.");
  final byte[][] inodes = new byte[(int) s.getNumInodes()][];

  for (int i = 0; i < s.getNumInodes(); ++i) {
    int size = CodedInputStream.readRawVarint32(in.read(), in);
    byte[] bytes = new byte[size];
    IOUtils.readFully(in, bytes, 0, size);
    inodes[i] = bytes;
  }
  LOG.debug("Sorting inodes");
  Arrays.sort(inodes, INODE_BYTES_COMPARATOR);
  LOG.debug("Finished sorting inodes");
  return inodes;
}
项目:sql-layer    文件:ProtobufReader.java   
private void loadFromBuffer(ByteBuffer buffer) {
    final String MESSAGE_NAME = AISProtobuf.AkibanInformationSchema.getDescriptor().getFullName();
    checkBuffer(buffer);
    final int serializedSize = buffer.getInt();
    final int initialPos = buffer.position();
    final int bufferSize = buffer.limit() - initialPos;
    if(bufferSize < serializedSize) {
        throw new ProtobufReadException(MESSAGE_NAME, "Buffer corrupt, serialized size greater than remaining");
    }
    CodedInputStream codedInput = CodedInputStream.newInstance(buffer.array(), buffer.position(), Math.min(serializedSize, bufferSize));
    try {
        pbAISBuilder.mergeFrom(codedInput, storageFormatRegistry.getExtensionRegistry());
        // Successfully consumed, update byte buffer
        buffer.position(initialPos + serializedSize);
    } catch(IOException e) {
        // CodedInputStream really only throws InvalidProtocolBufferException, but declares IOE
        throw new ProtobufReadException(MESSAGE_NAME, e.getMessage());
    }
}
项目:TextSecureSMP    文件:PushSMPMessageProtos.java   
public PushSMPMessageProtos.PushSMPMessageContent.Builder mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws IOException {
    PushSMPMessageProtos.PushSMPMessageContent parsedMessage = null;

    try {
        parsedMessage = (PushSMPMessageProtos.PushSMPMessageContent)PushSMPMessageProtos.PushSMPMessageContent.PARSER.parsePartialFrom(input, extensionRegistry);
    } catch (InvalidProtocolBufferException var8) {
        parsedMessage = (PushSMPMessageProtos.PushSMPMessageContent)var8.getUnfinishedMessage();
        throw var8;
    } finally {
        if(parsedMessage != null) {
            this.mergeFrom(parsedMessage);
        }

    }

    return this;
}
项目:TextSecureSMP    文件:PushSMPMessageProtos.java   
public PushSMPMessageProtos.PushSMPMessageContent.SyncMessageContext.Builder mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws IOException {
    PushSMPMessageProtos.PushSMPMessageContent.SyncMessageContext parsedMessage = null;

    try {
        parsedMessage = (PushSMPMessageProtos.PushSMPMessageContent.SyncMessageContext)PushSMPMessageProtos.PushSMPMessageContent.SyncMessageContext.PARSER.parsePartialFrom(input, extensionRegistry);
    } catch (InvalidProtocolBufferException var8) {
        parsedMessage = (PushSMPMessageProtos.PushSMPMessageContent.SyncMessageContext)var8.getUnfinishedMessage();
        throw var8;
    } finally {
        if(parsedMessage != null) {
            this.mergeFrom(parsedMessage);
        }

    }

    return this;
}
项目:TextSecureSMP    文件:PushSMPMessageProtos.java   
public PushSMPMessageProtos.PushSMPMessageContent.GroupContext.Builder mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws IOException {
    PushSMPMessageProtos.PushSMPMessageContent.GroupContext parsedMessage = null;

    try {
        parsedMessage = (PushSMPMessageProtos.PushSMPMessageContent.GroupContext)PushSMPMessageProtos.PushSMPMessageContent.GroupContext.PARSER.parsePartialFrom(input, extensionRegistry);
    } catch (InvalidProtocolBufferException var8) {
        parsedMessage = (PushSMPMessageProtos.PushSMPMessageContent.GroupContext)var8.getUnfinishedMessage();
        throw var8;
    } finally {
        if(parsedMessage != null) {
            this.mergeFrom(parsedMessage);
        }

    }

    return this;
}
项目:TextSecureSMP    文件:PushSMPMessageProtos.java   
public PushSMPMessageProtos.PushSMPMessageContent.AttachmentPointer.Builder mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws IOException {
    PushSMPMessageProtos.PushSMPMessageContent.AttachmentPointer parsedMessage = null;

    try {
        parsedMessage = (PushSMPMessageProtos.PushSMPMessageContent.AttachmentPointer)PushSMPMessageProtos.PushSMPMessageContent.AttachmentPointer.PARSER.parsePartialFrom(input, extensionRegistry);
    } catch (InvalidProtocolBufferException var8) {
        parsedMessage = (PushSMPMessageProtos.PushSMPMessageContent.AttachmentPointer)var8.getUnfinishedMessage();
        throw var8;
    } finally {
        if(parsedMessage != null) {
            this.mergeFrom(parsedMessage);
        }

    }

    return this;
}
项目:TextSecureSMP    文件:PushSMPMessageProtos.java   
public PushSMPMessageProtos.IncomingPushMessageSignal.Builder mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws IOException {
    PushSMPMessageProtos.IncomingPushMessageSignal parsedMessage = null;

    try {
        parsedMessage = (PushSMPMessageProtos.IncomingPushMessageSignal)PushSMPMessageProtos.IncomingPushMessageSignal.PARSER.parsePartialFrom(input, extensionRegistry);
    } catch (InvalidProtocolBufferException var8) {
        parsedMessage = (PushSMPMessageProtos.IncomingPushMessageSignal)var8.getUnfinishedMessage();
        throw var8;
    } finally {
        if(parsedMessage != null) {
            this.mergeFrom(parsedMessage);
        }

    }

    return this;
}
项目:FlexMap    文件:FSImageLoader.java   
private static byte[][] loadINodeSection(InputStream in)
        throws IOException {
  FsImageProto.INodeSection s = FsImageProto.INodeSection
      .parseDelimitedFrom(in);
  LOG.info("Loading " + s.getNumInodes() + " inodes.");
  final byte[][] inodes = new byte[(int) s.getNumInodes()][];

  for (int i = 0; i < s.getNumInodes(); ++i) {
    int size = CodedInputStream.readRawVarint32(in.read(), in);
    byte[] bytes = new byte[size];
    IOUtils.readFully(in, bytes, 0, size);
    inodes[i] = bytes;
  }
  LOG.debug("Sorting inodes");
  Arrays.sort(inodes, INODE_BYTES_COMPARATOR);
  LOG.debug("Finished sorting inodes");
  return inodes;
}
项目:hops    文件:RpcWritable.java   
@SuppressWarnings("unchecked")
@Override
<T> T readFrom(ByteBuffer bb) throws IOException {
  // using the parser with a byte[]-backed coded input stream is the
  // most efficient way to deserialize a protobuf.  it has a direct
  // path to the PB ctor that doesn't create multi-layered streams
  // that internally buffer.
  CodedInputStream cis = CodedInputStream.newInstance(
      bb.array(), bb.position() + bb.arrayOffset(), bb.remaining());
  try {
    cis.pushLimit(cis.readRawVarint32());
    message = message.getParserForType().parseFrom(cis);
    cis.checkLastTagWas(0);
  } finally {
    // advance over the bytes read.
    bb.position(bb.position() + cis.getTotalBytesRead());
  }
  return (T)message;
}
项目:compiler    文件:TestSequenceFile.java   
public static void main(String[] args) throws IOException {
        Configuration conf = new Configuration();
        FileSystem fileSystem = FileSystem.get(conf);
//      
//      SequenceFile.Writer w = SequenceFile.createWriter(fileSystem, conf, new Path("seq"), Text.class, BytesWritable.class);
//      for (int i = 0; i < 1; i++) {
//          ASTRoot.Builder ast = ASTRoot.newBuilder();
//          ast.addImports("a.b.C");
//          w.append(new Text(i + ""), new BytesWritable(ast.build().toByteArray()));
//          System.out.println("Parse before writing to sequence file: " + ASTRoot.parseFrom(ast.build().toByteArray()).getImportsList());
//      }
//      w.close();

        Text key = new Text();
        BytesWritable val = new BytesWritable();
        SequenceFile.Reader r = new SequenceFile.Reader(fileSystem, new Path("/Users/nmtiwari/nmt/githubCacheJSon/tmprepcache/ast-nmtiwari-0-1453911429.seq"), conf);
        while (r.next(key, val)) {
            System.out.println("next project");
            byte[] bytes = val.getBytes();
            System.out.print("Parse after writing to sequence file: ");
            //System.out.println(ASTRoot.parseFrom(bytes).getImportsList());
            System.out.println(ASTRoot.parseFrom(CodedInputStream.newInstance(bytes, 0, val.getLength())));
        }
        r.close();
    }
项目:grumble    文件:Mumble.java   
public Builder mergeFrom(
        CodedInputStream input,
        ExtensionRegistryLite extensionRegistry)
        throws IOException {
    MumbleProto.Mumble.PermissionQuery parsedMessage = null;
    try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
    } catch (InvalidProtocolBufferException e) {
        parsedMessage = (MumbleProto.Mumble.PermissionQuery) e.getUnfinishedMessage();
        throw e;
    } finally {
        if (parsedMessage != null) {
            mergeFrom(parsedMessage);
        }
    }
    return this;
}
项目:grumble    文件:Mumble.java   
public Builder mergeFrom(
        CodedInputStream input,
        ExtensionRegistryLite extensionRegistry)
        throws IOException {
    MumbleProto.Mumble.UserStats parsedMessage = null;
    try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
    } catch (InvalidProtocolBufferException e) {
        parsedMessage = (MumbleProto.Mumble.UserStats) e.getUnfinishedMessage();
        throw e;
    } finally {
        if (parsedMessage != null) {
            mergeFrom(parsedMessage);
        }
    }
    return this;
}
项目:grumble    文件:Mumble.java   
public Builder mergeFrom(
        CodedInputStream input,
        ExtensionRegistryLite extensionRegistry)
        throws IOException {
    MumbleProto.Mumble.SuggestConfig parsedMessage = null;
    try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
    } catch (InvalidProtocolBufferException e) {
        parsedMessage = (MumbleProto.Mumble.SuggestConfig) e.getUnfinishedMessage();
        throw e;
    } finally {
        if (parsedMessage != null) {
            mergeFrom(parsedMessage);
        }
    }
    return this;
}
项目:bazel    文件:ObjectCodecsTest.java   
@Test
public void testSerializeDeserializeInBulk() throws Exception {
  Integer value1 = 12345;
  Integer value2 = 67890;
  Integer value3 = 42;

  ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
  CodedOutputStream codedOut = CodedOutputStream.newInstance(bytesOut);
  underTest.serialize(KNOWN_CLASSIFIER, value1, codedOut);
  underTest.serialize(KNOWN_CLASSIFIER, value2, codedOut);
  underTest.serialize(KNOWN_CLASSIFIER, value3, codedOut);
  codedOut.flush();

  CodedInputStream codedIn = CodedInputStream.newInstance(bytesOut.toByteArray());
  assertThat(underTest.deserialize(KNOWN_CLASSIFIER_BYTES, codedIn)).isEqualTo(value1);
  assertThat(underTest.deserialize(KNOWN_CLASSIFIER_BYTES, codedIn)).isEqualTo(value2);
  assertThat(underTest.deserialize(KNOWN_CLASSIFIER_BYTES, codedIn)).isEqualTo(value3);
}
项目:bazel    文件:NestedSetCodec.java   
private Object deserializeOneNestedSet(
    CodedInputStream codedIn, Map<ByteString, Object> digestToChild)
    throws SerializationException, IOException {
  ByteString digest = codedIn.readBytes();
  CodedInputStream childCodedIn = codedIn.readBytes().newCodedInput();
  childCodedIn.enableAliasing(true); // Allow efficient views of byte slices when reading digests
  int childCount = childCodedIn.readInt32();
  final Object result;
  if (childCount > 1) {
    result = deserializeMultipleItemChildArray(digestToChild, childCodedIn, childCount);
  } else if (childCount == 1) {
    result = objectCodec.deserialize(childCodedIn);
  } else {
    result = NestedSet.EMPTY_CHILDREN;
  }
  digestToChild.put(digest, result);
  return result;
}
项目:bazel    文件:SkylarkSemanticsCodec.java   
@Override
public SkylarkSemantics deserialize(CodedInputStream codedIn)
    throws SerializationException, IOException {
  SkylarkSemantics.Builder builder = SkylarkSemantics.builder();

  // <== Add new options here in alphabetic order ==>
  builder.incompatibleBzlDisallowLoadAfterStatement(codedIn.readBool());
  builder.incompatibleCheckedArithmetic(codedIn.readBool());
  builder.incompatibleComprehensionVariablesDoNotLeak(codedIn.readBool());
  builder.incompatibleDepsetIsNotIterable(codedIn.readBool());
  builder.incompatibleDepsetUnion(codedIn.readBool());
  builder.incompatibleDictLiteralHasNoDuplicates(codedIn.readBool());
  builder.incompatibleDisableGlobTracking(codedIn.readBool());
  builder.incompatibleDisallowDictPlus(codedIn.readBool());
  builder.incompatibleDisallowKeywordOnlyArgs(codedIn.readBool());
  builder.incompatibleDisallowToplevelIfStatement(codedIn.readBool());
  builder.incompatibleDisallowUncalledSetConstructor(codedIn.readBool());
  builder.incompatibleLoadArgumentIsLabel(codedIn.readBool());
  builder.incompatibleNewActionsApi(codedIn.readBool());
  builder.incompatibleShowAllPrintMessages(codedIn.readBool());
  builder.incompatibleStringIsNotIterable(codedIn.readBool());
  builder.internalSkylarkFlagTestCanary(codedIn.readBool());

  return builder.build();
}
项目:grumble    文件:Mumble.java   
public Builder mergeFrom(
        CodedInputStream input,
        ExtensionRegistryLite extensionRegistry)
        throws IOException {
    MumbleProto.Mumble.Version parsedMessage = null;
    try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
    } catch (InvalidProtocolBufferException e) {
        parsedMessage = (MumbleProto.Mumble.Version) e.getUnfinishedMessage();
        throw e;
    } finally {
        if (parsedMessage != null) {
            mergeFrom(parsedMessage);
        }
    }
    return this;
}
项目:grumble    文件:Mumble.java   
public Builder mergeFrom(
        CodedInputStream input,
        ExtensionRegistryLite extensionRegistry)
        throws IOException {
    MumbleProto.Mumble.UDPTunnel parsedMessage = null;
    try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
    } catch (InvalidProtocolBufferException e) {
        parsedMessage = (MumbleProto.Mumble.UDPTunnel) e.getUnfinishedMessage();
        throw e;
    } finally {
        if (parsedMessage != null) {
            mergeFrom(parsedMessage);
        }
    }
    return this;
}
项目:grumble    文件:Mumble.java   
public Builder mergeFrom(
        CodedInputStream input,
        ExtensionRegistryLite extensionRegistry)
        throws IOException {
    MumbleProto.Mumble.Authenticate parsedMessage = null;
    try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
    } catch (InvalidProtocolBufferException e) {
        parsedMessage = (MumbleProto.Mumble.Authenticate) e.getUnfinishedMessage();
        throw e;
    } finally {
        if (parsedMessage != null) {
            mergeFrom(parsedMessage);
        }
    }
    return this;
}
项目:grumble    文件:Mumble.java   
public Builder mergeFrom(
        CodedInputStream input,
        ExtensionRegistryLite extensionRegistry)
        throws IOException {
    MumbleProto.Mumble.Reject parsedMessage = null;
    try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
    } catch (InvalidProtocolBufferException e) {
        parsedMessage = (MumbleProto.Mumble.Reject) e.getUnfinishedMessage();
        throw e;
    } finally {
        if (parsedMessage != null) {
            mergeFrom(parsedMessage);
        }
    }
    return this;
}
项目:grumble    文件:Mumble.java   
public Builder mergeFrom(
        CodedInputStream input,
        ExtensionRegistryLite extensionRegistry)
        throws IOException {
    MumbleProto.Mumble.ServerSync parsedMessage = null;
    try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
    } catch (InvalidProtocolBufferException e) {
        parsedMessage = (MumbleProto.Mumble.ServerSync) e.getUnfinishedMessage();
        throw e;
    } finally {
        if (parsedMessage != null) {
            mergeFrom(parsedMessage);
        }
    }
    return this;
}
项目:grumble    文件:Mumble.java   
public Builder mergeFrom(
        CodedInputStream input,
        ExtensionRegistryLite extensionRegistry)
        throws IOException {
    MumbleProto.Mumble.ChannelRemove parsedMessage = null;
    try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
    } catch (InvalidProtocolBufferException e) {
        parsedMessage = (MumbleProto.Mumble.ChannelRemove) e.getUnfinishedMessage();
        throw e;
    } finally {
        if (parsedMessage != null) {
            mergeFrom(parsedMessage);
        }
    }
    return this;
}
项目:bazel    文件:ObjectCodecs.java   
/**
 * Similar to {@link #deserialize(ByteString, ByteString)}, except allows the caller to specify a
 * {@link CodedInputStream} to deserialize data from. This is useful for decoding objects
 * serialized in bulk by {@link #serialize(String, Object, CodedOutputStream)}.
 */
public Object deserialize(ByteString classifier, CodedInputStream codedIn)
    throws SerializationException {
  ObjectCodec<?> codec = getCodec(classifier);
  // If safe, this will allow CodedInputStream to return a direct view of the underlying bytes
  // in some situations, bypassing a copy.
  codedIn.enableAliasing(true);
  try {
    Object result = codec.deserialize(codedIn);
    if (result == null) {
      throw new NullPointerException(
          "ObjectCodec " + codec + " for " + classifier.toStringUtf8() + " returned null");
    }
    return result;
  } catch (IOException e) {
    throw new SerializationException(
        "Failed to deserialize data using " + codec + " for " + classifier.toStringUtf8(), e);
  }
}
项目:grumble    文件:Mumble.java   
public Builder mergeFrom(
        CodedInputStream input,
        ExtensionRegistryLite extensionRegistry)
        throws IOException {
    MumbleProto.Mumble.UserState parsedMessage = null;
    try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
    } catch (InvalidProtocolBufferException e) {
        parsedMessage = (MumbleProto.Mumble.UserState) e.getUnfinishedMessage();
        throw e;
    } finally {
        if (parsedMessage != null) {
            mergeFrom(parsedMessage);
        }
    }
    return this;
}
项目:grumble    文件:Mumble.java   
public Builder mergeFrom(
        CodedInputStream input,
        ExtensionRegistryLite extensionRegistry)
        throws IOException {
    MumbleProto.Mumble.BanList.BanEntry parsedMessage = null;
    try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
    } catch (InvalidProtocolBufferException e) {
        parsedMessage = (MumbleProto.Mumble.BanList.BanEntry) e.getUnfinishedMessage();
        throw e;
    } finally {
        if (parsedMessage != null) {
            mergeFrom(parsedMessage);
        }
    }
    return this;
}
项目:grumble    文件:Mumble.java   
public Builder mergeFrom(
        CodedInputStream input,
        ExtensionRegistryLite extensionRegistry)
        throws IOException {
    MumbleProto.Mumble.VoiceTarget parsedMessage = null;
    try {
        parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
    } catch (InvalidProtocolBufferException e) {
        parsedMessage = (MumbleProto.Mumble.VoiceTarget) e.getUnfinishedMessage();
        throw e;
    } finally {
        if (parsedMessage != null) {
            mergeFrom(parsedMessage);
        }
    }
    return this;
}
项目:bazel    文件:ObjectCodecsTest.java   
@Test
public void testSerializeDeserializeUsesCustomLogicWhenAvailable() throws Exception {
  Integer original = Integer.valueOf(12345);

  doAnswer(
          new Answer<Void>() {
            @Override
            public Void answer(InvocationOnMock invocation) throws IOException {
              CodedOutputStream codedOutArg = (CodedOutputStream) invocation.getArguments()[1];
              codedOutArg.writeInt32NoTag(42);
              return null;
            }
          })
      .when(spyObjectCodec)
      .serialize(eq(original), any(CodedOutputStream.class));
  ArgumentCaptor<CodedInputStream> captor = ArgumentCaptor.forClass(CodedInputStream.class);
  doReturn(original).when(spyObjectCodec).deserialize(captor.capture());

  ByteString serialized = underTest.serialize(KNOWN_CLASSIFIER, original);
  Object deserialized = underTest.deserialize(KNOWN_CLASSIFIER_BYTES, serialized);
  assertThat(deserialized).isEqualTo(original);

  assertThat(captor.getValue().readInt32()).isEqualTo(42);
}