浅谈序列化之protobuf与avro对比(Java)
最近在做socket通信中用到了关于序列化工具选型的问题,在调研过程中开始趋向于用protobuf,可以省去了编解码的过程。能够实现快速开发,且只需要维护一份协议文件即可。
但是调研过程中发现了protobuf的一些弊端,比如需要生成相应的文件类,和业务绑定太紧密,所以在看了avro之后发现它完美解决了这个问题。
下面记录下对这两种序列化工具的入门与测评。
一、protobuf基本操作
protobuf简介:
protocol buffers (a.k.a., protobuf) are google's language-neutral, platform-neutral, extensible mechanism for serializing structured data.
protobuf是google提供的一种跨语言、跨平台、可扩展的序列化工具。
1.1定义协议文件(部分字段)(tcplog.proto):
syntax = "proto2"; message tcplog{ optional int32 total_byteps = 1; optional int64 flow_start_time =2; optional int64 date =3; }
1.2生成对应的java类:
生成过程可以使用ecplise 的插件 或者 直接在控制台中使用命令生成。
命令行中生成规则如下:
protoc.exe -i=proto的输入目录 --java_out=java类输出目录 proto的输入目录包括包括proto文件
生成java类如下:
// generated by the protocol buffer compiler. do not edit! // source: tcplog.proto public final class tcplogouterclass { private tcplogouterclass() {} public static void registerallextensions( com.google.protobuf.extensionregistrylite registry) { } public static void registerallextensions( com.google.protobuf.extensionregistry registry) { registerallextensions( (com.google.protobuf.extensionregistrylite) registry); } public interface tcplogorbuilder extends // @@protoc_insertion_point(interface_extends:tcplog) com.google.protobuf.messageorbuilder { /** * <code>optional int32 total_byteps = 1;</code> */ boolean hastotalbyteps(); /** * <code>optional int32 total_byteps = 1;</code> */ int gettotalbyteps(); /** * <code>optional int64 flow_start_time = 2;</code> */ boolean hasflowstarttime(); /** * <code>optional int64 flow_start_time = 2;</code> */ long getflowstarttime(); /** * <code>optional int64 date = 3;</code> */ boolean hasdate(); /** * <code>optional int64 date = 3;</code> */ long getdate(); /** * <code>optional int64 server_total_packet = 4;</code> */ boolean hasservertotalpacket(); /** * <code>optional int64 server_total_packet = 4;</code> */ long getservertotalpacket(); /** * <code>optional int64 client_total_byte = 5;</code> */ boolean hasclienttotalbyte(); /** * <code>optional int64 client_total_byte = 5;</code> */ long getclienttotalbyte(); /** * <code>optional int32 link_id = 6;</code> */ boolean haslinkid(); /** * <code>optional int32 link_id = 6;</code> */ int getlinkid(); /** * <code>optional int64 total_byte = 7;</code> */ boolean hastotalbyte(); /** * <code>optional int64 total_byte = 7;</code> */ long gettotalbyte(); /** * <code>optional int64 flow_end_time = 8;</code> */ boolean hasflowendtime(); /** * <code>optional int64 flow_end_time = 8;</code> */ long getflowendtime(); /** * <code>optional int32 client_port = 9;</code> */ boolean hasclientport(); /** * <code>optional int32 client_port = 9;</code> */ int getclientport(); /** * <code>optional int32 protocol = 10;</code> */ boolean hasprotocol(); /** * <code>optional int32 protocol = 10;</code> */ int getprotocol(); /** * <code>optional int64 total_packet = 11;</code> */ boolean hastotalpacket(); /** * <code>optional int64 total_packet = 11;</code> */ long gettotalpacket(); /** * <code>optional int64 flow_duration = 12;</code> */ boolean hasflowduration(); /** * <code>optional int64 flow_duration = 12;</code> */ long getflowduration(); /** * <code>optional string id = 13;</code> */ boolean hasid(); /** * <code>optional string id = 13;</code> */ java.lang.string getid(); /** * <code>optional string id = 13;</code> */ com.google.protobuf.bytestring getidbytes(); /** * <code>optional string server_ip_addr = 14;</code> */ boolean hasserveripaddr(); /** * <code>optional string server_ip_addr = 14;</code> */ java.lang.string getserveripaddr(); /** * <code>optional string server_ip_addr = 14;</code> */ com.google.protobuf.bytestring getserveripaddrbytes(); /** * <code>optional string direction_mask = 15;</code> */ boolean hasdirectionmask(); /** * <code>optional string direction_mask = 15;</code> */ java.lang.string getdirectionmask(); /** * <code>optional string direction_mask = 15;</code> */ com.google.protobuf.bytestring getdirectionmaskbytes(); /** * <code>optional int32 app = 16;</code> */ boolean hasapp(); /** * <code>optional int32 app = 16;</code> */ int getapp(); /** * <code>optional int32 client_country_id = 17;</code> */ boolean hasclientcountryid(); /** * <code>optional int32 client_country_id = 17;</code> */ int getclientcountryid(); /** * <code>optional int32 client_netsegment_id = 18;</code> */ boolean hasclientnetsegmentid(); /** * <code>optional int32 client_netsegment_id = 18;</code> */ int getclientnetsegmentid(); /** * <code>optional int64 client_total_packet = 19;</code> */ boolean hasclienttotalpacket(); /** * <code>optional int64 client_total_packet = 19;</code> */ long getclienttotalpacket(); /** * <code>optional string client_ip_addr = 20;</code> */ boolean hasclientipaddr(); /** * <code>optional string client_ip_addr = 20;</code> */ java.lang.string getclientipaddr(); /** * <code>optional string client_ip_addr = 20;</code> */ com.google.protobuf.bytestring getclientipaddrbytes(); /** * <code>optional int32 tcp_status = 21;</code> */ boolean hastcpstatus(); /** * <code>optional int32 tcp_status = 21;</code> */ int gettcpstatus(); /** * <code>optional int32 server_country_id = 22;</code> */ boolean hasservercountryid(); /** * <code>optional int32 server_country_id = 22;</code> */ int getservercountryid(); /** * <code>optional int32 server_netsegment_id = 23;</code> */ boolean hasservernetsegmentid(); /** * <code>optional int32 server_netsegment_id = 23;</code> */ int getservernetsegmentid(); /** * <code>optional int64 avg_pkt_size = 24;</code> */ boolean hasavgpktsize(); /** * <code>optional int64 avg_pkt_size = 24;</code> */ long getavgpktsize(); /** * <code>optional int32 server_port = 25;</code> */ boolean hasserverport(); /** * <code>optional int32 server_port = 25;</code> */ int getserverport(); /** * <code>optional int64 server_total_byte = 26;</code> */ boolean hasservertotalbyte(); /** * <code>optional int64 server_total_byte = 26;</code> */ long getservertotalbyte(); /** * <code>optional int32 total_packetps = 27;</code> */ boolean hastotalpacketps(); /** * <code>optional int32 total_packetps = 27;</code> */ int gettotalpacketps(); } /** * protobuf type {@code tcplog} */ public static final class tcplog extends com.google.protobuf.generatedmessagev3 implements // @@protoc_insertion_point(message_implements:tcplog) tcplogorbuilder { // use tcplog.newbuilder() to construct. private tcplog(com.google.protobuf.generatedmessagev3.builder<?> builder) { super(builder); } private tcplog() { totalbyteps_ = 0; flowstarttime_ = 0l; date_ = 0l; servertotalpacket_ = 0l; clienttotalbyte_ = 0l; linkid_ = 0; totalbyte_ = 0l; flowendtime_ = 0l; clientport_ = 0; protocol_ = 0; totalpacket_ = 0l; flowduration_ = 0l; id_ = ""; serveripaddr_ = ""; directionmask_ = ""; app_ = 0; clientcountryid_ = 0; clientnetsegmentid_ = 0; clienttotalpacket_ = 0l; clientipaddr_ = ""; tcpstatus_ = 0; servercountryid_ = 0; servernetsegmentid_ = 0; avgpktsize_ = 0l; serverport_ = 0; servertotalbyte_ = 0l; totalpacketps_ = 0; } @java.lang.override public final com.google.protobuf.unknownfieldset getunknownfields() { return this.unknownfields; } private tcplog( com.google.protobuf.codedinputstream input, com.google.protobuf.extensionregistrylite extensionregistry) throws com.google.protobuf.invalidprotocolbufferexception { this(); int mutable_bitfield0_ = 0; com.google.protobuf.unknownfieldset.builder unknownfields = com.google.protobuf.unknownfieldset.newbuilder(); try { boolean done = false; while (!done) { int tag = input.readtag(); switch (tag) { case 0: done = true; break; default: { if (!parseunknownfield(input, unknownfields, extensionregistry, tag)) { done = true; } break; } case 8: { bitfield0_ |= 0x00000001; totalbyteps_ = input.readint32(); break; } case 16: { bitfield0_ |= 0x00000002; flowstarttime_ = input.readint64(); break; } case 24: { bitfield0_ |= 0x00000004; date_ = input.readint64(); break; } case 32: { bitfield0_ |= 0x00000008; servertotalpacket_ = input.readint64(); break; } case 40: { bitfield0_ |= 0x00000010; clienttotalbyte_ = input.readint64(); break; } case 48: { bitfield0_ |= 0x00000020; linkid_ = input.readint32(); break; } case 56: { bitfield0_ |= 0x00000040; totalbyte_ = input.readint64(); break; } case 64: { bitfield0_ |= 0x00000080; flowendtime_ = input.readint64(); break; } case 72: { bitfield0_ |= 0x00000100; clientport_ = input.readint32(); break; } case 80: { bitfield0_ |= 0x00000200; protocol_ = input.readint32(); break; } case 88: { bitfield0_ |= 0x00000400; totalpacket_ = input.readint64(); break; } case 96: { bitfield0_ |= 0x00000800; flowduration_ = input.readint64(); break; } case 106: { com.google.protobuf.bytestring bs = input.readbytes(); bitfield0_ |= 0x00001000; id_ = bs; break; } case 114: { com.google.protobuf.bytestring bs = input.readbytes(); bitfield0_ |= 0x00002000; serveripaddr_ = bs; break; } case 122: { com.google.protobuf.bytestring bs = input.readbytes(); bitfield0_ |= 0x00004000; directionmask_ = bs; break; } case 128: { bitfield0_ |= 0x00008000; app_ = input.readint32(); break; } case 136: { bitfield0_ |= 0x00010000; clientcountryid_ = input.readint32(); break; } case 144: { bitfield0_ |= 0x00020000; clientnetsegmentid_ = input.readint32(); break; } case 152: { bitfield0_ |= 0x00040000; clienttotalpacket_ = input.readint64(); break; } case 162: { com.google.protobuf.bytestring bs = input.readbytes(); bitfield0_ |= 0x00080000; clientipaddr_ = bs; break; } case 168: { bitfield0_ |= 0x00100000; tcpstatus_ = input.readint32(); break; } case 176: { bitfield0_ |= 0x00200000; servercountryid_ = input.readint32(); break; } case 184: { bitfield0_ |= 0x00400000; servernetsegmentid_ = input.readint32(); break; } case 192: { bitfield0_ |= 0x00800000; avgpktsize_ = input.readint64(); break; } case 200: { bitfield0_ |= 0x01000000; serverport_ = input.readint32(); break; } case 208: { bitfield0_ |= 0x02000000; servertotalbyte_ = input.readint64(); break; } case 216: { bitfield0_ |= 0x04000000; totalpacketps_ = input.readint32(); break; } } } } catch (com.google.protobuf.invalidprotocolbufferexception e) { throw e.setunfinishedmessage(this); } catch (java.io.ioexception e) { throw new com.google.protobuf.invalidprotocolbufferexception( e).setunfinishedmessage(this); } finally { this.unknownfields = unknownfields.build(); makeextensionsimmutable(); } } public static final com.google.protobuf.descriptors.descriptor getdescriptor() { return tcplogouterclass.internal_static_tcplog_descriptor; } protected com.google.protobuf.generatedmessagev3.fieldaccessortable internalgetfieldaccessortable() { return tcplogouterclass.internal_static_tcplog_fieldaccessortable .ensurefieldaccessorsinitialized( tcplogouterclass.tcplog.class, tcplogouterclass.tcplog.builder.class); } private int bitfield0_; public static final int total_byteps_field_number = 1; private int totalbyteps_; /** * <code>optional int32 total_byteps = 1;</code> */ public boolean hastotalbyteps() { return ((bitfield0_ & 0x00000001) == 0x00000001); } /** * <code>optional int32 total_byteps = 1;</code> */ public int gettotalbyteps() { return totalbyteps_; } public static final int flow_start_time_field_number = 2; private long flowstarttime_; /** * <code>optional int64 flow_start_time = 2;</code> */ public boolean hasflowstarttime() { return ((bitfield0_ & 0x00000002) == 0x00000002); } /** * <code>optional int64 flow_start_time = 2;</code> */ public long getflowstarttime() { return flowstarttime_; } public static final int date_field_number = 3; private long date_; /** * <code>optional int64 date = 3;</code> */ public boolean hasdate() { return ((bitfield0_ & 0x00000004) == 0x00000004); } /** * <code>optional int64 date = 3;</code> */ public long getdate() { return date_; } public static final int server_total_packet_field_number = 4; private long servertotalpacket_; /** * <code>optional int64 server_total_packet = 4;</code> */ public boolean hasservertotalpacket() { return ((bitfield0_ & 0x00000008) == 0x00000008); } /** * <code>optional int64 server_total_packet = 4;</code> */ public long getservertotalpacket() { return servertotalpacket_; } public static final int client_total_byte_field_number = 5; private long clienttotalbyte_; /** * <code>optional int64 client_total_byte = 5;</code> */ public boolean hasclienttotalbyte() { return ((bitfield0_ & 0x00000010) == 0x00000010); } /** * <code>optional int64 client_total_byte = 5;</code> */ public long getclienttotalbyte() { return clienttotalbyte_; } public static final int link_id_field_number = 6; private int linkid_; /** * <code>optional int32 link_id = 6;</code> */ public boolean haslinkid() { return ((bitfield0_ & 0x00000020) == 0x00000020); } /** * <code>optional int32 link_id = 6;</code> */ public int getlinkid() { return linkid_; } public static final int total_byte_field_number = 7; private long totalbyte_; /** * <code>optional int64 total_byte = 7;</code> */ public boolean hastotalbyte() { return ((bitfield0_ & 0x00000040) == 0x00000040); } /** * <code>optional int64 total_byte = 7;</code> */ public long gettotalbyte() { return totalbyte_; } public static final int flow_end_time_field_number = 8; private long flowendtime_; /** * <code>optional int64 flow_end_time = 8;</code> */ public boolean hasflowendtime() { return ((bitfield0_ & 0x00000080) == 0x00000080); } /** * <code>optional int64 flow_end_time = 8;</code> */ public long getflowendtime() { return flowendtime_; } public static final int client_port_field_number = 9; private int clientport_; /** * <code>optional int32 client_port = 9;</code> */ public boolean hasclientport() { return ((bitfield0_ & 0x00000100) == 0x00000100); } /** * <code>optional int32 client_port = 9;</code> */ public int getclientport() { return clientport_; } public static final int protocol_field_number = 10; private int protocol_; /** * <code>optional int32 protocol = 10;</code> */ public boolean hasprotocol() { return ((bitfield0_ & 0x00000200) == 0x00000200); } /** * <code>optional int32 protocol = 10;</code> */ public int getprotocol() { return protocol_; } public static final int total_packet_field_number = 11; private long totalpacket_; /** * <code>optional int64 total_packet = 11;</code> */ public boolean hastotalpacket() { return ((bitfield0_ & 0x00000400) == 0x00000400); } /** * <code>optional int64 total_packet = 11;</code> */ public long gettotalpacket() { return totalpacket_; } public static final int flow_duration_field_number = 12; private long flowduration_; /** * <code>optional int64 flow_duration = 12;</code> */ public boolean hasflowduration() { return ((bitfield0_ & 0x00000800) == 0x00000800); } /** * <code>optional int64 flow_duration = 12;</code> */ public long getflowduration() { return flowduration_; } public static final int id_field_number = 13; private volatile java.lang.object id_; /** * <code>optional string id = 13;</code> */ public boolean hasid() { return ((bitfield0_ & 0x00001000) == 0x00001000); } /** * <code>optional string id = 13;</code> */ public java.lang.string getid() { java.lang.object ref = id_; if (ref instanceof java.lang.string) { return (java.lang.string) ref; } else { com.google.protobuf.bytestring bs = (com.google.protobuf.bytestring) ref; java.lang.string s = bs.tostringutf8(); if (bs.isvalidutf8()) { id_ = s; } return s; } } /** * <code>optional string id = 13;</code> */ public com.google.protobuf.bytestring getidbytes() { java.lang.object ref = id_; if (ref instanceof java.lang.string) { com.google.protobuf.bytestring b = com.google.protobuf.bytestring.copyfromutf8( (java.lang.string) ref); id_ = b; return b; } else { return (com.google.protobuf.bytestring) ref; } } public static final int server_ip_addr_field_number = 14; private volatile java.lang.object serveripaddr_; /** * <code>optional string server_ip_addr = 14;</code> */ public boolean hasserveripaddr() { return ((bitfield0_ & 0x00002000) == 0x00002000); } /** * <code>optional string server_ip_addr = 14;</code> */ public java.lang.string getserveripaddr() { java.lang.object ref = serveripaddr_; if (ref instanceof java.lang.string) { return (java.lang.string) ref; } else { com.google.protobuf.bytestring bs = (com.google.protobuf.bytestring) ref; java.lang.string s = bs.tostringutf8(); if (bs.isvalidutf8()) { serveripaddr_ = s; } return s; } } /** * <code>optional string server_ip_addr = 14;</code> */ public com.google.protobuf.bytestring getserveripaddrbytes() { java.lang.object ref = serveripaddr_; if (ref instanceof java.lang.string) { com.google.protobuf.bytestring b = com.google.protobuf.bytestring.copyfromutf8( (java.lang.string) ref); serveripaddr_ = b; return b; } else { return (com.google.protobuf.bytestring) ref; } } public static final int direction_mask_field_number = 15; private volatile java.lang.object directionmask_; /** * <code>optional string direction_mask = 15;</code> */ public boolean hasdirectionmask() { return ((bitfield0_ & 0x00004000) == 0x00004000); } /** * <code>optional string direction_mask = 15;</code> */ public java.lang.string getdirectionmask() { java.lang.object ref = directionmask_; if (ref instanceof java.lang.string) { return (java.lang.string) ref; } else { com.google.protobuf.bytestring bs = (com.google.protobuf.bytestring) ref; java.lang.string s = bs.tostringutf8(); if (bs.isvalidutf8()) { directionmask_ = s; } return s; } } /** * <code>optional string direction_mask = 15;</code> */ public com.google.protobuf.bytestring getdirectionmaskbytes() { java.lang.object ref = directionmask_; if (ref instanceof java.lang.string) { com.google.protobuf.bytestring b = com.google.protobuf.bytestring.copyfromutf8( (java.lang.string) ref); directionmask_ = b; return b; } else { return (com.google.protobuf.bytestring) ref; } } public static final int app_field_number = 16; private int app_; /** * <code>optional int32 app = 16;</code> */ public boolean hasapp() { return ((bitfield0_ & 0x00008000) == 0x00008000); } /** * <code>optional int32 app = 16;</code> */ public int getapp() { return app_; } public static final int client_country_id_field_number = 17; private int clientcountryid_; /** * <code>optional int32 client_country_id = 17;</code> */ public boolean hasclientcountryid() { return ((bitfield0_ & 0x00010000) == 0x00010000); } /** * <code>optional int32 client_country_id = 17;</code> */ public int getclientcountryid() { return clientcountryid_; } public static final int client_netsegment_id_field_number = 18; private int clientnetsegmentid_; /** * <code>optional int32 client_netsegment_id = 18;</code> */ public boolean hasclientnetsegmentid() { return ((bitfield0_ & 0x00020000) == 0x00020000); } /** * <code>optional int32 client_netsegment_id = 18;</code> */ public int getclientnetsegmentid() { return clientnetsegmentid_; } public static final int client_total_packet_field_number = 19; private long clienttotalpacket_; /** * <code>optional int64 client_total_packet = 19;</code> */ public boolean hasclienttotalpacket() { return ((bitfield0_ & 0x00040000) == 0x00040000); } /** * <code>optional int64 client_total_packet = 19;</code> */ public long getclienttotalpacket() { return clienttotalpacket_; } public static final int client_ip_addr_field_number = 20; private volatile java.lang.object clientipaddr_; /** * <code>optional string client_ip_addr = 20;</code> */ public boolean hasclientipaddr() { return ((bitfield0_ & 0x00080000) == 0x00080000); } /** * <code>optional string client_ip_addr = 20;</code> */ public java.lang.string getclientipaddr() { java.lang.object ref = clientipaddr_; if (ref instanceof java.lang.string) { return (java.lang.string) ref; } else { com.google.protobuf.bytestring bs = (com.google.protobuf.bytestring) ref; java.lang.string s = bs.tostringutf8(); if (bs.isvalidutf8()) { clientipaddr_ = s; } return s; } } /** * <code>optional string client_ip_addr = 20;</code> */ public com.google.protobuf.bytestring getclientipaddrbytes() { java.lang.object ref = clientipaddr_; if (ref instanceof java.lang.string) { com.google.protobuf.bytestring b = com.google.protobuf.bytestring.copyfromutf8( (java.lang.string) ref); clientipaddr_ = b; return b; } else { return (com.google.protobuf.bytestring) ref; } } public static final int tcp_status_field_number = 21; private int tcpstatus_; /** * <code>optional int32 tcp_status = 21;</code> */ public boolean hastcpstatus() { return ((bitfield0_ & 0x00100000) == 0x00100000); } /** * <code>optional int32 tcp_status = 21;</code> */ public int gettcpstatus() { return tcpstatus_; } public static final int server_country_id_field_number = 22; private int servercountryid_; /** * <code>optional int32 server_country_id = 22;</code> */ public boolean hasservercountryid() { return ((bitfield0_ & 0x00200000) == 0x00200000); } /** * <code>optional int32 server_country_id = 22;</code> */ public int getservercountryid() { return servercountryid_; } public static final int server_netsegment_id_field_number = 23; private int servernetsegmentid_; /** * <code>optional int32 server_netsegment_id = 23;</code> */ public boolean hasservernetsegmentid() { return ((bitfield0_ & 0x00400000) == 0x00400000); } /** * <code>optional int32 server_netsegment_id = 23;</code> */ public int getservernetsegmentid() { return servernetsegmentid_; } public static final int avg_pkt_size_field_number = 24; private long avgpktsize_; /** * <code>optional int64 avg_pkt_size = 24;</code> */ public boolean hasavgpktsize() { return ((bitfield0_ & 0x00800000) == 0x00800000); } /** * <code>optional int64 avg_pkt_size = 24;</code> */ public long getavgpktsize() { return avgpktsize_; } public static final int server_port_field_number = 25; private int serverport_; /** * <code>optional int32 server_port = 25;</code> */ public boolean hasserverport() { return ((bitfield0_ & 0x01000000) == 0x01000000); } /** * <code>optional int32 server_port = 25;</code> */ public int getserverport() { return serverport_; } public static final int server_total_byte_field_number = 26; private long servertotalbyte_; /** * <code>optional int64 server_total_byte = 26;</code> */ public boolean hasservertotalbyte() { return ((bitfield0_ & 0x02000000) == 0x02000000); } /** * <code>optional int64 server_total_byte = 26;</code> */ public long getservertotalbyte() { return servertotalbyte_; } public static final int total_packetps_field_number = 27; private int totalpacketps_; /** * <code>optional int32 total_packetps = 27;</code> */ public boolean hastotalpacketps() { return ((bitfield0_ & 0x04000000) == 0x04000000); } /** * <code>optional int32 total_packetps = 27;</code> */ public int gettotalpacketps() { return totalpacketps_; } private byte memoizedisinitialized = -1; public final boolean isinitialized() { byte isinitialized = memoizedisinitialized; if (isinitialized == 1) return true; if (isinitialized == 0) return false; memoizedisinitialized = 1; return true; } public void writeto(com.google.protobuf.codedoutputstream output) throws java.io.ioexception { if (((bitfield0_ & 0x00000001) == 0x00000001)) { output.writeint32(1, totalbyteps_); } if (((bitfield0_ & 0x00000002) == 0x00000002)) { output.writeint64(2, flowstarttime_); } if (((bitfield0_ & 0x00000004) == 0x00000004)) { output.writeint64(3, date_); } if (((bitfield0_ & 0x00000008) == 0x00000008)) { output.writeint64(4, servertotalpacket_); } if (((bitfield0_ & 0x00000010) == 0x00000010)) { output.writeint64(5, clienttotalbyte_); } if (((bitfield0_ & 0x00000020) == 0x00000020)) { output.writeint32(6, linkid_); } if (((bitfield0_ & 0x00000040) == 0x00000040)) { output.writeint64(7, totalbyte_); } if (((bitfield0_ & 0x00000080) == 0x00000080)) { output.writeint64(8, flowendtime_); } if (((bitfield0_ & 0x00000100) == 0x00000100)) { output.writeint32(9, clientport_); } if (((bitfield0_ & 0x00000200) == 0x00000200)) { output.writeint32(10, protocol_); } if (((bitfield0_ & 0x00000400) == 0x00000400)) { output.writeint64(11, totalpacket_); } if (((bitfield0_ & 0x00000800) == 0x00000800)) { output.writeint64(12, flowduration_); } if (((bitfield0_ & 0x00001000) == 0x00001000)) { com.google.protobuf.generatedmessagev3.writestring(output, 13, id_); } if (((bitfield0_ & 0x00002000) == 0x00002000)) { com.google.protobuf.generatedmessagev3.writestring(output, 14, serveripaddr_); } if (((bitfield0_ & 0x00004000) == 0x00004000)) { com.google.protobuf.generatedmessagev3.writestring(output, 15, directionmask_); } if (((bitfield0_ & 0x00008000) == 0x00008000)) { output.writeint32(16, app_); } if (((bitfield0_ & 0x00010000) == 0x00010000)) { output.writeint32(17, clientcountryid_); } if (((bitfield0_ & 0x00020000) == 0x00020000)) { output.writeint32(18, clientnetsegmentid_); } if (((bitfield0_ & 0x00040000) == 0x00040000)) { output.writeint64(19, clienttotalpacket_); } if (((bitfield0_ & 0x00080000) == 0x00080000)) { com.google.protobuf.generatedmessagev3.writestring(output, 20, clientipaddr_); } if (((bitfield0_ & 0x00100000) == 0x00100000)) { output.writeint32(21, tcpstatus_); } if (((bitfield0_ & 0x00200000) == 0x00200000)) { output.writeint32(22, servercountryid_); } if (((bitfield0_ & 0x00400000) == 0x00400000)) { output.writeint32(23, servernetsegmentid_); } if (((bitfield0_ & 0x00800000) == 0x00800000)) { output.writeint64(24, avgpktsize_); } if (((bitfield0_ & 0x01000000) == 0x01000000)) { output.writeint32(25, serverport_); } if (((bitfield0_ & 0x02000000) == 0x02000000)) { output.writeint64(26, servertotalbyte_); } if (((bitfield0_ & 0x04000000) == 0x04000000)) { output.writeint32(27, totalpacketps_); } unknownfields.writeto(output); } public int getserializedsize() { int size = memoizedsize; if (size != -1) return size; size = 0; if (((bitfield0_ & 0x00000001) == 0x00000001)) { size += com.google.protobuf.codedoutputstream .computeint32size(1, totalbyteps_); } if (((bitfield0_ & 0x00000002) == 0x00000002)) { size += com.google.protobuf.codedoutputstream .computeint64size(2, flowstarttime_); } if (((bitfield0_ & 0x00000004) == 0x00000004)) { size += com.google.protobuf.codedoutputstream .computeint64size(3, date_); } if (((bitfield0_ & 0x00000008) == 0x00000008)) { size += com.google.protobuf.codedoutputstream .computeint64size(4, servertotalpacket_); } if (((bitfield0_ & 0x00000010) == 0x00000010)) { size += com.google.protobuf.codedoutputstream .computeint64size(5, clienttotalbyte_); } if (((bitfield0_ & 0x00000020) == 0x00000020)) { size += com.google.protobuf.codedoutputstream .computeint32size(6, linkid_); } if (((bitfield0_ & 0x00000040) == 0x00000040)) { size += com.google.protobuf.codedoutputstream .computeint64size(7, totalbyte_); } if (((bitfield0_ & 0x00000080) == 0x00000080)) { size += com.google.protobuf.codedoutputstream .computeint64size(8, flowendtime_); } if (((bitfield0_ & 0x00000100) == 0x00000100)) { size += com.google.protobuf.codedoutputstream .computeint32size(9, clientport_); } if (((bitfield0_ & 0x00000200) == 0x00000200)) { size += com.google.protobuf.codedoutputstream .computeint32size(10, protocol_); } if (((bitfield0_ & 0x00000400) == 0x00000400)) { size += com.google.protobuf.codedoutputstream .computeint64size(11, totalpacket_); } if (((bitfield0_ & 0x00000800) == 0x00000800)) { size += com.google.protobuf.codedoutputstream .computeint64size(12, flowduration_); } if (((bitfield0_ & 0x00001000) == 0x00001000)) { size += com.google.protobuf.generatedmessagev3.computestringsize(13, id_); } if (((bitfield0_ & 0x00002000) == 0x00002000)) { size += com.google.protobuf.generatedmessagev3.computestringsize(14, serveripaddr_); } if (((bitfield0_ & 0x00004000) == 0x00004000)) { size += com.google.protobuf.generatedmessagev3.computestringsize(15, directionmask_); } if (((bitfield0_ & 0x00008000) == 0x00008000)) { size += com.google.protobuf.codedoutputstream .computeint32size(16, app_); } if (((bitfield0_ & 0x00010000) == 0x00010000)) { size += com.google.protobuf.codedoutputstream .computeint32size(17, clientcountryid_); } if (((bitfield0_ & 0x00020000) == 0x00020000)) { size += com.google.protobuf.codedoutputstream .computeint32size(18, clientnetsegmentid_); } if (((bitfield0_ & 0x00040000) == 0x00040000)) { size += com.google.protobuf.codedoutputstream .computeint64size(19, clienttotalpacket_); } if (((bitfield0_ & 0x00080000) == 0x00080000)) { size += com.google.protobuf.generatedmessagev3.computestringsize(20, clientipaddr_); } if (((bitfield0_ & 0x00100000) == 0x00100000)) { size += com.google.protobuf.codedoutputstream .computeint32size(21, tcpstatus_); } if (((bitfield0_ & 0x00200000) == 0x00200000)) { size += com.google.protobuf.codedoutputstream .computeint32size(22, servercountryid_); } if (((bitfield0_ & 0x00400000) == 0x00400000)) { size += com.google.protobuf.codedoutputstream .computeint32size(23, servernetsegmentid_); } if (((bitfield0_ & 0x00800000) == 0x00800000)) { size += com.google.protobuf.codedoutputstream .computeint64size(24, avgpktsize_); } if (((bitfield0_ & 0x01000000) == 0x01000000)) { size += com.google.protobuf.codedoutputstream .computeint32size(25, serverport_); } if (((bitfield0_ & 0x02000000) == 0x02000000)) { size += com.google.protobuf.codedoutputstream .computeint64size(26, servertotalbyte_); } if (((bitfield0_ & 0x04000000) == 0x04000000)) { size += com.google.protobuf.codedoutputstream .computeint32size(27, totalpacketps_); } size += unknownfields.getserializedsize(); memoizedsize = size; return size; } private static final long serialversionuid = 0l; @java.lang.override public boolean equals(final java.lang.object obj) { if (obj == this) { return true; } if (!(obj instanceof tcplogouterclass.tcplog)) { return super.equals(obj); } tcplogouterclass.tcplog other = (tcplogouterclass.tcplog) obj; boolean result = true; result = result && (hastotalbyteps() == other.hastotalbyteps()); if (hastotalbyteps()) { result = result && (gettotalbyteps() == other.gettotalbyteps()); } result = result && (hasflowstarttime() == other.hasflowstarttime()); if (hasflowstarttime()) { result = result && (getflowstarttime() == other.getflowstarttime()); } result = result && (hasdate() == other.hasdate()); if (hasdate()) { result = result && (getdate() == other.getdate()); } result = result && (hasservertotalpacket() == other.hasservertotalpacket()); if (hasservertotalpacket()) { result = result && (getservertotalpacket() == other.getservertotalpacket()); } result = result && (hasclienttotalbyte() == other.hasclienttotalbyte()); if (hasclienttotalbyte()) { result = result && (getclienttotalbyte() == other.getclienttotalbyte()); } result = result && (haslinkid() == other.haslinkid()); if (haslinkid()) { result = result && (getlinkid() == other.getlinkid()); } result = result && (hastotalbyte() == other.hastotalbyte()); if (hastotalbyte()) { result = result && (gettotalbyte() == other.gettotalbyte()); } result = result && (hasflowendtime() == other.hasflowendtime()); if (hasflowendtime()) { result = result && (getflowendtime() == other.getflowendtime()); } result = result && (hasclientport() == other.hasclientport()); if (hasclientport()) { result = result && (getclientport() == other.getclientport()); } result = result && (hasprotocol() == other.hasprotocol()); if (hasprotocol()) { result = result && (getprotocol() == other.getprotocol()); } result = result && (hastotalpacket() == other.hastotalpacket()); if (hastotalpacket()) { result = result && (gettotalpacket() == other.gettotalpacket()); } result = result && (hasflowduration() == other.hasflowduration()); if (hasflowduration()) { result = result && (getflowduration() == other.getflowduration()); } result = result && (hasid() == other.hasid()); if (hasid()) { result = result && getid() .equals(other.getid()); } result = result && (hasserveripaddr() == other.hasserveripaddr()); if (hasserveripaddr()) { result = result && getserveripaddr() .equals(other.getserveripaddr()); } result = result && (hasdirectionmask() == other.hasdirectionmask()); if (hasdirectionmask()) { result = result && getdirectionmask() .equals(other.getdirectionmask()); } result = result && (hasapp() == other.hasapp()); if (hasapp()) { result = result && (getapp() == other.getapp()); } result = result && (hasclientcountryid() == other.hasclientcountryid()); if (hasclientcountryid()) { result = result && (getclientcountryid() == other.getclientcountryid()); } result = result && (hasclientnetsegmentid() == other.hasclientnetsegmentid()); if (hasclientnetsegmentid()) { result = result && (getclientnetsegmentid() == other.getclientnetsegmentid()); } result = result && (hasclienttotalpacket() == other.hasclienttotalpacket()); if (hasclienttotalpacket()) { result = result && (getclienttotalpacket() == other.getclienttotalpacket()); } result = result && (hasclientipaddr() == other.hasclientipaddr()); if (hasclientipaddr()) { result = result && getclientipaddr() .equals(other.getclientipaddr()); } result = result && (hastcpstatus() == other.hastcpstatus()); if (hastcpstatus()) { result = result && (gettcpstatus() == other.gettcpstatus()); } result = result && (hasservercountryid() == other.hasservercountryid()); if (hasservercountryid()) { result = result && (getservercountryid() == other.getservercountryid()); } result = result && (hasservernetsegmentid() == other.hasservernetsegmentid()); if (hasservernetsegmentid()) { result = result && (getservernetsegmentid() == other.getservernetsegmentid()); } result = result && (hasavgpktsize() == other.hasavgpktsize()); if (hasavgpktsize()) { result = result && (getavgpktsize() == other.getavgpktsize()); } result = result && (hasserverport() == other.hasserverport()); if (hasserverport()) { result = result && (getserverport() == other.getserverport()); } result = result && (hasservertotalbyte() == other.hasservertotalbyte()); if (hasservertotalbyte()) { result = result && (getservertotalbyte() == other.getservertotalbyte()); } result = result && (hastotalpacketps() == other.hastotalpacketps()); if (hastotalpacketps()) { result = result && (gettotalpacketps() == other.gettotalpacketps()); } result = result && unknownfields.equals(other.unknownfields); return result; } @java.lang.override public int hashcode() { if (memoizedhashcode != 0) { return memoizedhashcode; } int hash = 41; hash = (19 * hash) + getdescriptor().hashcode(); if (hastotalbyteps()) { hash = (37 * hash) + total_byteps_field_number; hash = (53 * hash) + gettotalbyteps(); } if (hasflowstarttime()) { hash = (37 * hash) + flow_start_time_field_number; hash = (53 * hash) + com.google.protobuf.internal.hashlong( getflowstarttime()); } if (hasdate()) { hash = (37 * hash) + date_field_number; hash = (53 * hash) + com.google.protobuf.internal.hashlong( getdate()); } if (hasservertotalpacket()) { hash = (37 * hash) + server_total_packet_field_number; hash = (53 * hash) + com.google.protobuf.internal.hashlong( getservertotalpacket()); } if (hasclienttotalbyte()) { hash = (37 * hash) + client_total_byte_field_number; hash = (53 * hash) + com.google.protobuf.internal.hashlong( getclienttotalbyte()); } if (haslinkid()) { hash = (37 * hash) + link_id_field_number; hash = (53 * hash) + getlinkid(); } if (hastotalbyte()) { hash = (37 * hash) + total_byte_field_number; hash = (53 * hash) + com.google.protobuf.internal.hashlong( gettotalbyte()); } if (hasflowendtime()) { hash = (37 * hash) + flow_end_time_field_number; hash = (53 * hash) + com.google.protobuf.internal.hashlong( getflowendtime()); } if (hasclientport()) { hash = (37 * hash) + client_port_field_number; hash = (53 * hash) + getclientport(); } if (hasprotocol()) { hash = (37 * hash) + protocol_field_number; hash = (53 * hash) + getprotocol(); } if (hastotalpacket()) { hash = (37 * hash) + total_packet_field_number; hash = (53 * hash) + com.google.protobuf.internal.hashlong( gettotalpacket()); } if (hasflowduration()) { hash = (37 * hash) + flow_duration_field_number; hash = (53 * hash) + com.google.protobuf.internal.hashlong( getflowduration()); } if (hasid()) { hash = (37 * hash) + id_field_number; hash = (53 * hash) + getid().hashcode(); } if (hasserveripaddr()) { hash = (37 * hash) + server_ip_addr_field_number; hash = (53 * hash) + getserveripaddr().hashcode(); } if (hasdirectionmask()) { hash = (37 * hash) + direction_mask_field_number; hash = (53 * hash) + getdirectionmask().hashcode(); } if (hasapp()) { hash = (37 * hash) + app_field_number; hash = (53 * hash) + getapp(); } if (hasclientcountryid()) { hash = (37 * hash) + client_country_id_field_number; hash = (53 * hash) + getclientcountryid(); } if (hasclientnetsegmentid()) { hash = (37 * hash) + client_netsegment_id_field_number; hash = (53 * hash) + getclientnetsegmentid(); } if (hasclienttotalpacket()) { hash = (37 * hash) + client_total_packet_field_number; hash = (53 * hash) + com.google.protobuf.internal.hashlong( getclienttotalpacket()); } if (hasclientipaddr()) { hash = (37 * hash) + client_ip_addr_field_number; hash = (53 * hash) + getclientipaddr().hashcode(); } if (hastcpstatus()) { hash = (37 * hash) + tcp_status_field_number; hash = (53 * hash) + gettcpstatus(); } if (hasservercountryid()) { hash = (37 * hash) + server_country_id_field_number; hash = (53 * hash) + getservercountryid(); } if (hasservernetsegmentid()) { hash = (37 * hash) + server_netsegment_id_field_number; hash = (53 * hash) + getservernetsegmentid(); } if (hasavgpktsize()) { hash = (37 * hash) + avg_pkt_size_field_number; hash = (53 * hash) + com.google.protobuf.internal.hashlong( getavgpktsize()); } if (hasserverport()) { hash = (37 * hash) + server_port_field_number; hash = (53 * hash) + getserverport(); } if (hasservertotalbyte()) { hash = (37 * hash) + server_total_byte_field_number; hash = (53 * hash) + com.google.protobuf.internal.hashlong( getservertotalbyte()); } if (hastotalpacketps()) { hash = (37 * hash) + total_packetps_field_number; hash = (53 * hash) + gettotalpacketps(); } hash = (29 * hash) + unknownfields.hashcode(); memoizedhashcode = hash; return hash; } public static tcplogouterclass.tcplog parsefrom( java.nio.bytebuffer data) throws com.google.protobuf.invalidprotocolbufferexception { return parser.parsefrom(data); } public static tcplogouterclass.tcplog parsefrom( java.nio.bytebuffer data, com.google.protobuf.extensionregistrylite extensionregistry) throws com.google.protobuf.invalidprotocolbufferexception { return parser.parsefrom(data, extensionregistry); } public static tcplogouterclass.tcplog parsefrom( com.google.protobuf.bytestring data) throws com.google.protobuf.invalidprotocolbufferexception { return parser.parsefrom(data); } public static tcplogouterclass.tcplog parsefrom( com.google.protobuf.bytestring data, com.google.protobuf.extensionregistrylite extensionregistry) throws com.google.protobuf.invalidprotocolbufferexception { return parser.parsefrom(data, extensionregistry); } public static tcplogouterclass.tcplog parsefrom(byte[] data) throws com.google.protobuf.invalidprotocolbufferexception { return parser.parsefrom(data); } public static tcplogouterclass.tcplog parsefrom( byte[] data, com.google.protobuf.extensionregistrylite extensionregistry) throws com.google.protobuf.invalidprotocolbufferexception { return parser.parsefrom(data, extensionregistry); } public static tcplogouterclass.tcplog parsefrom(java.io.inputstream input) throws java.io.ioexception { return com.google.protobuf.generatedmessagev3 .parsewithioexception(parser, input); } public static tcplogouterclass.tcplog parsefrom( java.io.inputstream input, com.google.protobuf.extensionregistrylite extensionregistry) throws java.io.ioexception { return com.google.protobuf.generatedmessagev3 .parsewithioexception(parser, input, extensionregistry); } public static tcplogouterclass.tcplog parsedelimitedfrom(java.io.inputstream input) throws java.io.ioexception { return com.google.protobuf.generatedmessagev3 .parsedelimitedwithioexception(parser, input); } public static tcplogouterclass.tcplog parsedelimitedfrom( java.io.inputstream input, com.google.protobuf.extensionregistrylite extensionregistry) throws java.io.ioexception { return com.google.protobuf.generatedmessagev3 .parsedelimitedwithioexception(parser, input, extensionregistry); } public static tcplogouterclass.tcplog parsefrom( com.google.protobuf.codedinputstream input) throws java.io.ioexception { return com.google.protobuf.generatedmessagev3 .parsewithioexception(parser, input); } public static tcplogouterclass.tcplog parsefrom( com.google.protobuf.codedinputstream input, com.google.protobuf.extensionregistrylite extensionregistry) throws java.io.ioexception { return com.google.protobuf.generatedmessagev3 .parsewithioexception(parser, input, extensionregistry); } public builder newbuilderfortype() { return newbuilder(); } public static builder newbuilder() { return default_instance.tobuilder(); } public static builder newbuilder(tcplogouterclass.tcplog prototype) { return default_instance.tobuilder().mergefrom(prototype); } public builder tobuilder() { return this == default_instance ? new builder() : new builder().mergefrom(this); } @java.lang.override protected builder newbuilderfortype( com.google.protobuf.generatedmessagev3.builderparent parent) { builder builder = new builder(parent); return builder; } /** * protobuf type {@code tcplog} */ public static final class builder extends com.google.protobuf.generatedmessagev3.builder<builder> implements // @@protoc_insertion_point(builder_implements:tcplog) tcplogouterclass.tcplogorbuilder { public static final com.google.protobuf.descriptors.descriptor getdescriptor() { return tcplogouterclass.internal_static_tcplog_descriptor; } protected com.google.protobuf.generatedmessagev3.fieldaccessortable internalgetfieldaccessortable() { return tcplogouterclass.internal_static_tcplog_fieldaccessortable .ensurefieldaccessorsinitialized( tcplogouterclass.tcplog.class, tcplogouterclass.tcplog.builder.class); } // construct using tcplogouterclass.tcplog.newbuilder() private builder() { maybeforcebuilderinitialization(); } private builder( com.google.protobuf.generatedmessagev3.builderparent parent) { super(parent); maybeforcebuilderinitialization(); } private void maybeforcebuilderinitialization() { if (com.google.protobuf.generatedmessagev3 .alwaysusefieldbuilders) { } } public builder clear() { super.clear(); totalbyteps_ = 0; bitfield0_ = (bitfield0_ & ~0x00000001); flowstarttime_ = 0l; bitfield0_ = (bitfield0_ & ~0x00000002); date_ = 0l; bitfield0_ = (bitfield0_ & ~0x00000004); servertotalpacket_ = 0l; bitfield0_ = (bitfield0_ & ~0x00000008); clienttotalbyte_ = 0l; bitfield0_ = (bitfield0_ & ~0x00000010); linkid_ = 0; bitfield0_ = (bitfield0_ & ~0x00000020); totalbyte_ = 0l; bitfield0_ = (bitfield0_ & ~0x00000040); flowendtime_ = 0l; bitfield0_ = (bitfield0_ & ~0x00000080); clientport_ = 0; bitfield0_ = (bitfield0_ & ~0x00000100); protocol_ = 0; bitfield0_ = (bitfield0_ & ~0x00000200); totalpacket_ = 0l; bitfield0_ = (bitfield0_ & ~0x00000400); flowduration_ = 0l; bitfield0_ = (bitfield0_ & ~0x00000800); id_ = ""; bitfield0_ = (bitfield0_ & ~0x00001000); serveripaddr_ = ""; bitfield0_ = (bitfield0_ & ~0x00002000); directionmask_ = ""; bitfield0_ = (bitfield0_ & ~0x00004000); app_ = 0; bitfield0_ = (bitfield0_ & ~0x00008000); clientcountryid_ = 0; bitfield0_ = (bitfield0_ & ~0x00010000); clientnetsegmentid_ = 0; bitfield0_ = (bitfield0_ & ~0x00020000); clienttotalpacket_ = 0l; bitfield0_ = (bitfield0_ & ~0x00040000); clientipaddr_ = ""; bitfield0_ = (bitfield0_ & ~0x00080000); tcpstatus_ = 0; bitfield0_ = (bitfield0_ & ~0x00100000); servercountryid_ = 0; bitfield0_ = (bitfield0_ & ~0x00200000); servernetsegmentid_ = 0; bitfield0_ = (bitfield0_ & ~0x00400000); avgpktsize_ = 0l; bitfield0_ = (bitfield0_ & ~0x00800000); serverport_ = 0; bitfield0_ = (bitfield0_ & ~0x01000000); servertotalbyte_ = 0l; bitfield0_ = (bitfield0_ & ~0x02000000); totalpacketps_ = 0; bitfield0_ = (bitfield0_ & ~0x04000000); return this; } public com.google.protobuf.descriptors.descriptor getdescriptorfortype() { return tcplogouterclass.internal_static_tcplog_descriptor; } public tcplogouterclass.tcplog getdefaultinstancefortype() { return tcplogouterclass.tcplog.getdefaultinstance(); } public tcplogouterclass.tcplog build() { tcplogouterclass.tcplog result = buildpartial(); if (!result.isinitialized()) { throw newuninitializedmessageexception(result); } return result; } public tcplogouterclass.tcplog buildpartial() { tcplogouterclass.tcplog result = new tcplogouterclass.tcplog(this); int from_bitfield0_ = bitfield0_; int to_bitfield0_ = 0; if (((from_bitfield0_ & 0x00000001) == 0x00000001)) { to_bitfield0_ |= 0x00000001; } result.totalbyteps_ = totalbyteps_; if (((from_bitfield0_ & 0x00000002) == 0x00000002)) { to_bitfield0_ |= 0x00000002; } result.flowstarttime_ = flowstarttime_; if (((from_bitfield0_ & 0x00000004) == 0x00000004)) { to_bitfield0_ |= 0x00000004; } result.date_ = date_; if (((from_bitfield0_ & 0x00000008) == 0x00000008)) { to_bitfield0_ |= 0x00000008; } result.servertotalpacket_ = servertotalpacket_; if (((from_bitfield0_ & 0x00000010) == 0x00000010)) { to_bitfield0_ |= 0x00000010; } result.clienttotalbyte_ = clienttotalbyte_; if (((from_bitfield0_ & 0x00000020) == 0x00000020)) { to_bitfield0_ |= 0x00000020; } result.linkid_ = linkid_; if (((from_bitfield0_ & 0x00000040) == 0x00000040)) { to_bitfield0_ |= 0x00000040; } result.totalbyte_ = totalbyte_; if (((from_bitfield0_ & 0x00000080) == 0x00000080)) { to_bitfield0_ |= 0x00000080; } result.flowendtime_ = flowendtime_; if (((from_bitfield0_ & 0x00000100) == 0x00000100)) { to_bitfield0_ |= 0x00000100; } result.clientport_ = clientport_; if (((from_bitfield0_ & 0x00000200) == 0x00000200)) { to_bitfield0_ |= 0x00000200; } result.protocol_ = protocol_; if (((from_bitfield0_ & 0x00000400) == 0x00000400)) { to_bitfield0_ |= 0x00000400; } result.totalpacket_ = totalpacket_; if (((from_bitfield0_ & 0x00000800) == 0x00000800)) { to_bitfield0_ |= 0x00000800; } result.flowduration_ = flowduration_; if (((from_bitfield0_ & 0x00001000) == 0x00001000)) { to_bitfield0_ |= 0x00001000; } result.id_ = id_; if (((from_bitfield0_ & 0x00002000) == 0x00002000)) { to_bitfield0_ |= 0x00002000; } result.serveripaddr_ = serveripaddr_; if (((from_bitfield0_ & 0x00004000) == 0x00004000)) { to_bitfield0_ |= 0x00004000; } result.directionmask_ = directionmask_; if (((from_bitfield0_ & 0x00008000) == 0x00008000)) { to_bitfield0_ |= 0x00008000; } result.app_ = app_; if (((from_bitfield0_ & 0x00010000) == 0x00010000)) { to_bitfield0_ |= 0x00010000; } result.clientcountryid_ = clientcountryid_; if (((from_bitfield0_ & 0x00020000) == 0x00020000)) { to_bitfield0_ |= 0x00020000; } result.clientnetsegmentid_ = clientnetsegmentid_; if (((from_bitfield0_ & 0x00040000) == 0x00040000)) { to_bitfield0_ |= 0x00040000; } result.clienttotalpacket_ = clienttotalpacket_; if (((from_bitfield0_ & 0x00080000) == 0x00080000)) { to_bitfield0_ |= 0x00080000; } result.clientipaddr_ = clientipaddr_; if (((from_bitfield0_ & 0x00100000) == 0x00100000)) { to_bitfield0_ |= 0x00100000; } result.tcpstatus_ = tcpstatus_; if (((from_bitfield0_ & 0x00200000) == 0x00200000)) { to_bitfield0_ |= 0x00200000; } result.servercountryid_ = servercountryid_; if (((from_bitfield0_ & 0x00400000) == 0x00400000)) { to_bitfield0_ |= 0x00400000; } result.servernetsegmentid_ = servernetsegmentid_; if (((from_bitfield0_ & 0x00800000) == 0x00800000)) { to_bitfield0_ |= 0x00800000; } result.avgpktsize_ = avgpktsize_; if (((from_bitfield0_ & 0x01000000) == 0x01000000)) { to_bitfield0_ |= 0x01000000; } result.serverport_ = serverport_; if (((from_bitfield0_ & 0x02000000) == 0x02000000)) { to_bitfield0_ |= 0x02000000; } result.servertotalbyte_ = servertotalbyte_; if (((from_bitfield0_ & 0x04000000) == 0x04000000)) { to_bitfield0_ |= 0x04000000; } result.totalpacketps_ = totalpacketps_; result.bitfield0_ = to_bitfield0_; onbuilt(); return result; } public builder clone() { return (builder) super.clone(); } public builder setfield( com.google.protobuf.descriptors.fielddescriptor field, object value) { return (builder) super.setfield(field, value); } public builder clearfield( com.google.protobuf.descriptors.fielddescriptor field) { return (builder) super.clearfield(field); } public builder clearoneof( com.google.protobuf.descriptors.oneofdescriptor oneof) { return (builder) super.clearoneof(oneof); } public builder setrepeatedfield( com.google.protobuf.descriptors.fielddescriptor field, int index, object value) { return (builder) super.setrepeatedfield(field, index, value); } public builder addrepeatedfield( com.google.protobuf.descriptors.fielddescriptor field, object value) { return (builder) super.addrepeatedfield(field, value); } public builder mergefrom(com.google.protobuf.message other) { if (other instanceof tcplogouterclass.tcplog) { return mergefrom((tcplogouterclass.tcplog)other); } else { super.mergefrom(other); return this; } } public builder mergefrom(tcplogouterclass.tcplog other) { if (other == tcplogouterclass.tcplog.getdefaultinstance()) return this; if (other.hastotalbyteps()) { settotalbyteps(other.gettotalbyteps()); } if (other.hasflowstarttime()) { setflowstarttime(other.getflowstarttime()); } if (other.hasdate()) { setdate(other.getdate()); } if (other.hasservertotalpacket()) { setservertotalpacket(other.getservertotalpacket()); } if (other.hasclienttotalbyte()) { setclienttotalbyte(other.getclienttotalbyte()); } if (other.haslinkid()) { setlinkid(other.getlinkid()); } if (other.hastotalbyte()) { settotalbyte(other.gettotalbyte()); } if (other.hasflowendtime()) { setflowendtime(other.getflowendtime()); } if (other.hasclientport()) { setclientport(other.getclientport()); } if (other.hasprotocol()) { setprotocol(other.getprotocol()); } if (other.hastotalpacket()) { settotalpacket(other.gettotalpacket()); } if (other.hasflowduration()) { setflowduration(other.getflowduration()); } if (other.hasid()) { bitfield0_ |= 0x00001000; id_ = other.id_; onchanged(); } if (other.hasserveripaddr()) { bitfield0_ |= 0x00002000; serveripaddr_ = other.serveripaddr_; onchanged(); } if (other.hasdirectionmask()) { bitfield0_ |= 0x00004000; directionmask_ = other.directionmask_; onchanged(); } if (other.hasapp()) { setapp(other.getapp()); } if (other.hasclientcountryid()) { setclientcountryid(other.getclientcountryid()); } if (other.hasclientnetsegmentid()) { setclientnetsegmentid(other.getclientnetsegmentid()); } if (other.hasclienttotalpacket()) { setclienttotalpacket(other.getclienttotalpacket()); } if (other.hasclientipaddr()) { bitfield0_ |= 0x00080000; clientipaddr_ = other.clientipaddr_; onchanged(); } if (other.hastcpstatus()) { settcpstatus(other.gettcpstatus()); } if (other.hasservercountryid()) { setservercountryid(other.getservercountryid()); } if (other.hasservernetsegmentid()) { setservernetsegmentid(other.getservernetsegmentid()); } if (other.hasavgpktsize()) { setavgpktsize(other.getavgpktsize()); } if (other.hasserverport()) { setserverport(other.getserverport()); } if (other.hasservertotalbyte()) { setservertotalbyte(other.getservertotalbyte()); } if (other.hastotalpacketps()) { settotalpacketps(other.gettotalpacketps()); } this.mergeunknownfields(other.unknownfields); onchanged(); return this; } public final boolean isinitialized() { return true; } public builder mergefrom( com.google.protobuf.codedinputstream input, com.google.protobuf.extensionregistrylite extensionregistry) throws java.io.ioexception { tcplogouterclass.tcplog parsedmessage = null; try { parsedmessage = parser.parsepartialfrom(input, extensionregistry); } catch (com.google.protobuf.invalidprotocolbufferexception e) { parsedmessage = (tcplogouterclass.tcplog) e.getunfinishedmessage(); throw e.unwrapioexception(); } finally { if (parsedmessage != null) { mergefrom(parsedmessage); } } return this; } private int bitfield0_; private int totalbyteps_ ; /** * <code>optional int32 total_byteps = 1;</code> */ public boolean hastotalbyteps() { return ((bitfield0_ & 0x00000001) == 0x00000001); } /** * <code>optional int32 total_byteps = 1;</code> */ public int gettotalbyteps() { return totalbyteps_; } /** * <code>optional int32 total_byteps = 1;</code> */ public builder settotalbyteps(int value) { bitfield0_ |= 0x00000001; totalbyteps_ = value; onchanged(); return this; } /** * <code>optional int32 total_byteps = 1;</code> */ public builder cleartotalbyteps() { bitfield0_ = (bitfield0_ & ~0x00000001); totalbyteps_ = 0; onchanged(); return this; } private long flowstarttime_ ; /** * <code>optional int64 flow_start_time = 2;</code> */ public boolean hasflowstarttime() { return ((bitfield0_ & 0x00000002) == 0x00000002); } /** * <code>optional int64 flow_start_time = 2;</code> */ public long getflowstarttime() { return flowstarttime_; } /** * <code>optional int64 flow_start_time = 2;</code> */ public builder setflowstarttime(long value) { bitfield0_ |= 0x00000002; flowstarttime_ = value; onchanged(); return this; } /** * <code>optional int64 flow_start_time = 2;</code> */ public builder clearflowstarttime() { bitfield0_ = (bitfield0_ & ~0x00000002); flowstarttime_ = 0l; onchanged(); return this; } private long date_ ; /** * <code>optional int64 date = 3;</code> */ public boolean hasdate() { return ((bitfield0_ & 0x00000004) == 0x00000004); } /** * <code>optional int64 date = 3;</code> */ public long getdate() { return date_; } /** * <code>optional int64 date = 3;</code> */ public builder setdate(long value) { bitfield0_ |= 0x00000004; date_ = value; onchanged(); return this; } /** * <code>optional int64 date = 3;</code> */ public builder cleardate() { bitfield0_ = (bitfield0_ & ~0x00000004); date_ = 0l; onchanged(); return this; } private long servertotalpacket_ ; /** * <code>optional int64 server_total_packet = 4;</code> */ public boolean hasservertotalpacket() { return ((bitfield0_ & 0x00000008) == 0x00000008); } /** * <code>optional int64 server_total_packet = 4;</code> */ public long getservertotalpacket() { return servertotalpacket_; } /** * <code>optional int64 server_total_packet = 4;</code> */ public builder setservertotalpacket(long value) { bitfield0_ |= 0x00000008; servertotalpacket_ = value; onchanged(); return this; } /** * <code>optional int64 server_total_packet = 4;</code> */ public builder clearservertotalpacket() { bitfield0_ = (bitfield0_ & ~0x00000008); servertotalpacket_ = 0l; onchanged(); return this; } private long clienttotalbyte_ ; /** * <code>optional int64 client_total_byte = 5;</code> */ public boolean hasclienttotalbyte() { return ((bitfield0_ & 0x00000010) == 0x00000010); } /** * <code>optional int64 client_total_byte = 5;</code> */ public long getclienttotalbyte() { return clienttotalbyte_; } /** * <code>optional int64 client_total_byte = 5;</code> */ public builder setclienttotalbyte(long value) { bitfield0_ |= 0x00000010; clienttotalbyte_ = value; onchanged(); return this; } /** * <code>optional int64 client_total_byte = 5;</code> */ public builder clearclienttotalbyte() { bitfield0_ = (bitfield0_ & ~0x00000010); clienttotalbyte_ = 0l; onchanged(); return this; } private int linkid_ ; /** * <code>optional int32 link_id = 6;</code> */ public boolean haslinkid() { return ((bitfield0_ & 0x00000020) == 0x00000020); } /** * <code>optional int32 link_id = 6;</code> */ public int getlinkid() { return linkid_; } /** * <code>optional int32 link_id = 6;</code> */ public builder setlinkid(int value) { bitfield0_ |= 0x00000020; linkid_ = value; onchanged(); return this; } /** * <code>optional int32 link_id = 6;</code> */ public builder clearlinkid() { bitfield0_ = (bitfield0_ & ~0x00000020); linkid_ = 0; onchanged(); return this; } private long totalbyte_ ; /** * <code>optional int64 total_byte = 7;</code> */ public boolean hastotalbyte() { return ((bitfield0_ & 0x00000040) == 0x00000040); } /** * <code>optional int64 total_byte = 7;</code> */ public long gettotalbyte() { return totalbyte_; } /** * <code>optional int64 total_byte = 7;</code> */ public builder settotalbyte(long value) { bitfield0_ |= 0x00000040; totalbyte_ = value; onchanged(); return this; } /** * <code>optional int64 total_byte = 7;</code> */ public builder cleartotalbyte() { bitfield0_ = (bitfield0_ & ~0x00000040); totalbyte_ = 0l; onchanged(); return this; } private long flowendtime_ ; /** * <code>optional int64 flow_end_time = 8;</code> */ public boolean hasflowendtime() { return ((bitfield0_ & 0x00000080) == 0x00000080); } /** * <code>optional int64 flow_end_time = 8;</code> */ public long getflowendtime() { return flowendtime_; } /** * <code>optional int64 flow_end_time = 8;</code> */ public builder setflowendtime(long value) { bitfield0_ |= 0x00000080; flowendtime_ = value; onchanged(); return this; } /** * <code>optional int64 flow_end_time = 8;</code> */ public builder clearflowendtime() { bitfield0_ = (bitfield0_ & ~0x00000080); flowendtime_ = 0l; onchanged(); return this; } private int clientport_ ; /** * <code>optional int32 client_port = 9;</code> */ public boolean hasclientport() { return ((bitfield0_ & 0x00000100) == 0x00000100); } /** * <code>optional int32 client_port = 9;</code> */ public int getclientport() { return clientport_; } /** * <code>optional int32 client_port = 9;</code> */ public builder setclientport(int value) { bitfield0_ |= 0x00000100; clientport_ = value; onchanged(); return this; } /** * <code>optional int32 client_port = 9;</code> */ public builder clearclientport() { bitfield0_ = (bitfield0_ & ~0x00000100); clientport_ = 0; onchanged(); return this; } private int protocol_ ; /** * <code>optional int32 protocol = 10;</code> */ public boolean hasprotocol() { return ((bitfield0_ & 0x00000200) == 0x00000200); } /** * <code>optional int32 protocol = 10;</code> */ public int getprotocol() { return protocol_; } /** * <code>optional int32 protocol = 10;</code> */ public builder setprotocol(int value) { bitfield0_ |= 0x00000200; protocol_ = value; onchanged(); return this; } /** * <code>optional int32 protocol = 10;</code> */ public builder clearprotocol() { bitfield0_ = (bitfield0_ & ~0x00000200); protocol_ = 0; onchanged(); return this; } private long totalpacket_ ; /** * <code>optional int64 total_packet = 11;</code> */ public boolean hastotalpacket() { return ((bitfield0_ & 0x00000400) == 0x00000400); } /** * <code>optional int64 total_packet = 11;</code> */ public long gettotalpacket() { return totalpacket_; } /** * <code>optional int64 total_packet = 11;</code> */ public builder settotalpacket(long value) { bitfield0_ |= 0x00000400; totalpacket_ = value; onchanged(); return this; } /** * <code>optional int64 total_packet = 11;</code> */ public builder cleartotalpacket() { bitfield0_ = (bitfield0_ & ~0x00000400); totalpacket_ = 0l; onchanged(); return this; } private long flowduration_ ; /** * <code>optional int64 flow_duration = 12;</code> */ public boolean hasflowduration() { return ((bitfield0_ & 0x00000800) == 0x00000800); } /** * <code>optional int64 flow_duration = 12;</code> */ public long getflowduration() { return flowduration_; } /** * <code>optional int64 flow_duration = 12;</code> */ public builder setflowduration(long value) { bitfield0_ |= 0x00000800; flowduration_ = value; onchanged(); return this; } /** * <code>optional int64 flow_duration = 12;</code> */ public builder clearflowduration() { bitfield0_ = (bitfield0_ & ~0x00000800); flowduration_ = 0l; onchanged(); return this; } private java.lang.object id_ = ""; /** * <code>optional string id = 13;</code> */ public boolean hasid() { return ((bitfield0_ & 0x00001000) == 0x00001000); } /** * <code>optional string id = 13;</code> */ public java.lang.string getid() { java.lang.object ref = id_; if (!(ref instanceof java.lang.string)) { com.google.protobuf.bytestring bs = (com.google.protobuf.bytestring) ref; java.lang.string s = bs.tostringutf8(); if (bs.isvalidutf8()) { id_ = s; } return s; } else { return (java.lang.string) ref; } } /** * <code>optional string id = 13;</code> */ public com.google.protobuf.bytestring getidbytes() { java.lang.object ref = id_; if (ref instanceof string) { com.google.protobuf.bytestring b = com.google.protobuf.bytestring.copyfromutf8( (java.lang.string) ref); id_ = b; return b; } else { return (com.google.protobuf.bytestring) ref; } } /** * <code>optional string id = 13;</code> */ public builder setid( java.lang.string value) { if (value == null) { throw new nullpointerexception(); } bitfield0_ |= 0x00001000; id_ = value; onchanged(); return this; } /** * <code>optional string id = 13;</code> */ public builder clearid() { bitfield0_ = (bitfield0_ & ~0x00001000); id_ = getdefaultinstance().getid(); onchanged(); return this; } /** * <code>optional string id = 13;</code> */ public builder setidbytes( com.google.protobuf.bytestring value) { if (value == null) { throw new nullpointerexception(); } bitfield0_ |= 0x00001000; id_ = value; onchanged(); return this; } private java.lang.object serveripaddr_ = ""; /** * <code>optional string server_ip_addr = 14;</code> */ public boolean hasserveripaddr() { return ((bitfield0_ & 0x00002000) == 0x00002000); } /** * <code>optional string server_ip_addr = 14;</code> */ public java.lang.string getserveripaddr() { java.lang.object ref = serveripaddr_; if (!(ref instanceof java.lang.string)) { com.google.protobuf.bytestring bs = (com.google.protobuf.bytestring) ref; java.lang.string s = bs.tostringutf8(); if (bs.isvalidutf8()) { serveripaddr_ = s; } return s; } else { return (java.lang.string) ref; } } /** * <code>optional string server_ip_addr = 14;</code> */ public com.google.protobuf.bytestring getserveripaddrbytes() { java.lang.object ref = serveripaddr_; if (ref instanceof string) { com.google.protobuf.bytestring b = com.google.protobuf.bytestring.copyfromutf8( (java.lang.string) ref); serveripaddr_ = b; return b; } else { return (com.google.protobuf.bytestring) ref; } } /** * <code>optional string server_ip_addr = 14;</code> */ public builder setserveripaddr( java.lang.string value) { if (value == null) { throw new nullpointerexception(); } bitfield0_ |= 0x00002000; serveripaddr_ = value; onchanged(); return this; } /** * <code>optional string server_ip_addr = 14;</code> */ public builder clearserveripaddr() { bitfield0_ = (bitfield0_ & ~0x00002000); serveripaddr_ = getdefaultinstance().getserveripaddr(); onchanged(); return this; } /** * <code>optional string server_ip_addr = 14;</code> */ public builder setserveripaddrbytes( com.google.protobuf.bytestring value) { if (value == null) { throw new nullpointerexception(); } bitfield0_ |= 0x00002000; serveripaddr_ = value; onchanged(); return this; } private java.lang.object directionmask_ = ""; /** * <code>optional string direction_mask = 15;</code> */ public boolean hasdirectionmask() { return ((bitfield0_ & 0x00004000) == 0x00004000); } /** * <code>optional string direction_mask = 15;</code> */ public java.lang.string getdirectionmask() { java.lang.object ref = directionmask_; if (!(ref instanceof java.lang.string)) { com.google.protobuf.bytestring bs = (com.google.protobuf.bytestring) ref; java.lang.string s = bs.tostringutf8(); if (bs.isvalidutf8()) { directionmask_ = s; } return s; } else { return (java.lang.string) ref; } } /** * <code>optional string direction_mask = 15;</code> */ public com.google.protobuf.bytestring getdirectionmaskbytes() { java.lang.object ref = directionmask_; if (ref instanceof string) { com.google.protobuf.bytestring b = com.google.protobuf.bytestring.copyfromutf8( (java.lang.string) ref); directionmask_ = b; return b; } else { return (com.google.protobuf.bytestring) ref; } } /** * <code>optional string direction_mask = 15;</code> */ public builder setdirectionmask( java.lang.string value) { if (value == null) { throw new nullpointerexception(); } bitfield0_ |= 0x00004000; directionmask_ = value; onchanged(); return this; } /** * <code>optional string direction_mask = 15;</code> */ public builder cleardirectionmask() { bitfield0_ = (bitfield0_ & ~0x00004000); directionmask_ = getdefaultinstance().getdirectionmask(); onchanged(); return this; } /** * <code>optional string direction_mask = 15;</code> */ public builder setdirectionmaskbytes( com.google.protobuf.bytestring value) { if (value == null) { throw new nullpointerexception(); } bitfield0_ |= 0x00004000; directionmask_ = value; onchanged(); return this; } private int app_ ; /** * <code>optional int32 app = 16;</code> */ public boolean hasapp() { return ((bitfield0_ & 0x00008000) == 0x00008000); } /** * <code>optional int32 app = 16;</code> */ public int getapp() { return app_; } /** * <code>optional int32 app = 16;</code> */ public builder setapp(int value) { bitfield0_ |= 0x00008000; app_ = value; onchanged(); return this; } /** * <code>optional int32 app = 16;</code> */ public builder clearapp() { bitfield0_ = (bitfield0_ & ~0x00008000); app_ = 0; onchanged(); return this; } private int clientcountryid_ ; /** * <code>optional int32 client_country_id = 17;</code> */ public boolean hasclientcountryid() { return ((bitfield0_ & 0x00010000) == 0x00010000); } /** * <code>optional int32 client_country_id = 17;</code> */ public int getclientcountryid() { return clientcountryid_; } /** * <code>optional int32 client_country_id = 17;</code> */ public builder setclientcountryid(int value) { bitfield0_ |= 0x00010000; clientcountryid_ = value; onchanged(); return this; } /** * <code>optional int32 client_country_id = 17;</code> */ public builder clearclientcountryid() { bitfield0_ = (bitfield0_ & ~0x00010000); clientcountryid_ = 0; onchanged(); return this; } private int clientnetsegmentid_ ; /** * <code>optional int32 client_netsegment_id = 18;</code> */ public boolean hasclientnetsegmentid() { return ((bitfield0_ & 0x00020000) == 0x00020000); } /** * <code>optional int32 client_netsegment_id = 18;</code> */ public int getclientnetsegmentid() { return clientnetsegmentid_; } /** * <code>optional int32 client_netsegment_id = 18;</code> */ public builder setclientnetsegmentid(int value) { bitfield0_ |= 0x00020000; clientnetsegmentid_ = value; onchanged(); return this; } /** * <code>optional int32 client_netsegment_id = 18;</code> */ public builder clearclientnetsegmentid() { bitfield0_ = (bitfield0_ & ~0x00020000); clientnetsegmentid_ = 0; onchanged(); return this; } private long clienttotalpacket_ ; /** * <code>optional int64 client_total_packet = 19;</code> */ public boolean hasclienttotalpacket() { return ((bitfield0_ & 0x00040000) == 0x00040000); } /** * <code>optional int64 client_total_packet = 19;</code> */ public long getclienttotalpacket() { return clienttotalpacket_; } /** * <code>optional int64 client_total_packet = 19;</code> */ public builder setclienttotalpacket(long value) { bitfield0_ |= 0x00040000; clienttotalpacket_ = value; onchanged(); return this; } /** * <code>optional int64 client_total_packet = 19;</code> */ public builder clearclienttotalpacket() { bitfield0_ = (bitfield0_ & ~0x00040000); clienttotalpacket_ = 0l; onchanged(); return this; } private java.lang.object clientipaddr_ = ""; /** * <code>optional string client_ip_addr = 20;</code> */ public boolean hasclientipaddr() { return ((bitfield0_ & 0x00080000) == 0x00080000); } /** * <code>optional string client_ip_addr = 20;</code> */ public java.lang.string getclientipaddr() { java.lang.object ref = clientipaddr_; if (!(ref instanceof java.lang.string)) { com.google.protobuf.bytestring bs = (com.google.protobuf.bytestring) ref; java.lang.string s = bs.tostringutf8(); if (bs.isvalidutf8()) { clientipaddr_ = s; } return s; } else { return (java.lang.string) ref; } } /** * <code>optional string client_ip_addr = 20;</code> */ public com.google.protobuf.bytestring getclientipaddrbytes() { java.lang.object ref = clientipaddr_; if (ref instanceof string) { com.google.protobuf.bytestring b = com.google.protobuf.bytestring.copyfromutf8( (java.lang.string) ref); clientipaddr_ = b; return b; } else { return (com.google.protobuf.bytestring) ref; } } /** * <code>optional string client_ip_addr = 20;</code> */ public builder setclientipaddr( java.lang.string value) { if (value == null) { throw new nullpointerexception(); } bitfield0_ |= 0x00080000; clientipaddr_ = value; onchanged(); return this; } /** * <code>optional string client_ip_addr = 20;</code> */ public builder clearclientipaddr() { bitfield0_ = (bitfield0_ & ~0x00080000); clientipaddr_ = getdefaultinstance().getclientipaddr(); onchanged(); return this; } /** * <code>optional string client_ip_addr = 20;</code> */ public builder setclientipaddrbytes( com.google.protobuf.bytestring value) { if (value == null) { throw new nullpointerexception(); } bitfield0_ |= 0x00080000; clientipaddr_ = value; onchanged(); return this; } private int tcpstatus_ ; /** * <code>optional int32 tcp_status = 21;</code> */ public boolean hastcpstatus() { return ((bitfield0_ & 0x00100000) == 0x00100000); } /** * <code>optional int32 tcp_status = 21;</code> */ public int gettcpstatus() { return tcpstatus_; } /** * <code>optional int32 tcp_status = 21;</code> */ public builder settcpstatus(int value) { bitfield0_ |= 0x00100000; tcpstatus_ = value; onchanged(); return this; } /** * <code>optional int32 tcp_status = 21;</code> */ public builder cleartcpstatus() { bitfield0_ = (bitfield0_ & ~0x00100000); tcpstatus_ = 0; onchanged(); return this; } private int servercountryid_ ; /** * <code>optional int32 server_country_id = 22;</code> */ public boolean hasservercountryid() { return ((bitfield0_ & 0x00200000) == 0x00200000); } /** * <code>optional int32 server_country_id = 22;</code> */ public int getservercountryid() { return servercountryid_; } /** * <code>optional int32 server_country_id = 22;</code> */ public builder setservercountryid(int value) { bitfield0_ |= 0x00200000; servercountryid_ = value; onchanged(); return this; } /** * <code>optional int32 server_country_id = 22;</code> */ public builder clearservercountryid() { bitfield0_ = (bitfield0_ & ~0x00200000); servercountryid_ = 0; onchanged(); return this; } private int servernetsegmentid_ ; /** * <code>optional int32 server_netsegment_id = 23;</code> */ public boolean hasservernetsegmentid() { return ((bitfield0_ & 0x00400000) == 0x00400000); } /** * <code>optional int32 server_netsegment_id = 23;</code> */ public int getservernetsegmentid() { return servernetsegmentid_; } /** * <code>optional int32 server_netsegment_id = 23;</code> */ public builder setservernetsegmentid(int value) { bitfield0_ |= 0x00400000; servernetsegmentid_ = value; onchanged(); return this; } /** * <code>optional int32 server_netsegment_id = 23;</code> */ public builder clearservernetsegmentid() { bitfield0_ = (bitfield0_ & ~0x00400000); servernetsegmentid_ = 0; onchanged(); return this; } private long avgpktsize_ ; /** * <code>optional int64 avg_pkt_size = 24;</code> */ public boolean hasavgpktsize() { return ((bitfield0_ & 0x00800000) == 0x00800000); } /** * <code>optional int64 avg_pkt_size = 24;</code> */ public long getavgpktsize() { return avgpktsize_; } /** * <code>optional int64 avg_pkt_size = 24;</code> */ public builder setavgpktsize(long value) { bitfield0_ |= 0x00800000; avgpktsize_ = value; onchanged(); return this; } /** * <code>optional int64 avg_pkt_size = 24;</code> */ public builder clearavgpktsize() { bitfield0_ = (bitfield0_ & ~0x00800000); avgpktsize_ = 0l; onchanged(); return this; } private int serverport_ ; /** * <code>optional int32 server_port = 25;</code> */ public boolean hasserverport() { return ((bitfield0_ & 0x01000000) == 0x01000000); } /** * <code>optional int32 server_port = 25;</code> */ public int getserverport() { return serverport_; } /** * <code>optional int32 server_port = 25;</code> */ public builder setserverport(int value) { bitfield0_ |= 0x01000000; serverport_ = value; onchanged(); return this; } /** * <code>optional int32 server_port = 25;</code> */ public builder clearserverport() { bitfield0_ = (bitfield0_ & ~0x01000000); serverport_ = 0; onchanged(); return this; } private long servertotalbyte_ ; /** * <code>optional int64 server_total_byte = 26;</code> */ public boolean hasservertotalbyte() { return ((bitfield0_ & 0x02000000) == 0x02000000); } /** * <code>optional int64 server_total_byte = 26;</code> */ public long getservertotalbyte() { return servertotalbyte_; } /** * <code>optional int64 server_total_byte = 26;</code> */ public builder setservertotalbyte(long value) { bitfield0_ |= 0x02000000; servertotalbyte_ = value; onchanged(); return this; } /** * <code>optional int64 server_total_byte = 26;</code> */ public builder clearservertotalbyte() { bitfield0_ = (bitfield0_ & ~0x02000000); servertotalbyte_ = 0l; onchanged(); return this; } private int totalpacketps_ ; /** * <code>optional int32 total_packetps = 27;</code> */ public boolean hastotalpacketps() { return ((bitfield0_ & 0x04000000) == 0x04000000); } /** * <code>optional int32 total_packetps = 27;</code> */ public int gettotalpacketps() { return totalpacketps_; } /** * <code>optional int32 total_packetps = 27;</code> */ public builder settotalpacketps(int value) { bitfield0_ |= 0x04000000; totalpacketps_ = value; onchanged(); return this; } /** * <code>optional int32 total_packetps = 27;</code> */ public builder cleartotalpacketps() { bitfield0_ = (bitfield0_ & ~0x04000000); totalpacketps_ = 0; onchanged(); return this; } public final builder setunknownfields( final com.google.protobuf.unknownfieldset unknownfields) { return super.setunknownfields(unknownfields); } public final builder mergeunknownfields( final com.google.protobuf.unknownfieldset unknownfields) { return super.mergeunknownfields(unknownfields); } // @@protoc_insertion_point(builder_scope:tcplog) } // @@protoc_insertion_point(class_scope:tcplog) private static final tcplogouterclass.tcplog default_instance; static { default_instance = new tcplogouterclass.tcplog(); } public static tcplogouterclass.tcplog getdefaultinstance() { return default_instance; } @java.lang.deprecated public static final com.google.protobuf.parser<tcplog> parser = new com.google.protobuf.abstractparser<tcplog>() { public tcplog parsepartialfrom( com.google.protobuf.codedinputstream input, com.google.protobuf.extensionregistrylite extensionregistry) throws com.google.protobuf.invalidprotocolbufferexception { return new tcplog(input, extensionregistry); } }; public static com.google.protobuf.parser<tcplog> parser() { return parser; } @java.lang.override public com.google.protobuf.parser<tcplog> getparserfortype() { return parser; } public tcplogouterclass.tcplog getdefaultinstancefortype() { return default_instance; } } private static final com.google.protobuf.descriptors.descriptor internal_static_tcplog_descriptor; private static final com.google.protobuf.generatedmessagev3.fieldaccessortable internal_static_tcplog_fieldaccessortable; public static com.google.protobuf.descriptors.filedescriptor getdescriptor() { return descriptor; } private static com.google.protobuf.descriptors.filedescriptor descriptor; static { java.lang.string[] descriptordata = { "\n\014tcplog.proto\"\357\004\n\006tcplog\022\024\n\014total_bytep" + "s\030\001 \001(\005\022\027\n\017flow_start_time\030\002 \001(\003\022\014\n\004date" + "\030\003 \001(\003\022\033\n\023server_total_packet\030\004 \001(\003\022\031\n\021c" + "lient_total_byte\030\005 \001(\003\022\017\n\007link_id\030\006 \001(\005\022" + "\022\n\ntotal_byte\030\007 \001(\003\022\025\n\rflow_end_time\030\010 \001" + "(\003\022\023\n\013client_port\030\t \001(\005\022\020\n\010protocol\030\n \001(" + "\005\022\024\n\014total_packet\030\013 \001(\003\022\025\n\rflow_duration" + "\030\014 \001(\003\022\n\n\002id\030\r \001(\t\022\026\n\016server_ip_addr\030\016 \001" + "(\t\022\026\n\016direction_mask\030\017 \001(\t\022\013\n\003app\030\020 \001(\005\022" + "\031\n\021client_country_id\030\021 \001(\005\022\034\n\024client_net", "segment_id\030\022 \001(\005\022\033\n\023client_total_packet\030" + "\023 \001(\003\022\026\n\016client_ip_addr\030\024 \001(\t\022\022\n\ntcp_sta" + "tus\030\025 \001(\005\022\031\n\021server_country_id\030\026 \001(\005\022\034\n\024" + "server_netsegment_id\030\027 \001(\005\022\024\n\014avg_pkt_si" + "ze\030\030 \001(\003\022\023\n\013server_port\030\031 \001(\005\022\031\n\021server_" + "total_byte\030\032 \001(\003\022\026\n\016total_packetps\030\033 \001(\005" }; com.google.protobuf.descriptors.filedescriptor.internaldescriptorassigner assigner = new com.google.protobuf.descriptors.filedescriptor. internaldescriptorassigner() { public com.google.protobuf.extensionregistry assigndescriptors( com.google.protobuf.descriptors.filedescriptor root) { descriptor = root; return null; } }; com.google.protobuf.descriptors.filedescriptor .internalbuildgeneratedfilefrom(descriptordata, new com.google.protobuf.descriptors.filedescriptor[] { }, assigner); internal_static_tcplog_descriptor = getdescriptor().getmessagetypes().get(0); internal_static_tcplog_fieldaccessortable = new com.google.protobuf.generatedmessagev3.fieldaccessortable( internal_static_tcplog_descriptor, new java.lang.string[] { "totalbyteps", "flowstarttime", "date", "servertotalpacket", "clienttotalbyte", "linkid", "totalbyte", "flowendtime", "clientport", "protocol", "totalpacket", "flowduration", "id", "serveripaddr", "directionmask", "app", "clientcountryid", "clientnetsegmentid", "clienttotalpacket", "clientipaddr", "tcpstatus", "servercountryid", "servernetsegmentid", "avgpktsize", "serverport", "servertotalbyte", "totalpacketps", }); } // @@protoc_insertion_point(outer_class_scope) }
之后便可以使用该类进行序列化和反序列化。
具体示例代码如下》:
import java.io.file; import java.io.fileoutputstream; public class prototest3 { /** * @param args * @throws exception * @author qiang(upupgo) */ public static void main(string[] args) throws exception { //模拟将对象转成byte[],方便传输 tcplogouterclass.tcplog.builder builder = tcplogouterclass.tcplog.newbuilder(); builder.settotalbyteps(1024); builder.setflowstarttime(1502415717l); builder.setdate(1502415717l); //序列化到文件 tcplogouterclass.tcplog tcplog= builder.build(); fileoutputstream out = new fileoutputstream(new file("d:/pb")); out.write(tcplog.tobytearray()); out.close(); //反序列化 tcplogouterclass.tcplog tcp = tcplogouterclass.tcplog.parsefrom(tcplog.tobytearray()); system.out.println(tcp); } }
二、avro序列化基本操作:
avro简介:
apache avro™ is a data serialization system. avro provides: rich data structures. a compact, fast, binary data format. a container file, to store persistent data. remote procedure call (rpc). simple integration with dynamic languages. code generation is not required to read or write data files nor to use or implement rpc protocols. code generation as an optional optimization, only worth implementing for statically typed languages.
avro是一个序列化系统。丰富的数据结构、快速压缩的二进制数据格式、数据持久化存储、rpc及动态语言集成。
2.1定义协议文件(tcplog.avro)
{"namespace": "example.avro", "type": "record", "name": "tcplog", "fields": [ {"name": "total_byteps", "type": "int"}, {"name": "flow_start_time", "type": "long"}, {"name": "date", "type": "long"} ] }
avro和protobuf一样可以生成相应语言的类文件,或直接支持动态扩张。下面以java语言不生成类说明:
具体序列化与反序列化操作代码如下:、
package avro; import java.io.file; import org.apache.avro.schema; import org.apache.avro.file.datafilereader; import org.apache.avro.file.datafilewriter; import org.apache.avro.generic.genericdata; import org.apache.avro.generic.genericdatumreader; import org.apache.avro.generic.genericdatumwriter; import org.apache.avro.generic.genericrecord; import org.apache.avro.io.datumreader; import org.apache.avro.io.datumwriter; /** * @date 2017年8月13日22:15:32 * @author qiang(upupgo) * */ public class avrotest2 { public static void main(string[] args) throws exception { string filepath = "d:/tcplog.avsc"; schema schema = new schema.parser().parse(new file(filepath)); genericrecord tcplog = new genericdata.record(schema); tcplog.put("total_byteps", 1024); tcplog.put("flow_start_time", 1502415717l); tcplog.put("date", 1502415717l); system.out.println(tcplog); // serialize user1 and tcplog to disk file file = new file("d:/avro"); datumwriter<genericrecord> datumwriter = new genericdatumwriter<genericrecord>(schema); datafilewriter<genericrecord> datafilewriter = new datafilewriter<genericrecord>(datumwriter); datafilewriter.create(schema, file); long timestart = system.currenttimemillis(); datafilewriter.append(tcplog); datafilewriter.close(); long timeend = system.currenttimemillis(); system.out.println(timeend-timestart); // deserialize users from disk datumreader<genericrecord> datumreader = new genericdatumreader<genericrecord>(schema); datafilereader<genericrecord> datafilereader = new datafilereader<>(new file("d:/avro"), datumreader); genericrecord tcplogs = null; long timestart1 = system.currenttimemillis(); while (datafilereader.hasnext()) { // reuse user object by passing it to next(). this saves us from // allocating and garbage collecting many objects for files with // many items. tcplogs = datafilereader.next(); // system.out.println("xx"+tcplogs); } long timeend1 = system.currenttimemillis(); system.out.println("deserialize"+(timeend1-timestart1)); } }
以下是通过对100w tcplog序列化操作对比结论:
通过对比测试发现 avro的性能要不pb稍微好一些,且支持动态性。故技术选型上可以优先考虑。
以上是通过测试对比了pb与avro的一些性能差异,但是具体测试和机器和样本都有关系,可以参考。
以下是对比protobuf、avro、thrift的一些优缺点:
google protobuf: 优点 二进制消息,性能好/效率高(空间和时间效率都很不错) proto文件生成目标代码,简单易用 序列化反序列化直接对应程序中的数据类,不需要解析后在进行映射(xml,json都是这种方式) 支持向前兼容(新加字段采用默认值)和向后兼容(忽略新加字段),简化升级 支持多种语言(可以把proto文件看做idl文件) netty等一些框架集成 缺点 官方只支持c++,java和python语言绑定 二进制可读性差(貌似提供了text_fromat功能) 二进制不具有自描述特性 默认不具备动态特性(可以通过动态定义生成消息类型或者动态编译支持) 只涉及序列化和反序列化技术,不涉及rpc功能(类似xml或者json的解析器) apache thrift: 应用 facebook的开源的日志收集系统(scribe: https://github.com/facebook/scribe) 淘宝的实时数据传输平台(timetunnel http://code.taobao.org/p/timetunnel/wiki/index) evernote开放接口(https://github.com/evernote/evernote-thrift) quora(http://www.quora.com/apache-thrift) hbase( http://abloz.com/hbase/book.html#thrift ) … 优点 支持非常多的语言绑定 thrift文件生成目标代码,简单易用 消息定义文件支持注释 数据结构与传输表现的分离,支持多种消息格式 包含完整的客户端/服务端堆栈,可快速实现rpc 支持同步和异步通信 缺点 和protobuf一样不支持动态特性 apache avro: 应用 hadoop rpc (http://hadoop.apache.org/#what+is+apache+hadoop%3f) 优点 二进制消息,性能好/效率高 使用json描述模式 模式和数据统一存储,消息自描述,不需要生成stub代码(支持生成idl) rpc调用在握手阶段交换模式定义 包含完整的客户端/服务端堆栈,可快速实现rpc 支持同步和异步通信 支持动态消息 模式定义允许定义数据的排序(序列化时会遵循这个顺序) 提供了基于jetty内核的服务基于netty的服务 缺点 只支持avro自己的序列化格式 语言绑定不如thrift丰富
如有错误欢迎指正,如果对您有帮助也欢迎打赏 点赞 推荐 谢谢!^^
以上这篇浅谈序列化之protobuf与avro对比(java)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。