資源簡介
opencv編譯附加組件所需庫
代碼片段和文件信息
import?com.google.protobuf.ByteString;
import?com.google.protobuf.CodedInputStream;
import?com.google.protobuf.conformance.Conformance;
import?com.google.protobuf.InvalidProtocolBufferException;
import?com.google.protobuf_test_messages.proto3.TestMessagesProto3;
import?com.google.protobuf.util.JsonFormat;
import?com.google.protobuf.util.JsonFormat.TypeRegistry;
import?java.io.IOException;
import?java.nio.ByteBuffer;
class?ConformanceJava?{
??private?int?testCount?=?0;
??private?TypeRegistry?typeRegistry;
??private?boolean?readFromStdin(byte[]?buf?int?len)?throws?Exception?{
????int?ofs?=?0;
????while?(len?>?0)?{
??????int?read?=?System.in.read(buf?ofs?len);
??????if?(read?==?-1)?{
????????return?false;??//?EOF
??????}
??????ofs?+=?read;
??????len?-=?read;
????}
????return?true;
??}
??private?void?writeToStdout(byte[]?buf)?throws?Exception?{
????System.out.write(buf);
??}
??//?Returns?-1?on?EOF?(the?actual?values?will?always?be?positive).
??private?int?readLittleEndianIntFromStdin()?throws?Exception?{
????byte[]?buf?=?new?byte[4];
????if?(!readFromStdin(buf?4))?{
??????return?-1;
????}
????return?(buf[0]?&?0xff)
????????|?((buf[1]?&?0xff)?<8)
????????|?((buf[2]?&?0xff)?<16)
????????|?((buf[3]?&?0xff)?<24);
??}
??private?void?writeLittleEndianIntToStdout(int?val)?throws?Exception?{
????byte[]?buf?=?new?byte[4];
????buf[0]?=?(byte)val;
????buf[1]?=?(byte)(val?>>?8);
????buf[2]?=?(byte)(val?>>?16);
????buf[3]?=?(byte)(val?>>?24);
????writeToStdout(buf);
??}
??private?enum?BinaryDecoder?{
????BYTE_STRING_DECODER()?{
??????@Override
??????public?TestMessagesProto3.TestAllTypes?parse(ByteString?bytes)
??????????throws?InvalidProtocolBufferException?{
????????return?TestMessagesProto3.TestAllTypes.parseFrom(bytes);
??????}
????}
????BYTE_ARRAY_DECODER()?{
??????@Override
??????public?TestMessagesProto3.TestAllTypes?parse(ByteString?bytes)
??????????throws?InvalidProtocolBufferException?{
????????return?TestMessagesProto3.TestAllTypes.parseFrom(bytes.toByteArray());
??????}
????}
????ARRAY_BYTE_BUFFER_DECODER()?{
??????@Override
??????public?TestMessagesProto3.TestAllTypes?parse(ByteString?bytes)
??????????throws?InvalidProtocolBufferException?{
????????ByteBuffer?buffer?=?ByteBuffer.allocate(bytes.size());
????????bytes.copyTo(buffer);
????????buffer.flip();
????????try?{
??????????return?TestMessagesProto3.TestAllTypes.parseFrom(CodedInputStream.newInstance(buffer));
????????}?catch?(InvalidProtocolBufferException?e)?{
??????????throw?e;
????????}?catch?(IOException?e)?{
??????????throw?new?RuntimeException(
??????????????“ByteString?based?ByteBuffer?should?not?throw?IOException.“?e);
????????}
??????}
????}
????READONLY_ARRAY_BYTE_BUFFER_DECODER()?{
??????@Override
??????public?TestMessagesProto3.TestAllTypes?parse(ByteString?bytes)
??????????throws?InvalidProtocolBufferException?{
????????try?{
??????????return?TestMessagesProto3.TestAllTypes.parseFrom(
??????????????CodedInputStream.newInstance(bytes.asReadOnlyByteBuffer()));
???
- 上一篇:戰德臣計算機思維導論mooc全部習題及答案解析
- 下一篇:商品管理系統完整版1.0
評論
共有 條評論