当前位置: 首页>>代码示例>>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;未经允许,请勿转载。