本文整理汇总了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());
}
示例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;
}
示例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());
}
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
}
示例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);
}
}
示例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;
}
}
示例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();
}
}
示例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);
}
}
示例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);
}
示例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;
}
}
示例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;
}