Java 使用 Protobuf
示例
1、编写 gps_data.proto 描述文件
syntax = "proto3";
option java_package = "com.twx.learn.protobuf.proto";
option java_outer_classname = "GpsDataProto";
message gps_data {
int64 id = 1;
string terminalId = 2;
string dataTime = 3;
double lon = 4;
double lat = 5;
float speed = 6;
int32 altitude = 7;
int32 locType = 8;
int32 gpsStatus = 9;
float direction = 10;
int32 satellite = 11;
}
- java_outer_classname 最后输出的Java类名
- java_package 声明java包
Int64 int32 string`这些proto类型与Java类型的对应关系,参考附注。
2、mac 安装protobuf
brew install protobuf
3、使用protoc
编译proto,转成java代码
protoc -I=src/main/resources/proto —java_out=src/main/java gps_data.proto
- -I 后面是 proto 文件所在目录
- —java_out 后面是 java 文件存放地址
- 最后一行是 proto 文件名称
执行命令后,结构图如下:
4、接下来,我们使用生成的GpsDataProto
来序列化和反序列化,引入依赖:
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.12.1</version>
</dependency>
5、编写测试类:
package com.twx.learn.protobuf;
import com.google.protobuf.InvalidProtocolBufferException;
import com.twx.learn.protobuf.proto.GpsDataProto;
/**
* @author tangwx@soyuan.com.cn
* @date 2020/5/29 10:35
*/
public class App {
public static void main(String[] args) {
System.out.println("===== 构建一个GPS模型开始 =====");
GpsDataProto.gps_data.Builder gps_builder = GpsDataProto.gps_data.newBuilder();
gps_builder.setAltitude(1);
gps_builder.setDataTime("2017-12-17 16:21:44");
gps_builder.setGpsStatus(1);
gps_builder.setLat(39.123);
gps_builder.setLon(120.112);
gps_builder.setDirection(30.2F);
gps_builder.setId(100L);
GpsDataProto.gps_data gps_data = gps_builder.build();
System.out.println(gps_data.toString());
System.out.println("===== 构建GPS模型结束 =====");
System.out.println("===== gps Byte 开始=====");
for (byte b : gps_data.toByteArray()) {
System.out.print(b);
}
System.out.println("\n" + "bytes长度" + gps_data.toByteString().size());
System.out.println("===== gps Byte 结束 =====");
System.out.println("===== 使用gps 反序列化生成对象开始 =====");
GpsDataProto.gps_data gd = null;
try {
gd = GpsDataProto.gps_data.parseFrom(gps_data.toByteArray());
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
System.out.print(gd.toString());
System.out.println("===== 使用gps 反序列化生成对象结束 =====");
}
}
输出结果:
===== 构建一个GPS模型开始 =====
id: 100
dataTime: "2017-12-17 16:21:44"
lon: 120.112
lat: 39.123
altitude: 1
gpsStatus: 1
direction: 30.2
===== 构建GPS模型结束 =====
===== gps Byte 开始=====
810026195048495545495045495532495458504958525233-707312243794644157-76-56118-66-113676456172185-102-103-1565
bytes长度50
===== gps Byte 结束 =====
===== 使用gps 反序列化生成对象开始 =====
id: 100
dataTime: "2017-12-17 16:21:44"
lon: 120.112
lat: 39.123
altitude: 1
gpsStatus: 1
direction: 30.2
===== 使用gps 反序列化生成对象结束 =====
附注
proto类型—>java类型
GpsDataProto
因为生成的GpsDataProto有点长,所以在最后贴出
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: gps_data.proto
package com.twx.learn.protobuf.proto;
public final class GpsDataProto {
private GpsDataProto() {}
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 gps_dataOrBuilder extends
// @@protoc_insertion_point(interface_extends:gps_data)
com.google.protobuf.MessageOrBuilder {
/**
* <code>int64 id = 1;</code>
* @return The id.
*/
long getId();
/**
* <code>string terminalId = 2;</code>
* @return The terminalId.
*/
java.lang.String getTerminalId();
/**
* <code>string terminalId = 2;</code>
* @return The bytes for terminalId.
*/
com.google.protobuf.ByteString
getTerminalIdBytes();
/**
* <code>string dataTime = 3;</code>
* @return The dataTime.
*/
java.lang.String getDataTime();
/**
* <code>string dataTime = 3;</code>
* @return The bytes for dataTime.
*/
com.google.protobuf.ByteString
getDataTimeBytes();
/**
* <code>double lon = 4;</code>
* @return The lon.
*/
double getLon();
/**
* <code>double lat = 5;</code>
* @return The lat.
*/
double getLat();
/**
* <code>float speed = 6;</code>
* @return The speed.
*/
float getSpeed();
/**
* <code>int32 altitude = 7;</code>
* @return The altitude.
*/
int getAltitude();
/**
* <code>int32 locType = 8;</code>
* @return The locType.
*/
int getLocType();
/**
* <code>int32 gpsStatus = 9;</code>
* @return The gpsStatus.
*/
int getGpsStatus();
/**
* <code>float direction = 10;</code>
* @return The direction.
*/
float getDirection();
/**
* <code>int32 satellite = 11;</code>
* @return The satellite.
*/
int getSatellite();
}
/**
* Protobuf type {@code gps_data}
*/
public static final class gps_data extends
com.google.protobuf.GeneratedMessageV3 implements
// @@protoc_insertion_point(message_implements:gps_data)
gps_dataOrBuilder {
private static final long serialVersionUID = 0L;
// Use gps_data.newBuilder() to construct.
private gps_data(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
super(builder);
}
private gps_data() {
terminalId_ = "";
dataTime_ = "";
}
@java.lang.Override
@SuppressWarnings({"unused"})
protected java.lang.Object newInstance(
UnusedPrivateParameter unused) {
return new gps_data();
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return this.unknownFields;
}
private gps_data(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
if (extensionRegistry == null) {
throw new java.lang.NullPointerException();
}
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;
case 8: {
id_ = input.readInt64();
break;
}
case 18: {
java.lang.String s = input.readStringRequireUtf8();
terminalId_ = s;
break;
}
case 26: {
java.lang.String s = input.readStringRequireUtf8();
dataTime_ = s;
break;
}
case 33: {
lon_ = input.readDouble();
break;
}
case 41: {
lat_ = input.readDouble();
break;
}
case 53: {
speed_ = input.readFloat();
break;
}
case 56: {
altitude_ = input.readInt32();
break;
}
case 64: {
locType_ = input.readInt32();
break;
}
case 72: {
gpsStatus_ = input.readInt32();
break;
}
case 85: {
direction_ = input.readFloat();
break;
}
case 88: {
satellite_ = input.readInt32();
break;
}
default: {
if (!parseUnknownField(
input, unknownFields, extensionRegistry, tag)) {
done = true;
}
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 com.twx.learn.protobuf.proto.GpsDataProto.internal_static_gps_data_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.twx.learn.protobuf.proto.GpsDataProto.internal_static_gps_data_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.twx.learn.protobuf.proto.GpsDataProto.gps_data.class, com.twx.learn.protobuf.proto.GpsDataProto.gps_data.Builder.class);
}
public static final int ID_FIELD_NUMBER = 1;
private long id_;
/**
* <code>int64 id = 1;</code>
* @return The id.
*/
public long getId() {
return id_;
}
public static final int TERMINALID_FIELD_NUMBER = 2;
private volatile java.lang.Object terminalId_;
/**
* <code>string terminalId = 2;</code>
* @return The terminalId.
*/
public java.lang.String getTerminalId() {
java.lang.Object ref = terminalId_;
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();
terminalId_ = s;
return s;
}
}
/**
* <code>string terminalId = 2;</code>
* @return The bytes for terminalId.
*/
public com.google.protobuf.ByteString
getTerminalIdBytes() {
java.lang.Object ref = terminalId_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
terminalId_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
public static final int DATATIME_FIELD_NUMBER = 3;
private volatile java.lang.Object dataTime_;
/**
* <code>string dataTime = 3;</code>
* @return The dataTime.
*/
public java.lang.String getDataTime() {
java.lang.Object ref = dataTime_;
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();
dataTime_ = s;
return s;
}
}
/**
* <code>string dataTime = 3;</code>
* @return The bytes for dataTime.
*/
public com.google.protobuf.ByteString
getDataTimeBytes() {
java.lang.Object ref = dataTime_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
dataTime_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
public static final int LON_FIELD_NUMBER = 4;
private double lon_;
/**
* <code>double lon = 4;</code>
* @return The lon.
*/
public double getLon() {
return lon_;
}
public static final int LAT_FIELD_NUMBER = 5;
private double lat_;
/**
* <code>double lat = 5;</code>
* @return The lat.
*/
public double getLat() {
return lat_;
}
public static final int SPEED_FIELD_NUMBER = 6;
private float speed_;
/**
* <code>float speed = 6;</code>
* @return The speed.
*/
public float getSpeed() {
return speed_;
}
public static final int ALTITUDE_FIELD_NUMBER = 7;
private int altitude_;
/**
* <code>int32 altitude = 7;</code>
* @return The altitude.
*/
public int getAltitude() {
return altitude_;
}
public static final int LOCTYPE_FIELD_NUMBER = 8;
private int locType_;
/**
* <code>int32 locType = 8;</code>
* @return The locType.
*/
public int getLocType() {
return locType_;
}
public static final int GPSSTATUS_FIELD_NUMBER = 9;
private int gpsStatus_;
/**
* <code>int32 gpsStatus = 9;</code>
* @return The gpsStatus.
*/
public int getGpsStatus() {
return gpsStatus_;
}
public static final int DIRECTION_FIELD_NUMBER = 10;
private float direction_;
/**
* <code>float direction = 10;</code>
* @return The direction.
*/
public float getDirection() {
return direction_;
}
public static final int SATELLITE_FIELD_NUMBER = 11;
private int satellite_;
/**
* <code>int32 satellite = 11;</code>
* @return The satellite.
*/
public int getSatellite() {
return satellite_;
}
private byte memoizedIsInitialized = -1;
@java.lang.Override
public final boolean isInitialized() {
byte isInitialized = memoizedIsInitialized;
if (isInitialized == 1) return true;
if (isInitialized == 0) return false;
memoizedIsInitialized = 1;
return true;
}
@java.lang.Override
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
if (id_ != 0L) {
output.writeInt64(1, id_);
}
if (!getTerminalIdBytes().isEmpty()) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 2, terminalId_);
}
if (!getDataTimeBytes().isEmpty()) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 3, dataTime_);
}
if (lon_ != 0D) {
output.writeDouble(4, lon_);
}
if (lat_ != 0D) {
output.writeDouble(5, lat_);
}
if (speed_ != 0F) {
output.writeFloat(6, speed_);
}
if (altitude_ != 0) {
output.writeInt32(7, altitude_);
}
if (locType_ != 0) {
output.writeInt32(8, locType_);
}
if (gpsStatus_ != 0) {
output.writeInt32(9, gpsStatus_);
}
if (direction_ != 0F) {
output.writeFloat(10, direction_);
}
if (satellite_ != 0) {
output.writeInt32(11, satellite_);
}
unknownFields.writeTo(output);
}
@java.lang.Override
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (id_ != 0L) {
size += com.google.protobuf.CodedOutputStream
.computeInt64Size(1, id_);
}
if (!getTerminalIdBytes().isEmpty()) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, terminalId_);
}
if (!getDataTimeBytes().isEmpty()) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, dataTime_);
}
if (lon_ != 0D) {
size += com.google.protobuf.CodedOutputStream
.computeDoubleSize(4, lon_);
}
if (lat_ != 0D) {
size += com.google.protobuf.CodedOutputStream
.computeDoubleSize(5, lat_);
}
if (speed_ != 0F) {
size += com.google.protobuf.CodedOutputStream
.computeFloatSize(6, speed_);
}
if (altitude_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(7, altitude_);
}
if (locType_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(8, locType_);
}
if (gpsStatus_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(9, gpsStatus_);
}
if (direction_ != 0F) {
size += com.google.protobuf.CodedOutputStream
.computeFloatSize(10, direction_);
}
if (satellite_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(11, satellite_);
}
size += unknownFields.getSerializedSize();
memoizedSize = size;
return size;
}
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof com.twx.learn.protobuf.proto.GpsDataProto.gps_data)) {
return super.equals(obj);
}
com.twx.learn.protobuf.proto.GpsDataProto.gps_data other = (com.twx.learn.protobuf.proto.GpsDataProto.gps_data) obj;
if (getId()
!= other.getId()) return false;
if (!getTerminalId()
.equals(other.getTerminalId())) return false;
if (!getDataTime()
.equals(other.getDataTime())) return false;
if (java.lang.Double.doubleToLongBits(getLon())
!= java.lang.Double.doubleToLongBits(
other.getLon())) return false;
if (java.lang.Double.doubleToLongBits(getLat())
!= java.lang.Double.doubleToLongBits(
other.getLat())) return false;
if (java.lang.Float.floatToIntBits(getSpeed())
!= java.lang.Float.floatToIntBits(
other.getSpeed())) return false;
if (getAltitude()
!= other.getAltitude()) return false;
if (getLocType()
!= other.getLocType()) return false;
if (getGpsStatus()
!= other.getGpsStatus()) return false;
if (java.lang.Float.floatToIntBits(getDirection())
!= java.lang.Float.floatToIntBits(
other.getDirection())) return false;
if (getSatellite()
!= other.getSatellite()) return false;
if (!unknownFields.equals(other.unknownFields)) return false;
return true;
}
@java.lang.Override
public int hashCode() {
if (memoizedHashCode != 0) {
return memoizedHashCode;
}
int hash = 41;
hash = (19 * hash) + getDescriptor().hashCode();
hash = (37 * hash) + ID_FIELD_NUMBER;
hash = (53 * hash) + com.google.protobuf.Internal.hashLong(
getId());
hash = (37 * hash) + TERMINALID_FIELD_NUMBER;
hash = (53 * hash) + getTerminalId().hashCode();
hash = (37 * hash) + DATATIME_FIELD_NUMBER;
hash = (53 * hash) + getDataTime().hashCode();
hash = (37 * hash) + LON_FIELD_NUMBER;
hash = (53 * hash) + com.google.protobuf.Internal.hashLong(
java.lang.Double.doubleToLongBits(getLon()));
hash = (37 * hash) + LAT_FIELD_NUMBER;
hash = (53 * hash) + com.google.protobuf.Internal.hashLong(
java.lang.Double.doubleToLongBits(getLat()));
hash = (37 * hash) + SPEED_FIELD_NUMBER;
hash = (53 * hash) + java.lang.Float.floatToIntBits(
getSpeed());
hash = (37 * hash) + ALTITUDE_FIELD_NUMBER;
hash = (53 * hash) + getAltitude();
hash = (37 * hash) + LOCTYPE_FIELD_NUMBER;
hash = (53 * hash) + getLocType();
hash = (37 * hash) + GPSSTATUS_FIELD_NUMBER;
hash = (53 * hash) + getGpsStatus();
hash = (37 * hash) + DIRECTION_FIELD_NUMBER;
hash = (53 * hash) + java.lang.Float.floatToIntBits(
getDirection());
hash = (37 * hash) + SATELLITE_FIELD_NUMBER;
hash = (53 * hash) + getSatellite();
hash = (29 * hash) + unknownFields.hashCode();
memoizedHashCode = hash;
return hash;
}
public static com.twx.learn.protobuf.proto.GpsDataProto.gps_data parseFrom(
java.nio.ByteBuffer data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.twx.learn.protobuf.proto.GpsDataProto.gps_data parseFrom(
java.nio.ByteBuffer data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.twx.learn.protobuf.proto.GpsDataProto.gps_data parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.twx.learn.protobuf.proto.GpsDataProto.gps_data parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.twx.learn.protobuf.proto.GpsDataProto.gps_data parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static com.twx.learn.protobuf.proto.GpsDataProto.gps_data parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static com.twx.learn.protobuf.proto.GpsDataProto.gps_data parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.twx.learn.protobuf.proto.GpsDataProto.gps_data 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 com.twx.learn.protobuf.proto.GpsDataProto.gps_data parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseDelimitedWithIOException(PARSER, input);
}
public static com.twx.learn.protobuf.proto.GpsDataProto.gps_data 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 com.twx.learn.protobuf.proto.GpsDataProto.gps_data parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input);
}
public static com.twx.learn.protobuf.proto.GpsDataProto.gps_data parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
.parseWithIOException(PARSER, input, extensionRegistry);
}
@java.lang.Override
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(com.twx.learn.protobuf.proto.GpsDataProto.gps_data prototype) {
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
}
@java.lang.Override
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 gps_data}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:gps_data)
com.twx.learn.protobuf.proto.GpsDataProto.gps_dataOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return com.twx.learn.protobuf.proto.GpsDataProto.internal_static_gps_data_descriptor;
}
@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable() {
return com.twx.learn.protobuf.proto.GpsDataProto.internal_static_gps_data_fieldAccessorTable
.ensureFieldAccessorsInitialized(
com.twx.learn.protobuf.proto.GpsDataProto.gps_data.class, com.twx.learn.protobuf.proto.GpsDataProto.gps_data.Builder.class);
}
// Construct using com.twx.learn.protobuf.proto.GpsDataProto.gps_data.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessageV3
.alwaysUseFieldBuilders) {
}
}
@java.lang.Override
public Builder clear() {
super.clear();
id_ = 0L;
terminalId_ = "";
dataTime_ = "";
lon_ = 0D;
lat_ = 0D;
speed_ = 0F;
altitude_ = 0;
locType_ = 0;
gpsStatus_ = 0;
direction_ = 0F;
satellite_ = 0;
return this;
}
@java.lang.Override
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return com.twx.learn.protobuf.proto.GpsDataProto.internal_static_gps_data_descriptor;
}
@java.lang.Override
public com.twx.learn.protobuf.proto.GpsDataProto.gps_data getDefaultInstanceForType() {
return com.twx.learn.protobuf.proto.GpsDataProto.gps_data.getDefaultInstance();
}
@java.lang.Override
public com.twx.learn.protobuf.proto.GpsDataProto.gps_data build() {
com.twx.learn.protobuf.proto.GpsDataProto.gps_data result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
@java.lang.Override
public com.twx.learn.protobuf.proto.GpsDataProto.gps_data buildPartial() {
com.twx.learn.protobuf.proto.GpsDataProto.gps_data result = new com.twx.learn.protobuf.proto.GpsDataProto.gps_data(this);
result.id_ = id_;
result.terminalId_ = terminalId_;
result.dataTime_ = dataTime_;
result.lon_ = lon_;
result.lat_ = lat_;
result.speed_ = speed_;
result.altitude_ = altitude_;
result.locType_ = locType_;
result.gpsStatus_ = gpsStatus_;
result.direction_ = direction_;
result.satellite_ = satellite_;
onBuilt();
return result;
}
@java.lang.Override
public Builder clone() {
return super.clone();
}
@java.lang.Override
public Builder setField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.setField(field, value);
}
@java.lang.Override
public Builder clearField(
com.google.protobuf.Descriptors.FieldDescriptor field) {
return super.clearField(field);
}
@java.lang.Override
public Builder clearOneof(
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
return super.clearOneof(oneof);
}
@java.lang.Override
public Builder setRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
int index, java.lang.Object value) {
return super.setRepeatedField(field, index, value);
}
@java.lang.Override
public Builder addRepeatedField(
com.google.protobuf.Descriptors.FieldDescriptor field,
java.lang.Object value) {
return super.addRepeatedField(field, value);
}
@java.lang.Override
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof com.twx.learn.protobuf.proto.GpsDataProto.gps_data) {
return mergeFrom((com.twx.learn.protobuf.proto.GpsDataProto.gps_data)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(com.twx.learn.protobuf.proto.GpsDataProto.gps_data other) {
if (other == com.twx.learn.protobuf.proto.GpsDataProto.gps_data.getDefaultInstance()) return this;
if (other.getId() != 0L) {
setId(other.getId());
}
if (!other.getTerminalId().isEmpty()) {
terminalId_ = other.terminalId_;
onChanged();
}
if (!other.getDataTime().isEmpty()) {
dataTime_ = other.dataTime_;
onChanged();
}
if (other.getLon() != 0D) {
setLon(other.getLon());
}
if (other.getLat() != 0D) {
setLat(other.getLat());
}
if (other.getSpeed() != 0F) {
setSpeed(other.getSpeed());
}
if (other.getAltitude() != 0) {
setAltitude(other.getAltitude());
}
if (other.getLocType() != 0) {
setLocType(other.getLocType());
}
if (other.getGpsStatus() != 0) {
setGpsStatus(other.getGpsStatus());
}
if (other.getDirection() != 0F) {
setDirection(other.getDirection());
}
if (other.getSatellite() != 0) {
setSatellite(other.getSatellite());
}
this.mergeUnknownFields(other.unknownFields);
onChanged();
return this;
}
@java.lang.Override
public final boolean isInitialized() {
return true;
}
@java.lang.Override
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
com.twx.learn.protobuf.proto.GpsDataProto.gps_data parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (com.twx.learn.protobuf.proto.GpsDataProto.gps_data) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private long id_ ;
/**
* <code>int64 id = 1;</code>
* @return The id.
*/
public long getId() {
return id_;
}
/**
* <code>int64 id = 1;</code>
* @param value The id to set.
* @return This builder for chaining.
*/
public Builder setId(long value) {
id_ = value;
onChanged();
return this;
}
/**
* <code>int64 id = 1;</code>
* @return This builder for chaining.
*/
public Builder clearId() {
id_ = 0L;
onChanged();
return this;
}
private java.lang.Object terminalId_ = "";
/**
* <code>string terminalId = 2;</code>
* @return The terminalId.
*/
public java.lang.String getTerminalId() {
java.lang.Object ref = terminalId_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
terminalId_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>string terminalId = 2;</code>
* @return The bytes for terminalId.
*/
public com.google.protobuf.ByteString
getTerminalIdBytes() {
java.lang.Object ref = terminalId_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
terminalId_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string terminalId = 2;</code>
* @param value The terminalId to set.
* @return This builder for chaining.
*/
public Builder setTerminalId(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
terminalId_ = value;
onChanged();
return this;
}
/**
* <code>string terminalId = 2;</code>
* @return This builder for chaining.
*/
public Builder clearTerminalId() {
terminalId_ = getDefaultInstance().getTerminalId();
onChanged();
return this;
}
/**
* <code>string terminalId = 2;</code>
* @param value The bytes for terminalId to set.
* @return This builder for chaining.
*/
public Builder setTerminalIdBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
terminalId_ = value;
onChanged();
return this;
}
private java.lang.Object dataTime_ = "";
/**
* <code>string dataTime = 3;</code>
* @return The dataTime.
*/
public java.lang.String getDataTime() {
java.lang.Object ref = dataTime_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
dataTime_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>string dataTime = 3;</code>
* @return The bytes for dataTime.
*/
public com.google.protobuf.ByteString
getDataTimeBytes() {
java.lang.Object ref = dataTime_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
dataTime_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>string dataTime = 3;</code>
* @param value The dataTime to set.
* @return This builder for chaining.
*/
public Builder setDataTime(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
dataTime_ = value;
onChanged();
return this;
}
/**
* <code>string dataTime = 3;</code>
* @return This builder for chaining.
*/
public Builder clearDataTime() {
dataTime_ = getDefaultInstance().getDataTime();
onChanged();
return this;
}
/**
* <code>string dataTime = 3;</code>
* @param value The bytes for dataTime to set.
* @return This builder for chaining.
*/
public Builder setDataTimeBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
dataTime_ = value;
onChanged();
return this;
}
private double lon_ ;
/**
* <code>double lon = 4;</code>
* @return The lon.
*/
public double getLon() {
return lon_;
}
/**
* <code>double lon = 4;</code>
* @param value The lon to set.
* @return This builder for chaining.
*/
public Builder setLon(double value) {
lon_ = value;
onChanged();
return this;
}
/**
* <code>double lon = 4;</code>
* @return This builder for chaining.
*/
public Builder clearLon() {
lon_ = 0D;
onChanged();
return this;
}
private double lat_ ;
/**
* <code>double lat = 5;</code>
* @return The lat.
*/
public double getLat() {
return lat_;
}
/**
* <code>double lat = 5;</code>
* @param value The lat to set.
* @return This builder for chaining.
*/
public Builder setLat(double value) {
lat_ = value;
onChanged();
return this;
}
/**
* <code>double lat = 5;</code>
* @return This builder for chaining.
*/
public Builder clearLat() {
lat_ = 0D;
onChanged();
return this;
}
private float speed_ ;
/**
* <code>float speed = 6;</code>
* @return The speed.
*/
public float getSpeed() {
return speed_;
}
/**
* <code>float speed = 6;</code>
* @param value The speed to set.
* @return This builder for chaining.
*/
public Builder setSpeed(float value) {
speed_ = value;
onChanged();
return this;
}
/**
* <code>float speed = 6;</code>
* @return This builder for chaining.
*/
public Builder clearSpeed() {
speed_ = 0F;
onChanged();
return this;
}
private int altitude_ ;
/**
* <code>int32 altitude = 7;</code>
* @return The altitude.
*/
public int getAltitude() {
return altitude_;
}
/**
* <code>int32 altitude = 7;</code>
* @param value The altitude to set.
* @return This builder for chaining.
*/
public Builder setAltitude(int value) {
altitude_ = value;
onChanged();
return this;
}
/**
* <code>int32 altitude = 7;</code>
* @return This builder for chaining.
*/
public Builder clearAltitude() {
altitude_ = 0;
onChanged();
return this;
}
private int locType_ ;
/**
* <code>int32 locType = 8;</code>
* @return The locType.
*/
public int getLocType() {
return locType_;
}
/**
* <code>int32 locType = 8;</code>
* @param value The locType to set.
* @return This builder for chaining.
*/
public Builder setLocType(int value) {
locType_ = value;
onChanged();
return this;
}
/**
* <code>int32 locType = 8;</code>
* @return This builder for chaining.
*/
public Builder clearLocType() {
locType_ = 0;
onChanged();
return this;
}
private int gpsStatus_ ;
/**
* <code>int32 gpsStatus = 9;</code>
* @return The gpsStatus.
*/
public int getGpsStatus() {
return gpsStatus_;
}
/**
* <code>int32 gpsStatus = 9;</code>
* @param value The gpsStatus to set.
* @return This builder for chaining.
*/
public Builder setGpsStatus(int value) {
gpsStatus_ = value;
onChanged();
return this;
}
/**
* <code>int32 gpsStatus = 9;</code>
* @return This builder for chaining.
*/
public Builder clearGpsStatus() {
gpsStatus_ = 0;
onChanged();
return this;
}
private float direction_ ;
/**
* <code>float direction = 10;</code>
* @return The direction.
*/
public float getDirection() {
return direction_;
}
/**
* <code>float direction = 10;</code>
* @param value The direction to set.
* @return This builder for chaining.
*/
public Builder setDirection(float value) {
direction_ = value;
onChanged();
return this;
}
/**
* <code>float direction = 10;</code>
* @return This builder for chaining.
*/
public Builder clearDirection() {
direction_ = 0F;
onChanged();
return this;
}
private int satellite_ ;
/**
* <code>int32 satellite = 11;</code>
* @return The satellite.
*/
public int getSatellite() {
return satellite_;
}
/**
* <code>int32 satellite = 11;</code>
* @param value The satellite to set.
* @return This builder for chaining.
*/
public Builder setSatellite(int value) {
satellite_ = value;
onChanged();
return this;
}
/**
* <code>int32 satellite = 11;</code>
* @return This builder for chaining.
*/
public Builder clearSatellite() {
satellite_ = 0;
onChanged();
return this;
}
@java.lang.Override
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.setUnknownFields(unknownFields);
}
@java.lang.Override
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return super.mergeUnknownFields(unknownFields);
}
// @@protoc_insertion_point(builder_scope:gps_data)
}
// @@protoc_insertion_point(class_scope:gps_data)
private static final com.twx.learn.protobuf.proto.GpsDataProto.gps_data DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new com.twx.learn.protobuf.proto.GpsDataProto.gps_data();
}
public static com.twx.learn.protobuf.proto.GpsDataProto.gps_data getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<gps_data>
PARSER = new com.google.protobuf.AbstractParser<gps_data>() {
@java.lang.Override
public gps_data parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new gps_data(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<gps_data> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<gps_data> getParserForType() {
return PARSER;
}
@java.lang.Override
public com.twx.learn.protobuf.proto.GpsDataProto.gps_data getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_gps_data_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
internal_static_gps_data_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\016gps_data.proto\"\301\001\n\010gps_data\022\n\n\002id\030\001 \001(" +
"\003\022\022\n\nterminalId\030\002 \001(\t\022\020\n\010dataTime\030\003 \001(\t\022" +
"\013\n\003lon\030\004 \001(\001\022\013\n\003lat\030\005 \001(\001\022\r\n\005speed\030\006 \001(\002" +
"\022\020\n\010altitude\030\007 \001(\005\022\017\n\007locType\030\010 \001(\005\022\021\n\tg" +
"psStatus\030\t \001(\005\022\021\n\tdirection\030\n \001(\002\022\021\n\tsat" +
"ellite\030\013 \001(\005B,\n\034com.twx.learn.protobuf.p" +
"rotoB\014GpsDataProtob\006proto3"
};
descriptor = com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] {
});
internal_static_gps_data_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_gps_data_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
internal_static_gps_data_descriptor,
new java.lang.String[] { "Id", "TerminalId", "DataTime", "Lon", "Lat", "Speed", "Altitude", "LocType", "GpsStatus", "Direction", "Satellite", });
}
// @@protoc_insertion_point(outer_class_scope)
}