當前位置: 首頁>>代碼示例>>Java>>正文


Java CodedInputStream.newInstance方法代碼示例

本文整理匯總了Java中com.google.protobuf.CodedInputStream.newInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java CodedInputStream.newInstance方法的具體用法?Java CodedInputStream.newInstance怎麽用?Java CodedInputStream.newInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.protobuf.CodedInputStream的用法示例。


在下文中一共展示了CodedInputStream.newInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testTryWrite

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
@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());
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:20,代碼來源:ProtoConnectionTest.java

示例2: readFrom

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
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;
}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:27,代碼來源:BlockListAsLongs.java

示例3: loadFromBuffer

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
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());
    }
}
 
開發者ID:jaytaylor,項目名稱:sql-layer,代碼行數:20,代碼來源:ProtobufReader.java

示例4: readFrom

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
@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;
}
 
開發者ID:hopshadoop,項目名稱:hops,代碼行數:20,代碼來源:RpcWritable.java

示例5: testSerializeDeserializeInBulk

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
@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);
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:19,代碼來源:ObjectCodecsTest.java

示例6: ProtoConnection

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
public ProtoConnection(NonBlockingConnection connection) {
    this.connection = connection;
    input = connection.getInputStream();
    output = connection.getOutputStream();
    codedInput = CodedInputStream.newInstance(input);
    codedOutput = CodedOutputStream.newInstance(output);
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:8,代碼來源:ProtoConnection.java

示例7: readPreprocessedBlock

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
private Iterable<RtbImpression> readPreprocessedBlock(BlockContext context) throws IOException {
    List<RtbImpression> impressions = new ArrayList<>();
    try (InputStream is = context.createInputStream(PREPROCESS)) {
        CodedInputStream cis = CodedInputStream.newInstance(is);
        while (!cis.isAtEnd()) {
            int len = cis.readRawVarint32();
            int oldLimit = cis.pushLimit(len);
            impressions.add(RtbImpression.parseFrom(cis));
            cis.popLimit(oldLimit);
        }
    }
    return impressions;
}
 
開發者ID:papyrusglobal,項目名稱:state-channels,代碼行數:14,代碼來源:RtbValidator.java

示例8: isWallet

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
/**
 * Cheap test to see if input stream is a wallet. This checks for a magic value at the beginning of the stream.
 *
 * @param is
 *            input stream to test
 * @return true if input stream is a wallet
 */
public static boolean isWallet(InputStream is) {
    try {
        final CodedInputStream cis = CodedInputStream.newInstance(is);
        final int tag = cis.readTag();
        final int field = WireFormat.getTagFieldNumber(tag);
        if (field != 1) // network_identifier
            return false;
        final String network = cis.readString();
        return NetworkParameters.fromID(network) != null;
    } catch (IOException x) {
        return false;
    }
}
 
開發者ID:creativechain,項目名稱:creacoinj,代碼行數:21,代碼來源:WalletProtobufSerializer.java

示例9: getExtraActionInfo

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
public static ExtraActionInfo getExtraActionInfo(String extraActionFile) {
  ExtensionRegistry registry = ExtensionRegistry.newInstance();
  ExtraActionsBase.registerAllExtensions(registry);

  try (InputStream stream = Files.newInputStream(Paths.get(extraActionFile))) {
    CodedInputStream coded = CodedInputStream.newInstance(stream);
    return ExtraActionInfo.parseFrom(coded, registry);
  } catch (IOException e) {
    throw new RuntimeException("ERROR: failed to deserialize extra action file "
      + extraActionFile + ": " + e.getMessage(), e);
  }
}
 
開發者ID:DSC-SPIDAL,項目名稱:twister2,代碼行數:13,代碼來源:ExtraActionUtils.java

示例10: packetDispatch

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
public void packetDispatch(ByteBuf channelBuffer){
    DataBuffer buffer = new DataBuffer(channelBuffer);
    com.mogujie.tt.protobuf.base.Header header = new com.mogujie.tt.protobuf.base.Header();
    header.decode(buffer);
    /**buffer 的指針位於body的地方*/
    int commandId = header.getCommandId();
    int serviceId = header.getServiceId();
    int seqNo = header.getSeqnum();
    logger.d("dispatch packet, serviceId:%d, commandId:%d", serviceId,
            commandId);
    CodedInputStream codedInputStream = CodedInputStream.newInstance(new ByteBufInputStream(buffer.getOrignalBuffer()));

   Packetlistener listener = listenerQueue.pop(seqNo);
   if(listener!=null){
        listener.onSuccess(codedInputStream);
        return;
   }

    // todo eric make it a table
    // 抽象 父類執行
    switch (serviceId){
        case IMBaseDefine.ServiceID.SID_LOGIN_VALUE:
            IMPacketDispatcher.loginPacketDispatcher(commandId,codedInputStream);
            break;
        case IMBaseDefine.ServiceID.SID_BUDDY_LIST_VALUE:
            IMPacketDispatcher.buddyPacketDispatcher(commandId,codedInputStream);
            break;
        case IMBaseDefine.ServiceID.SID_MSG_VALUE:
            IMPacketDispatcher.msgPacketDispatcher(commandId,codedInputStream);
            break;
        case IMBaseDefine.ServiceID.SID_GROUP_VALUE:
            IMPacketDispatcher.groupPacketDispatcher(commandId,codedInputStream);
            break;
        default:
            logger.e("packet#unhandled serviceId:%d, commandId:%d", serviceId,
                    commandId);
            break;
    }
}
 
開發者ID:ccfish86,項目名稱:sctalk,代碼行數:40,代碼來源:IMSocketManager.java

示例11: readDataManifest

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
private SnapshotDataManifest readDataManifest() throws IOException {
  FSDataInputStream in = null;
  try {
    in = fs.open(new Path(workingDir, DATA_MANIFEST_NAME));
    CodedInputStream cin = CodedInputStream.newInstance(in);
    cin.setSizeLimit(manifestSizeLimit);
    return SnapshotDataManifest.parseFrom(cin);
  } catch (FileNotFoundException e) {
    return null;
  } finally {
    if (in != null) in.close();
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:14,代碼來源:SnapshotManifest.java

示例12: mergeDelimitedFrom

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
/**
 * This version of protobuf's mergeDelimitedFrom avoids the hard-coded 64MB limit for decoding
 * buffers
 * @param builder current message builder
 * @param in Inputsream with delimited protobuf data
 * @throws IOException
 */
public static void mergeDelimitedFrom(Message.Builder builder, InputStream in)
  throws IOException {
  // This used to be builder.mergeDelimitedFrom(in);
  // but is replaced to allow us to bump the protobuf size limit.
  final int firstByte = in.read();
  if (firstByte != -1) {
    final int size = CodedInputStream.readRawVarint32(firstByte, in);
    final InputStream limitedInput = new LimitInputStream(in, size);
    final CodedInputStream codedInput = CodedInputStream.newInstance(limitedInput);
    codedInput.setSizeLimit(size);
    builder.mergeFrom(codedInput);
    codedInput.checkLastTagWas(0);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:22,代碼來源:ProtobufUtil.java

示例13: mergeFrom

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
/**
 * This version of protobuf's mergeFrom avoids the hard-coded 64MB limit for decoding
 * buffers where the message size is not known
 * @param builder current message builder
 * @param in InputStream containing protobuf data
 * @throws IOException 
 */
public static void mergeFrom(Message.Builder builder, InputStream in)
    throws IOException {
  final CodedInputStream codedInput = CodedInputStream.newInstance(in);
  codedInput.setSizeLimit(Integer.MAX_VALUE);
  builder.mergeFrom(codedInput);
  codedInput.checkLastTagWas(0);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:15,代碼來源:ProtobufUtil.java

示例14: isWallet

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
/**
 * Cheap test to see if input stream is a wallet. This checks for a magic value at the beginning of the stream.
 * 
 * @param is
 *            input stream to test
 * @return true if input stream is a wallet
 */
public static boolean isWallet(InputStream is) {
    try {
        final CodedInputStream cis = CodedInputStream.newInstance(is);
        final int tag = cis.readTag();
        final int field = WireFormat.getTagFieldNumber(tag);
        if (field != 1) // network_identifier
            return false;
        final String network = cis.readString();
        return NetworkParameters.fromID(network) != null;
    } catch (IOException x) {
        return false;
    }
}
 
開發者ID:HashEngineering,項目名稱:namecoinj,代碼行數:21,代碼來源:WalletProtobufSerializer.java

示例15: apply

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
List<T> apply(InputStream in) throws IOException {
    List<T> list = new ArrayList<>();
    CodedInputStream stream = CodedInputStream.newInstance(in);
    int size;
    while (!stream.isAtEnd() && (size = stream.readRawVarint32()) != 0) {
        ByteArrayInputStream delimited = new ByteArrayInputStream(stream.readRawBytes(size));
        list.add(parse.apply(delimited));
    }
    return list;
}
 
開發者ID:horrorho,項目名稱:InflatableDonkey,代碼行數:11,代碼來源:DelimitedProtobufHandler.java


注:本文中的com.google.protobuf.CodedInputStream.newInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。