corrected protos

This commit is contained in:
MaximZaitsev
2016-07-08 17:55:59 +03:00
parent 2b71f3ad85
commit 659be75b57
18 changed files with 3601 additions and 723 deletions
+13 -14
View File
@@ -59,21 +59,20 @@ fun main(args: Array<String>) {
val car = ThisCar.instance val car = ThisCar.instance
var lastTime: Long = System.currentTimeMillis() var lastTime: Long = System.currentTimeMillis()
while (true) { while (true) {
Thread.sleep(50)
val deltaTimeMs = (System.currentTimeMillis() - lastTime) val deltaTimeMs = (System.currentTimeMillis() - lastTime)
if (deltaTimeMs > 50) { if (!car.pathDone) {
if (!car.pathDone) { println(car)
println(car)
}
var pathDone = car.move(deltaTimeMs.toDouble()/ 1000)
if (pathDone) {
val routeDone = RouteDoneP.RouteDone.newBuilder().setUid(car.id).build()
val pathDoneRequest = DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, setRouteUrl, Unpooled.copiedBuffer(routeDone.toByteArray()))
pathDoneRequest.headers().set(HttpHeaderNames.HOST, serverHost)
pathDoneRequest.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE)
pathDoneRequest.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, pathDoneRequest.content().readableBytes())
Client.sendRequest(pathDoneRequest, serverHost, serverPort)
}
lastTime = System.currentTimeMillis()
} }
var pathDone = car.move(deltaTimeMs.toDouble() / 1000)
if (pathDone) {
val routeDone = RouteDoneP.RouteDone.newBuilder().setUid(car.id).build()
val pathDoneRequest = DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, setRouteUrl, Unpooled.copiedBuffer(routeDone.toByteArray()))
pathDoneRequest.headers().set(HttpHeaderNames.HOST, serverHost)
pathDoneRequest.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE)
pathDoneRequest.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, pathDoneRequest.content().readableBytes())
Client.sendRequest(pathDoneRequest, serverHost, serverPort)
}
lastTime = System.currentTimeMillis()
} }
} }
+1 -1
View File
@@ -9,7 +9,7 @@ import proto.car.RouteP.Route.WayPoint
*/ */
class ThisCar private constructor() { class ThisCar private constructor() {
var id = "" var id = 0
//metr //metr
@@ -21,7 +21,6 @@ class ClientHandler : SimpleChannelInboundHandler<Any> {
var url: String = "" var url: String = ""
var contentBytes: ByteArray = ByteArray(0); var contentBytes: ByteArray = ByteArray(0);
override fun channelReadComplete(ctx: ChannelHandlerContext) { override fun channelReadComplete(ctx: ChannelHandlerContext) {
val url = ctx.channel().attr(AttributeKey.valueOf<String>("url")).get() val url = ctx.channel().attr(AttributeKey.valueOf<String>("url")).get()
@@ -29,17 +28,17 @@ class ClientHandler : SimpleChannelInboundHandler<Any> {
when (url) { when (url) {
connectUrl -> { connectUrl -> {
try { try {
val uid = ConnectP.ConnectionResponse.parseFrom(contentBytes).uid val response = ConnectP.ConnectionResponse.parseFrom(contentBytes)
synchronized(ThisCar.instance, { if (response.responseCase == ConnectP.ConnectionResponse.ResponseCase.UID) {
ThisCar.instance.id = uid; val uid = response.uid
}) synchronized(ThisCar.instance, {
ThisCar.instance.id = uid;
})
}
} catch (e: InvalidProtocolBufferException) { } catch (e: InvalidProtocolBufferException) {
e.printStackTrace()
} }
} }
else -> {
//todo error
}
} }
ctx.close() ctx.close()
} }
+291 -100
View File
@@ -518,14 +518,20 @@ public final class ConnectP {
com.google.protobuf.MessageOrBuilder { com.google.protobuf.MessageOrBuilder {
/** /**
* <code>optional string uid = 1;</code> * <code>optional .carkot.Error error = 2;</code>
*/ */
java.lang.String getUid(); proto.car.ErrorP.Error getError();
/** /**
* <code>optional string uid = 1;</code> * <code>optional .carkot.Error error = 2;</code>
*/ */
com.google.protobuf.ByteString proto.car.ErrorP.ErrorOrBuilder getErrorOrBuilder();
getUidBytes();
/**
* <code>optional int32 uid = 1;</code>
*/
int getUid();
public proto.car.ConnectP.ConnectionResponse.ResponseCase getResponseCase();
} }
/** /**
* Protobuf type {@code carkot.ConnectionResponse} * Protobuf type {@code carkot.ConnectionResponse}
@@ -539,7 +545,6 @@ public final class ConnectP {
super(builder); super(builder);
} }
private ConnectionResponse() { private ConnectionResponse() {
uid_ = "";
} }
@java.lang.Override @java.lang.Override
@@ -567,10 +572,23 @@ public final class ConnectP {
} }
break; break;
} }
case 10: { case 8: {
java.lang.String s = input.readStringRequireUtf8(); responseCase_ = 1;
response_ = input.readInt32();
uid_ = s; break;
}
case 18: {
proto.car.ErrorP.Error.Builder subBuilder = null;
if (responseCase_ == 2) {
subBuilder = ((proto.car.ErrorP.Error) response_).toBuilder();
}
response_ =
input.readMessage(proto.car.ErrorP.Error.parser(), extensionRegistry);
if (subBuilder != null) {
subBuilder.mergeFrom((proto.car.ErrorP.Error) response_);
response_ = subBuilder.buildPartial();
}
responseCase_ = 2;
break; break;
} }
} }
@@ -596,38 +614,73 @@ public final class ConnectP {
proto.car.ConnectP.ConnectionResponse.class, proto.car.ConnectP.ConnectionResponse.Builder.class); proto.car.ConnectP.ConnectionResponse.class, proto.car.ConnectP.ConnectionResponse.Builder.class);
} }
public static final int UID_FIELD_NUMBER = 1; private int responseCase_ = 0;
private volatile java.lang.Object uid_; private java.lang.Object response_;
/** public enum ResponseCase
* <code>optional string uid = 1;</code> implements com.google.protobuf.Internal.EnumLite {
*/ ERROR(2),
public java.lang.String getUid() { UID(1),
java.lang.Object ref = uid_; RESPONSE_NOT_SET(0);
if (ref instanceof java.lang.String) { private final int value;
return (java.lang.String) ref; private ResponseCase(int value) {
} else { this.value = value;
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
uid_ = s;
return s;
} }
/**
* @deprecated Use {@link #forNumber(int)} instead.
*/
@java.lang.Deprecated
public static ResponseCase valueOf(int value) {
return forNumber(value);
}
public static ResponseCase forNumber(int value) {
switch (value) {
case 2: return ERROR;
case 1: return UID;
case 0: return RESPONSE_NOT_SET;
default: return null;
}
}
public int getNumber() {
return this.value;
}
};
public ResponseCase
getResponseCase() {
return ResponseCase.forNumber(
responseCase_);
}
public static final int ERROR_FIELD_NUMBER = 2;
/**
* <code>optional .carkot.Error error = 2;</code>
*/
public proto.car.ErrorP.Error getError() {
if (responseCase_ == 2) {
return (proto.car.ErrorP.Error) response_;
}
return proto.car.ErrorP.Error.getDefaultInstance();
} }
/** /**
* <code>optional string uid = 1;</code> * <code>optional .carkot.Error error = 2;</code>
*/ */
public com.google.protobuf.ByteString public proto.car.ErrorP.ErrorOrBuilder getErrorOrBuilder() {
getUidBytes() { if (responseCase_ == 2) {
java.lang.Object ref = uid_; return (proto.car.ErrorP.Error) response_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
uid_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
} }
return proto.car.ErrorP.Error.getDefaultInstance();
}
public static final int UID_FIELD_NUMBER = 1;
/**
* <code>optional int32 uid = 1;</code>
*/
public int getUid() {
if (responseCase_ == 1) {
return (java.lang.Integer) response_;
}
return 0;
} }
private byte memoizedIsInitialized = -1; private byte memoizedIsInitialized = -1;
@@ -642,8 +695,12 @@ public final class ConnectP {
public void writeTo(com.google.protobuf.CodedOutputStream output) public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException { throws java.io.IOException {
if (!getUidBytes().isEmpty()) { if (responseCase_ == 1) {
com.google.protobuf.GeneratedMessage.writeString(output, 1, uid_); output.writeInt32(
1, (int)((java.lang.Integer) response_));
}
if (responseCase_ == 2) {
output.writeMessage(2, (proto.car.ErrorP.Error) response_);
} }
} }
@@ -652,8 +709,14 @@ public final class ConnectP {
if (size != -1) return size; if (size != -1) return size;
size = 0; size = 0;
if (!getUidBytes().isEmpty()) { if (responseCase_ == 1) {
size += com.google.protobuf.GeneratedMessage.computeStringSize(1, uid_); size += com.google.protobuf.CodedOutputStream
.computeInt32Size(
1, (int)((java.lang.Integer) response_));
}
if (responseCase_ == 2) {
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(2, (proto.car.ErrorP.Error) response_);
} }
memoizedSize = size; memoizedSize = size;
return size; return size;
@@ -772,8 +835,8 @@ public final class ConnectP {
} }
public Builder clear() { public Builder clear() {
super.clear(); super.clear();
uid_ = ""; responseCase_ = 0;
response_ = null;
return this; return this;
} }
@@ -796,7 +859,17 @@ public final class ConnectP {
public proto.car.ConnectP.ConnectionResponse buildPartial() { public proto.car.ConnectP.ConnectionResponse buildPartial() {
proto.car.ConnectP.ConnectionResponse result = new proto.car.ConnectP.ConnectionResponse(this); proto.car.ConnectP.ConnectionResponse result = new proto.car.ConnectP.ConnectionResponse(this);
result.uid_ = uid_; if (responseCase_ == 2) {
if (errorBuilder_ == null) {
result.response_ = response_;
} else {
result.response_ = errorBuilder_.build();
}
}
if (responseCase_ == 1) {
result.response_ = response_;
}
result.responseCase_ = responseCase_;
onBuilt(); onBuilt();
return result; return result;
} }
@@ -812,9 +885,18 @@ public final class ConnectP {
public Builder mergeFrom(proto.car.ConnectP.ConnectionResponse other) { public Builder mergeFrom(proto.car.ConnectP.ConnectionResponse other) {
if (other == proto.car.ConnectP.ConnectionResponse.getDefaultInstance()) return this; if (other == proto.car.ConnectP.ConnectionResponse.getDefaultInstance()) return this;
if (!other.getUid().isEmpty()) { switch (other.getResponseCase()) {
uid_ = other.uid_; case ERROR: {
onChanged(); mergeError(other.getError());
break;
}
case UID: {
setUid(other.getUid());
break;
}
case RESPONSE_NOT_SET: {
break;
}
} }
onChanged(); onChanged();
return this; return this;
@@ -841,73 +923,179 @@ public final class ConnectP {
} }
return this; return this;
} }
private int responseCase_ = 0;
private java.lang.Object response_;
public ResponseCase
getResponseCase() {
return ResponseCase.forNumber(
responseCase_);
}
private java.lang.Object uid_ = ""; public Builder clearResponse() {
responseCase_ = 0;
response_ = null;
onChanged();
return this;
}
private com.google.protobuf.SingleFieldBuilder<
proto.car.ErrorP.Error, proto.car.ErrorP.Error.Builder, proto.car.ErrorP.ErrorOrBuilder> errorBuilder_;
/** /**
* <code>optional string uid = 1;</code> * <code>optional .carkot.Error error = 2;</code>
*/ */
public java.lang.String getUid() { public proto.car.ErrorP.Error getError() {
java.lang.Object ref = uid_; if (errorBuilder_ == null) {
if (!(ref instanceof java.lang.String)) { if (responseCase_ == 2) {
com.google.protobuf.ByteString bs = return (proto.car.ErrorP.Error) response_;
(com.google.protobuf.ByteString) ref; }
java.lang.String s = bs.toStringUtf8(); return proto.car.ErrorP.Error.getDefaultInstance();
uid_ = s;
return s;
} else { } else {
return (java.lang.String) ref; if (responseCase_ == 2) {
return errorBuilder_.getMessage();
}
return proto.car.ErrorP.Error.getDefaultInstance();
} }
} }
/** /**
* <code>optional string uid = 1;</code> * <code>optional .carkot.Error error = 2;</code>
*/ */
public com.google.protobuf.ByteString public Builder setError(proto.car.ErrorP.Error value) {
getUidBytes() { if (errorBuilder_ == null) {
java.lang.Object ref = uid_; if (value == null) {
if (ref instanceof String) { throw new NullPointerException();
com.google.protobuf.ByteString b = }
com.google.protobuf.ByteString.copyFromUtf8( response_ = value;
(java.lang.String) ref); onChanged();
uid_ = b;
return b;
} else { } else {
return (com.google.protobuf.ByteString) ref; errorBuilder_.setMessage(value);
}
responseCase_ = 2;
return this;
}
/**
* <code>optional .carkot.Error error = 2;</code>
*/
public Builder setError(
proto.car.ErrorP.Error.Builder builderForValue) {
if (errorBuilder_ == null) {
response_ = builderForValue.build();
onChanged();
} else {
errorBuilder_.setMessage(builderForValue.build());
}
responseCase_ = 2;
return this;
}
/**
* <code>optional .carkot.Error error = 2;</code>
*/
public Builder mergeError(proto.car.ErrorP.Error value) {
if (errorBuilder_ == null) {
if (responseCase_ == 2 &&
response_ != proto.car.ErrorP.Error.getDefaultInstance()) {
response_ = proto.car.ErrorP.Error.newBuilder((proto.car.ErrorP.Error) response_)
.mergeFrom(value).buildPartial();
} else {
response_ = value;
}
onChanged();
} else {
if (responseCase_ == 2) {
errorBuilder_.mergeFrom(value);
}
errorBuilder_.setMessage(value);
}
responseCase_ = 2;
return this;
}
/**
* <code>optional .carkot.Error error = 2;</code>
*/
public Builder clearError() {
if (errorBuilder_ == null) {
if (responseCase_ == 2) {
responseCase_ = 0;
response_ = null;
onChanged();
}
} else {
if (responseCase_ == 2) {
responseCase_ = 0;
response_ = null;
}
errorBuilder_.clear();
}
return this;
}
/**
* <code>optional .carkot.Error error = 2;</code>
*/
public proto.car.ErrorP.Error.Builder getErrorBuilder() {
return getErrorFieldBuilder().getBuilder();
}
/**
* <code>optional .carkot.Error error = 2;</code>
*/
public proto.car.ErrorP.ErrorOrBuilder getErrorOrBuilder() {
if ((responseCase_ == 2) && (errorBuilder_ != null)) {
return errorBuilder_.getMessageOrBuilder();
} else {
if (responseCase_ == 2) {
return (proto.car.ErrorP.Error) response_;
}
return proto.car.ErrorP.Error.getDefaultInstance();
} }
} }
/** /**
* <code>optional string uid = 1;</code> * <code>optional .carkot.Error error = 2;</code>
*/ */
public Builder setUid( private com.google.protobuf.SingleFieldBuilder<
java.lang.String value) { proto.car.ErrorP.Error, proto.car.ErrorP.Error.Builder, proto.car.ErrorP.ErrorOrBuilder>
if (value == null) { getErrorFieldBuilder() {
throw new NullPointerException(); if (errorBuilder_ == null) {
} if (!(responseCase_ == 2)) {
response_ = proto.car.ErrorP.Error.getDefaultInstance();
uid_ = value; }
errorBuilder_ = new com.google.protobuf.SingleFieldBuilder<
proto.car.ErrorP.Error, proto.car.ErrorP.Error.Builder, proto.car.ErrorP.ErrorOrBuilder>(
(proto.car.ErrorP.Error) response_,
getParentForChildren(),
isClean());
response_ = null;
}
responseCase_ = 2;
onChanged();;
return errorBuilder_;
}
/**
* <code>optional int32 uid = 1;</code>
*/
public int getUid() {
if (responseCase_ == 1) {
return (java.lang.Integer) response_;
}
return 0;
}
/**
* <code>optional int32 uid = 1;</code>
*/
public Builder setUid(int value) {
responseCase_ = 1;
response_ = value;
onChanged(); onChanged();
return this; return this;
} }
/** /**
* <code>optional string uid = 1;</code> * <code>optional int32 uid = 1;</code>
*/ */
public Builder clearUid() { public Builder clearUid() {
if (responseCase_ == 1) {
uid_ = getDefaultInstance().getUid(); responseCase_ = 0;
onChanged(); response_ = null;
return this; onChanged();
} }
/**
* <code>optional string uid = 1;</code>
*/
public Builder setUidBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
uid_ = value;
onChanged();
return this; return this;
} }
public final Builder setUnknownFields( public final Builder setUnknownFields(
@@ -978,10 +1166,11 @@ public final class ConnectP {
descriptor; descriptor;
static { static {
java.lang.String[] descriptorData = { java.lang.String[] descriptorData = {
"\n\rconnect.proto\022\006carkot\"-\n\021ConnectionReq" + "\n\rconnect.proto\022\006carkot\032\013error.proto\"-\n\021" +
"uest\022\n\n\002ip\030\001 \001(\t\022\014\n\004port\030\002 \001(\005\"!\n\022Connec" + "ConnectionRequest\022\n\n\002ip\030\001 \001(\t\022\014\n\004port\030\002 " +
"tionResponse\022\013\n\003uid\030\001 \001(\tB\025\n\tproto.carB\010" + "\001(\005\"O\n\022ConnectionResponse\022\036\n\005error\030\002 \001(\013" +
"ConnectPb\006proto3" "2\r.carkot.ErrorH\000\022\r\n\003uid\030\001 \001(\005H\000B\n\n\010resp" +
"onseB\025\n\tproto.carB\010ConnectPb\006proto3"
}; };
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
@@ -994,6 +1183,7 @@ public final class ConnectP {
com.google.protobuf.Descriptors.FileDescriptor com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData, .internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] { new com.google.protobuf.Descriptors.FileDescriptor[] {
proto.car.ErrorP.getDescriptor(),
}, assigner); }, assigner);
internal_static_carkot_ConnectionRequest_descriptor = internal_static_carkot_ConnectionRequest_descriptor =
getDescriptor().getMessageTypes().get(0); getDescriptor().getMessageTypes().get(0);
@@ -1006,7 +1196,8 @@ public final class ConnectP {
internal_static_carkot_ConnectionResponse_fieldAccessorTable = new internal_static_carkot_ConnectionResponse_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable( com.google.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_carkot_ConnectionResponse_descriptor, internal_static_carkot_ConnectionResponse_descriptor,
new java.lang.String[] { "Uid", }); new java.lang.String[] { "Error", "Uid", "Response", });
proto.car.ErrorP.getDescriptor();
} }
// @@protoc_insertion_point(outer_class_scope) // @@protoc_insertion_point(outer_class_scope)
@@ -0,0 +1,555 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: error.proto
package proto.car;
public final class ErrorP {
private ErrorP() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
}
public interface ErrorOrBuilder extends
// @@protoc_insertion_point(interface_extends:carkot.Error)
com.google.protobuf.MessageOrBuilder {
/**
* <code>optional string errorMessage = 1;</code>
*/
java.lang.String getErrorMessage();
/**
* <code>optional string errorMessage = 1;</code>
*/
com.google.protobuf.ByteString
getErrorMessageBytes();
/**
* <code>optional int32 errorCode = 2;</code>
*/
int getErrorCode();
}
/**
* Protobuf type {@code carkot.Error}
*/
public static final class Error extends
com.google.protobuf.GeneratedMessage implements
// @@protoc_insertion_point(message_implements:carkot.Error)
ErrorOrBuilder {
// Use Error.newBuilder() to construct.
private Error(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
super(builder);
}
private Error() {
errorMessage_ = "";
errorCode_ = 0;
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return com.google.protobuf.UnknownFieldSet.getDefaultInstance();
}
private Error(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
int mutable_bitField0_ = 0;
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
default: {
if (!input.skipField(tag)) {
done = true;
}
break;
}
case 10: {
java.lang.String s = input.readStringRequireUtf8();
errorMessage_ = s;
break;
}
case 16: {
errorCode_ = 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 {
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return proto.car.ErrorP.internal_static_carkot_Error_descriptor;
}
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
return proto.car.ErrorP.internal_static_carkot_Error_fieldAccessorTable
.ensureFieldAccessorsInitialized(
proto.car.ErrorP.Error.class, proto.car.ErrorP.Error.Builder.class);
}
public static final int ERRORMESSAGE_FIELD_NUMBER = 1;
private volatile java.lang.Object errorMessage_;
/**
* <code>optional string errorMessage = 1;</code>
*/
public java.lang.String getErrorMessage() {
java.lang.Object ref = errorMessage_;
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();
errorMessage_ = s;
return s;
}
}
/**
* <code>optional string errorMessage = 1;</code>
*/
public com.google.protobuf.ByteString
getErrorMessageBytes() {
java.lang.Object ref = errorMessage_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
errorMessage_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
public static final int ERRORCODE_FIELD_NUMBER = 2;
private int errorCode_;
/**
* <code>optional int32 errorCode = 2;</code>
*/
public int getErrorCode() {
return errorCode_;
}
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 (!getErrorMessageBytes().isEmpty()) {
com.google.protobuf.GeneratedMessage.writeString(output, 1, errorMessage_);
}
if (errorCode_ != 0) {
output.writeInt32(2, errorCode_);
}
}
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (!getErrorMessageBytes().isEmpty()) {
size += com.google.protobuf.GeneratedMessage.computeStringSize(1, errorMessage_);
}
if (errorCode_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(2, errorCode_);
}
memoizedSize = size;
return size;
}
private static final long serialVersionUID = 0L;
public static proto.car.ErrorP.Error parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static proto.car.ErrorP.Error parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static proto.car.ErrorP.Error parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static proto.car.ErrorP.Error parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static proto.car.ErrorP.Error parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessage
.parseWithIOException(PARSER, input);
}
public static proto.car.ErrorP.Error parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessage
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static proto.car.ErrorP.Error parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessage
.parseDelimitedWithIOException(PARSER, input);
}
public static proto.car.ErrorP.Error parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessage
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static proto.car.ErrorP.Error parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessage
.parseWithIOException(PARSER, input);
}
public static proto.car.ErrorP.Error parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessage
.parseWithIOException(PARSER, input, extensionRegistry);
}
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(proto.car.ErrorP.Error 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.GeneratedMessage.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* Protobuf type {@code carkot.Error}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessage.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:carkot.Error)
proto.car.ErrorP.ErrorOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return proto.car.ErrorP.internal_static_carkot_Error_descriptor;
}
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
return proto.car.ErrorP.internal_static_carkot_Error_fieldAccessorTable
.ensureFieldAccessorsInitialized(
proto.car.ErrorP.Error.class, proto.car.ErrorP.Error.Builder.class);
}
// Construct using proto.car.ErrorP.Error.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessage.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
}
}
public Builder clear() {
super.clear();
errorMessage_ = "";
errorCode_ = 0;
return this;
}
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return proto.car.ErrorP.internal_static_carkot_Error_descriptor;
}
public proto.car.ErrorP.Error getDefaultInstanceForType() {
return proto.car.ErrorP.Error.getDefaultInstance();
}
public proto.car.ErrorP.Error build() {
proto.car.ErrorP.Error result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
public proto.car.ErrorP.Error buildPartial() {
proto.car.ErrorP.Error result = new proto.car.ErrorP.Error(this);
result.errorMessage_ = errorMessage_;
result.errorCode_ = errorCode_;
onBuilt();
return result;
}
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof proto.car.ErrorP.Error) {
return mergeFrom((proto.car.ErrorP.Error)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(proto.car.ErrorP.Error other) {
if (other == proto.car.ErrorP.Error.getDefaultInstance()) return this;
if (!other.getErrorMessage().isEmpty()) {
errorMessage_ = other.errorMessage_;
onChanged();
}
if (other.getErrorCode() != 0) {
setErrorCode(other.getErrorCode());
}
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 {
proto.car.ErrorP.Error parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (proto.car.ErrorP.Error) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private java.lang.Object errorMessage_ = "";
/**
* <code>optional string errorMessage = 1;</code>
*/
public java.lang.String getErrorMessage() {
java.lang.Object ref = errorMessage_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
errorMessage_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>optional string errorMessage = 1;</code>
*/
public com.google.protobuf.ByteString
getErrorMessageBytes() {
java.lang.Object ref = errorMessage_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
errorMessage_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>optional string errorMessage = 1;</code>
*/
public Builder setErrorMessage(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
errorMessage_ = value;
onChanged();
return this;
}
/**
* <code>optional string errorMessage = 1;</code>
*/
public Builder clearErrorMessage() {
errorMessage_ = getDefaultInstance().getErrorMessage();
onChanged();
return this;
}
/**
* <code>optional string errorMessage = 1;</code>
*/
public Builder setErrorMessageBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
errorMessage_ = value;
onChanged();
return this;
}
private int errorCode_ ;
/**
* <code>optional int32 errorCode = 2;</code>
*/
public int getErrorCode() {
return errorCode_;
}
/**
* <code>optional int32 errorCode = 2;</code>
*/
public Builder setErrorCode(int value) {
errorCode_ = value;
onChanged();
return this;
}
/**
* <code>optional int32 errorCode = 2;</code>
*/
public Builder clearErrorCode() {
errorCode_ = 0;
onChanged();
return this;
}
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return this;
}
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return this;
}
// @@protoc_insertion_point(builder_scope:carkot.Error)
}
// @@protoc_insertion_point(class_scope:carkot.Error)
private static final proto.car.ErrorP.Error DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new proto.car.ErrorP.Error();
}
public static proto.car.ErrorP.Error getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<Error>
PARSER = new com.google.protobuf.AbstractParser<Error>() {
public Error parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new Error(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<Error> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<Error> getParserForType() {
return PARSER;
}
public proto.car.ErrorP.Error getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_carkot_Error_descriptor;
private static final
com.google.protobuf.GeneratedMessage.FieldAccessorTable
internal_static_carkot_Error_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\013error.proto\022\006carkot\"0\n\005Error\022\024\n\014errorM" +
"essage\030\001 \001(\t\022\021\n\terrorCode\030\002 \001(\005B\023\n\tproto" +
".carB\006ErrorPb\006proto3"
};
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_carkot_Error_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_carkot_Error_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_carkot_Error_descriptor,
new java.lang.String[] { "ErrorMessage", "ErrorCode", });
}
// @@protoc_insertion_point(outer_class_scope)
}
File diff suppressed because it is too large Load Diff
+27 -101
View File
@@ -13,14 +13,9 @@ public final class RouteDoneP {
com.google.protobuf.MessageOrBuilder { com.google.protobuf.MessageOrBuilder {
/** /**
* <code>optional string uid = 1;</code> * <code>optional int32 uid = 1;</code>
*/ */
java.lang.String getUid(); int getUid();
/**
* <code>optional string uid = 1;</code>
*/
com.google.protobuf.ByteString
getUidBytes();
} }
/** /**
* Protobuf type {@code carkot.RouteDone} * Protobuf type {@code carkot.RouteDone}
@@ -34,7 +29,7 @@ public final class RouteDoneP {
super(builder); super(builder);
} }
private RouteDone() { private RouteDone() {
uid_ = ""; uid_ = 0;
} }
@java.lang.Override @java.lang.Override
@@ -62,10 +57,9 @@ public final class RouteDoneP {
} }
break; break;
} }
case 10: { case 8: {
java.lang.String s = input.readStringRequireUtf8();
uid_ = s; uid_ = input.readInt32();
break; break;
} }
} }
@@ -92,37 +86,12 @@ public final class RouteDoneP {
} }
public static final int UID_FIELD_NUMBER = 1; public static final int UID_FIELD_NUMBER = 1;
private volatile java.lang.Object uid_; private int uid_;
/** /**
* <code>optional string uid = 1;</code> * <code>optional int32 uid = 1;</code>
*/ */
public java.lang.String getUid() { public int getUid() {
java.lang.Object ref = uid_; return uid_;
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();
uid_ = s;
return s;
}
}
/**
* <code>optional string uid = 1;</code>
*/
public com.google.protobuf.ByteString
getUidBytes() {
java.lang.Object ref = uid_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
uid_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
} }
private byte memoizedIsInitialized = -1; private byte memoizedIsInitialized = -1;
@@ -137,8 +106,8 @@ public final class RouteDoneP {
public void writeTo(com.google.protobuf.CodedOutputStream output) public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException { throws java.io.IOException {
if (!getUidBytes().isEmpty()) { if (uid_ != 0) {
com.google.protobuf.GeneratedMessage.writeString(output, 1, uid_); output.writeInt32(1, uid_);
} }
} }
@@ -147,8 +116,9 @@ public final class RouteDoneP {
if (size != -1) return size; if (size != -1) return size;
size = 0; size = 0;
if (!getUidBytes().isEmpty()) { if (uid_ != 0) {
size += com.google.protobuf.GeneratedMessage.computeStringSize(1, uid_); size += com.google.protobuf.CodedOutputStream
.computeInt32Size(1, uid_);
} }
memoizedSize = size; memoizedSize = size;
return size; return size;
@@ -267,7 +237,7 @@ public final class RouteDoneP {
} }
public Builder clear() { public Builder clear() {
super.clear(); super.clear();
uid_ = ""; uid_ = 0;
return this; return this;
} }
@@ -307,9 +277,8 @@ public final class RouteDoneP {
public Builder mergeFrom(proto.car.RouteDoneP.RouteDone other) { public Builder mergeFrom(proto.car.RouteDoneP.RouteDone other) {
if (other == proto.car.RouteDoneP.RouteDone.getDefaultInstance()) return this; if (other == proto.car.RouteDoneP.RouteDone.getDefaultInstance()) return this;
if (!other.getUid().isEmpty()) { if (other.getUid() != 0) {
uid_ = other.uid_; setUid(other.getUid());
onChanged();
} }
onChanged(); onChanged();
return this; return this;
@@ -337,71 +306,28 @@ public final class RouteDoneP {
return this; return this;
} }
private java.lang.Object uid_ = ""; private int uid_ ;
/** /**
* <code>optional string uid = 1;</code> * <code>optional int32 uid = 1;</code>
*/ */
public java.lang.String getUid() { public int getUid() {
java.lang.Object ref = uid_; return uid_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
uid_ = s;
return s;
} else {
return (java.lang.String) ref;
}
} }
/** /**
* <code>optional string uid = 1;</code> * <code>optional int32 uid = 1;</code>
*/ */
public com.google.protobuf.ByteString public Builder setUid(int value) {
getUidBytes() {
java.lang.Object ref = uid_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
uid_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>optional string uid = 1;</code>
*/
public Builder setUid(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
uid_ = value; uid_ = value;
onChanged(); onChanged();
return this; return this;
} }
/** /**
* <code>optional string uid = 1;</code> * <code>optional int32 uid = 1;</code>
*/ */
public Builder clearUid() { public Builder clearUid() {
uid_ = getDefaultInstance().getUid(); uid_ = 0;
onChanged();
return this;
}
/**
* <code>optional string uid = 1;</code>
*/
public Builder setUidBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
uid_ = value;
onChanged(); onChanged();
return this; return this;
} }
@@ -469,7 +395,7 @@ public final class RouteDoneP {
static { static {
java.lang.String[] descriptorData = { java.lang.String[] descriptorData = {
"\n\017routeDone.proto\022\006carkot\"\030\n\tRouteDone\022\013" + "\n\017routeDone.proto\022\006carkot\"\030\n\tRouteDone\022\013" +
"\n\003uid\030\001 \001(\tB\027\n\tproto.carB\nRouteDonePb\006pr" + "\n\003uid\030\001 \001(\005B\027\n\tproto.carB\nRouteDonePb\006pr" +
"oto3" "oto3"
}; };
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
+4 -9
View File
@@ -1,20 +1,16 @@
package server package server
import ThisCar
import com.google.protobuf.InvalidProtocolBufferException import com.google.protobuf.InvalidProtocolBufferException
import connectUrl
import getLocationUrl import getLocationUrl
import io.netty.buffer.Unpooled import io.netty.buffer.Unpooled
import io.netty.channel.ChannelFutureListener import io.netty.channel.ChannelFutureListener
import io.netty.channel.ChannelHandlerContext import io.netty.channel.ChannelHandlerContext
import io.netty.channel.SimpleChannelInboundHandler import io.netty.channel.SimpleChannelInboundHandler
import io.netty.handler.codec.http.* import io.netty.handler.codec.http.*
import proto.car.ConnectP.ConnectionRequest
import proto.car.LocationP import proto.car.LocationP
import proto.car.RouteDoneP.RouteDone
import proto.car.RouteP import proto.car.RouteP
import routeDoneUrl
import setRouteUrl import setRouteUrl
import java.util.*
/** /**
* Created by user on 7/6/16. * Created by user on 7/6/16.
@@ -32,14 +28,14 @@ class Handler : SimpleChannelInboundHandler<Any>() {
var dataAnswer: ByteArray = ByteArray(0) var dataAnswer: ByteArray = ByteArray(0)
when (url) { when (url) {
getLocationUrl -> { getLocationUrl -> {
dataAnswer = LocationP.Location.newBuilder().setAngle(car.angle).setX(car.x).setY(car.y).build().toByteArray(); dataAnswer = LocationP.Location.newBuilder().setLocationResponse(LocationP.Location.LocationResponse.newBuilder().setAngle(car.angle).setX(car.x).setY(car.y)).build().toByteArray()
} }
setRouteUrl -> { setRouteUrl -> {
var data: RouteP.Route? = null; var data: RouteP.Route? = null;
try { try {
data = RouteP.Route.parseFrom(contentBytes) data = RouteP.Route.parseFrom(contentBytes)
} catch (e: InvalidProtocolBufferException) { } catch (e: InvalidProtocolBufferException) {
//todo error answer success = false;
} }
if (data != null) { if (data != null) {
val wayPoints = data.wayPointsList val wayPoints = data.wayPointsList
@@ -49,11 +45,10 @@ class Handler : SimpleChannelInboundHandler<Any>() {
} }
else -> { else -> {
success = false success = false
//todo unsup operation. error answer
} }
} }
val response = DefaultFullHttpResponse(HttpVersion.HTTP_1_1, if (success) HttpResponseStatus.OK else HttpResponseStatus.NOT_FOUND, Unpooled.copiedBuffer(dataAnswer)) val response = DefaultFullHttpResponse(HttpVersion.HTTP_1_1, if (success) HttpResponseStatus.OK else HttpResponseStatus.BAD_REQUEST, Unpooled.copiedBuffer(dataAnswer))
response.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes()) response.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes())
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
} }
+2 -2
View File
@@ -77,7 +77,7 @@ fun main(args: Array<String>) {
val data = scanner.nextLine() val data = scanner.nextLine()
val datas = data.split(" ") val datas = data.split(" ")
try { try {
val id = datas[0] val id = datas[0].toInt()
val distance = datas[1].toDouble() val distance = datas[1].toDouble()
val angle = datas[2].toDouble() val angle = datas[2].toDouble()
@@ -106,7 +106,7 @@ fun main(args: Array<String>) {
request.headers().set(HttpHeaderNames.HOST, car.host) request.headers().set(HttpHeaderNames.HOST, car.host)
request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE) request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE)
request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes()) request.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes())
Client.sendRequest(request, car.host, car.port, car.id) Client.sendRequest(request, car.host, car.port, car.uid)
} }
} }
} }
+3 -6
View File
@@ -1,10 +1,7 @@
package car.client package car.client
import io.netty.bootstrap.Bootstrap import io.netty.bootstrap.Bootstrap
import io.netty.channel.ChannelFutureListener
import io.netty.channel.ChannelInitializer
import io.netty.channel.nio.NioEventLoopGroup import io.netty.channel.nio.NioEventLoopGroup
import io.netty.channel.socket.SocketChannel
import io.netty.channel.socket.nio.NioSocketChannel import io.netty.channel.socket.nio.NioSocketChannel
import io.netty.handler.codec.http.HttpRequest import io.netty.handler.codec.http.HttpRequest
import io.netty.util.AttributeKey import io.netty.util.AttributeKey
@@ -21,14 +18,14 @@ object Client {
val b = Bootstrap(); val b = Bootstrap();
b.group(group).channel(NioSocketChannel().javaClass).handler(ClientInitializer()) b.group(group).channel(NioSocketChannel().javaClass).handler(ClientInitializer())
.attr(AttributeKey.newInstance<String>("url"), "") .attr(AttributeKey.newInstance<String>("url"), "")
.attr(AttributeKey.newInstance<String>("uid"), "") .attr(AttributeKey.newInstance<Int>("uid"), 0)
return b return b
} }
fun sendRequest(request: HttpRequest, host: String, port: Int, carUid: String) { fun sendRequest(request: HttpRequest, host: String, port: Int, carUid: Int) {
try { try {
bootstrap.attr(AttributeKey.valueOf<String>("url"), request.uri()) bootstrap.attr(AttributeKey.valueOf<String>("url"), request.uri())
bootstrap.attr(AttributeKey.valueOf<String>("uid"), carUid) bootstrap.attr(AttributeKey.valueOf<Int>("uid"), carUid)
val ch = bootstrap.connect(host, port).sync().channel() val ch = bootstrap.connect(host, port).sync().channel()
ch.writeAndFlush(request) ch.writeAndFlush(request)
ch.closeFuture().sync()//wait for answer ch.closeFuture().sync()//wait for answer
+13 -16
View File
@@ -8,8 +8,6 @@ import io.netty.handler.codec.http.HttpContent
import io.netty.util.AttributeKey import io.netty.util.AttributeKey
import objects.Environment import objects.Environment
import proto.car.LocationP import proto.car.LocationP
import setRouteUrl
import java.util.*
/** /**
* Created by user on 7/8/16. * Created by user on 7/8/16.
@@ -22,25 +20,24 @@ class ClientHandler : SimpleChannelInboundHandler<Any> {
override fun channelReadComplete(ctx: ChannelHandlerContext) { override fun channelReadComplete(ctx: ChannelHandlerContext) {
val url = ctx.channel().attr(AttributeKey.valueOf<String>("url")).get() val url = ctx.channel().attr(AttributeKey.valueOf<String>("url")).get()
val carUid = ctx.channel().attr(AttributeKey.valueOf<String>("uid")).get() val carUid = ctx.channel().attr(AttributeKey.valueOf<Int>("uid")).get()
val environment = Environment.instance val environment = Environment.instance
when (url) { when (url) {
setRouteUrl -> {
}
getLocationUrl -> { getLocationUrl -> {
try { try {
val data = LocationP.Location.parseFrom(contentBytes) val response = LocationP.Location.parseFrom(contentBytes);
synchronized(environment, {
val car = environment.map.get(carUid) if (response.responseCase == LocationP.Location.ResponseCase.LOCATIONRESPONSE) {
if (car != null) { val data = response.locationResponse
car.x = data.x synchronized(environment, {
car.y = data.y val car = environment.map.get(carUid)
} if (car != null) {
}) car.x = data.x
car.y = data.y
}
})
}
} catch (e: InvalidProtocolBufferException) { } catch (e: InvalidProtocolBufferException) {
//todo error answer
} }
} }
else -> { else -> {
+4 -7
View File
@@ -27,15 +27,14 @@ class Handler : SimpleChannelInboundHandler<Any>() {
val environment = Environment.instance val environment = Environment.instance
var success = true; var success = true;
var answer: ByteArray = ByteArray(0)
var answer:ByteArray = ByteArray(0)
when (url) { when (url) {
connectUrl -> { connectUrl -> {
var data: ConnectionRequest? = null var data: ConnectionRequest? = null
try { try {
data = ConnectionRequest.parseFrom(contentBytes) data = ConnectionRequest.parseFrom(contentBytes)
} catch (e: InvalidProtocolBufferException) { } catch (e: InvalidProtocolBufferException) {
//todo error answer success = false;
} }
if (data != null) { if (data != null) {
val uid = environment.connectCar(data.ip, data.port) val uid = environment.connectCar(data.ip, data.port)
@@ -47,7 +46,7 @@ class Handler : SimpleChannelInboundHandler<Any>() {
try { try {
data = RouteDone.parseFrom(contentBytes) data = RouteDone.parseFrom(contentBytes)
} catch (e: InvalidProtocolBufferException) { } catch (e: InvalidProtocolBufferException) {
//todo error answer success = false;
} }
if (data != null) { if (data != null) {
val id = data.uid val id = data.uid
@@ -63,11 +62,9 @@ class Handler : SimpleChannelInboundHandler<Any>() {
} }
else -> { else -> {
success = false success = false
//todo unsup operation. error answer
} }
} }
val response = DefaultFullHttpResponse(HttpVersion.HTTP_1_1, if (success) HttpResponseStatus.OK else HttpResponseStatus.BAD_REQUEST, Unpooled.copiedBuffer(answer))
val response = DefaultFullHttpResponse(HttpVersion.HTTP_1_1, if (success) HttpResponseStatus.OK else HttpResponseStatus.NOT_FOUND, Unpooled.copiedBuffer(answer))
response.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes()) response.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes())
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
} }
+4 -4
View File
@@ -5,9 +5,9 @@ import car.client.Client
/** /**
* Created by user on 7/7/16. * Created by user on 7/7/16.
*/ */
class Car constructor(id: String, host: String, port: Int) { class Car constructor(uid: Int, host: String, port: Int) {
val id: String val uid: Int
val host: String val host: String
val port: Int val port: Int
@@ -17,7 +17,7 @@ class Car constructor(id: String, host: String, port: Int) {
var y: Double var y: Double
init { init {
this.id = id this.uid = uid
this.host = host this.host = host
this.port = port this.port = port
this.free = true this.free = true
@@ -26,6 +26,6 @@ class Car constructor(id: String, host: String, port: Int) {
} }
override fun toString(): String { override fun toString(): String {
return "$id ; x:$x; y:$y" return "$uid ; x:$x; y:$y"
} }
} }
+7 -7
View File
@@ -7,7 +7,7 @@ import java.util.*
*/ */
class Environment private constructor() { class Environment private constructor() {
val map: MutableMap<String, Car> val map: MutableMap<Int, Car>
companion object { companion object {
@@ -19,20 +19,20 @@ class Environment private constructor() {
} }
@Synchronized @Synchronized
fun connectCar(host:String, port:Int):String { fun connectCar(host:String, port:Int):Int {
//todo учетка памяти, тут машинки добавляются,но никогда не удаляются. Если включать и выключать одну и ту же машинку, то либо сервер зациклится, либо out of memory //todo учетка памяти, тут машинки добавляются,но никогда не удаляются. Если включать и выключать одну и ту же машинку, то либо сервер зациклится, либо out of memory
//todo в зависимости от того, что кончится раньше, память или айдишники:) Может сделать поток, который мониторит раз в N минут все машинки и дропает те, которые не активны более какого-то времени? //todo в зависимости от того, что кончится раньше, память или айдишники:) Может сделать поток, который мониторит раз в N минут все машинки и дропает те, которые не активны более какого-то времени?
var unique = false var unique = false
val random = Random() val random = Random()
var stringUid = "" var uid:Int = 0
while (!unique) { while (!unique) {
stringUid = "id:" + random.nextInt(1000000) uid = random.nextInt(1000000)
if (map.get(stringUid) == null) { if (map.get(uid) == null) {
unique = true; unique = true;
} }
} }
map.put(stringUid, Car(stringUid, host, port)) map.put(uid, Car(uid, host, port))
return stringUid return uid
} }
+291 -100
View File
@@ -518,14 +518,20 @@ public final class ConnectP {
com.google.protobuf.MessageOrBuilder { com.google.protobuf.MessageOrBuilder {
/** /**
* <code>optional string uid = 1;</code> * <code>optional .carkot.Error error = 2;</code>
*/ */
java.lang.String getUid(); proto.car.ErrorP.Error getError();
/** /**
* <code>optional string uid = 1;</code> * <code>optional .carkot.Error error = 2;</code>
*/ */
com.google.protobuf.ByteString proto.car.ErrorP.ErrorOrBuilder getErrorOrBuilder();
getUidBytes();
/**
* <code>optional int32 uid = 1;</code>
*/
int getUid();
public proto.car.ConnectP.ConnectionResponse.ResponseCase getResponseCase();
} }
/** /**
* Protobuf type {@code carkot.ConnectionResponse} * Protobuf type {@code carkot.ConnectionResponse}
@@ -539,7 +545,6 @@ public final class ConnectP {
super(builder); super(builder);
} }
private ConnectionResponse() { private ConnectionResponse() {
uid_ = "";
} }
@java.lang.Override @java.lang.Override
@@ -567,10 +572,23 @@ public final class ConnectP {
} }
break; break;
} }
case 10: { case 8: {
java.lang.String s = input.readStringRequireUtf8(); responseCase_ = 1;
response_ = input.readInt32();
uid_ = s; break;
}
case 18: {
proto.car.ErrorP.Error.Builder subBuilder = null;
if (responseCase_ == 2) {
subBuilder = ((proto.car.ErrorP.Error) response_).toBuilder();
}
response_ =
input.readMessage(proto.car.ErrorP.Error.parser(), extensionRegistry);
if (subBuilder != null) {
subBuilder.mergeFrom((proto.car.ErrorP.Error) response_);
response_ = subBuilder.buildPartial();
}
responseCase_ = 2;
break; break;
} }
} }
@@ -596,38 +614,73 @@ public final class ConnectP {
proto.car.ConnectP.ConnectionResponse.class, proto.car.ConnectP.ConnectionResponse.Builder.class); proto.car.ConnectP.ConnectionResponse.class, proto.car.ConnectP.ConnectionResponse.Builder.class);
} }
public static final int UID_FIELD_NUMBER = 1; private int responseCase_ = 0;
private volatile java.lang.Object uid_; private java.lang.Object response_;
/** public enum ResponseCase
* <code>optional string uid = 1;</code> implements com.google.protobuf.Internal.EnumLite {
*/ ERROR(2),
public java.lang.String getUid() { UID(1),
java.lang.Object ref = uid_; RESPONSE_NOT_SET(0);
if (ref instanceof java.lang.String) { private final int value;
return (java.lang.String) ref; private ResponseCase(int value) {
} else { this.value = value;
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
uid_ = s;
return s;
} }
/**
* @deprecated Use {@link #forNumber(int)} instead.
*/
@java.lang.Deprecated
public static ResponseCase valueOf(int value) {
return forNumber(value);
}
public static ResponseCase forNumber(int value) {
switch (value) {
case 2: return ERROR;
case 1: return UID;
case 0: return RESPONSE_NOT_SET;
default: return null;
}
}
public int getNumber() {
return this.value;
}
};
public ResponseCase
getResponseCase() {
return ResponseCase.forNumber(
responseCase_);
}
public static final int ERROR_FIELD_NUMBER = 2;
/**
* <code>optional .carkot.Error error = 2;</code>
*/
public proto.car.ErrorP.Error getError() {
if (responseCase_ == 2) {
return (proto.car.ErrorP.Error) response_;
}
return proto.car.ErrorP.Error.getDefaultInstance();
} }
/** /**
* <code>optional string uid = 1;</code> * <code>optional .carkot.Error error = 2;</code>
*/ */
public com.google.protobuf.ByteString public proto.car.ErrorP.ErrorOrBuilder getErrorOrBuilder() {
getUidBytes() { if (responseCase_ == 2) {
java.lang.Object ref = uid_; return (proto.car.ErrorP.Error) response_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
uid_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
} }
return proto.car.ErrorP.Error.getDefaultInstance();
}
public static final int UID_FIELD_NUMBER = 1;
/**
* <code>optional int32 uid = 1;</code>
*/
public int getUid() {
if (responseCase_ == 1) {
return (java.lang.Integer) response_;
}
return 0;
} }
private byte memoizedIsInitialized = -1; private byte memoizedIsInitialized = -1;
@@ -642,8 +695,12 @@ public final class ConnectP {
public void writeTo(com.google.protobuf.CodedOutputStream output) public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException { throws java.io.IOException {
if (!getUidBytes().isEmpty()) { if (responseCase_ == 1) {
com.google.protobuf.GeneratedMessage.writeString(output, 1, uid_); output.writeInt32(
1, (int)((java.lang.Integer) response_));
}
if (responseCase_ == 2) {
output.writeMessage(2, (proto.car.ErrorP.Error) response_);
} }
} }
@@ -652,8 +709,14 @@ public final class ConnectP {
if (size != -1) return size; if (size != -1) return size;
size = 0; size = 0;
if (!getUidBytes().isEmpty()) { if (responseCase_ == 1) {
size += com.google.protobuf.GeneratedMessage.computeStringSize(1, uid_); size += com.google.protobuf.CodedOutputStream
.computeInt32Size(
1, (int)((java.lang.Integer) response_));
}
if (responseCase_ == 2) {
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(2, (proto.car.ErrorP.Error) response_);
} }
memoizedSize = size; memoizedSize = size;
return size; return size;
@@ -772,8 +835,8 @@ public final class ConnectP {
} }
public Builder clear() { public Builder clear() {
super.clear(); super.clear();
uid_ = ""; responseCase_ = 0;
response_ = null;
return this; return this;
} }
@@ -796,7 +859,17 @@ public final class ConnectP {
public proto.car.ConnectP.ConnectionResponse buildPartial() { public proto.car.ConnectP.ConnectionResponse buildPartial() {
proto.car.ConnectP.ConnectionResponse result = new proto.car.ConnectP.ConnectionResponse(this); proto.car.ConnectP.ConnectionResponse result = new proto.car.ConnectP.ConnectionResponse(this);
result.uid_ = uid_; if (responseCase_ == 2) {
if (errorBuilder_ == null) {
result.response_ = response_;
} else {
result.response_ = errorBuilder_.build();
}
}
if (responseCase_ == 1) {
result.response_ = response_;
}
result.responseCase_ = responseCase_;
onBuilt(); onBuilt();
return result; return result;
} }
@@ -812,9 +885,18 @@ public final class ConnectP {
public Builder mergeFrom(proto.car.ConnectP.ConnectionResponse other) { public Builder mergeFrom(proto.car.ConnectP.ConnectionResponse other) {
if (other == proto.car.ConnectP.ConnectionResponse.getDefaultInstance()) return this; if (other == proto.car.ConnectP.ConnectionResponse.getDefaultInstance()) return this;
if (!other.getUid().isEmpty()) { switch (other.getResponseCase()) {
uid_ = other.uid_; case ERROR: {
onChanged(); mergeError(other.getError());
break;
}
case UID: {
setUid(other.getUid());
break;
}
case RESPONSE_NOT_SET: {
break;
}
} }
onChanged(); onChanged();
return this; return this;
@@ -841,73 +923,179 @@ public final class ConnectP {
} }
return this; return this;
} }
private int responseCase_ = 0;
private java.lang.Object response_;
public ResponseCase
getResponseCase() {
return ResponseCase.forNumber(
responseCase_);
}
private java.lang.Object uid_ = ""; public Builder clearResponse() {
responseCase_ = 0;
response_ = null;
onChanged();
return this;
}
private com.google.protobuf.SingleFieldBuilder<
proto.car.ErrorP.Error, proto.car.ErrorP.Error.Builder, proto.car.ErrorP.ErrorOrBuilder> errorBuilder_;
/** /**
* <code>optional string uid = 1;</code> * <code>optional .carkot.Error error = 2;</code>
*/ */
public java.lang.String getUid() { public proto.car.ErrorP.Error getError() {
java.lang.Object ref = uid_; if (errorBuilder_ == null) {
if (!(ref instanceof java.lang.String)) { if (responseCase_ == 2) {
com.google.protobuf.ByteString bs = return (proto.car.ErrorP.Error) response_;
(com.google.protobuf.ByteString) ref; }
java.lang.String s = bs.toStringUtf8(); return proto.car.ErrorP.Error.getDefaultInstance();
uid_ = s;
return s;
} else { } else {
return (java.lang.String) ref; if (responseCase_ == 2) {
return errorBuilder_.getMessage();
}
return proto.car.ErrorP.Error.getDefaultInstance();
} }
} }
/** /**
* <code>optional string uid = 1;</code> * <code>optional .carkot.Error error = 2;</code>
*/ */
public com.google.protobuf.ByteString public Builder setError(proto.car.ErrorP.Error value) {
getUidBytes() { if (errorBuilder_ == null) {
java.lang.Object ref = uid_; if (value == null) {
if (ref instanceof String) { throw new NullPointerException();
com.google.protobuf.ByteString b = }
com.google.protobuf.ByteString.copyFromUtf8( response_ = value;
(java.lang.String) ref); onChanged();
uid_ = b;
return b;
} else { } else {
return (com.google.protobuf.ByteString) ref; errorBuilder_.setMessage(value);
}
responseCase_ = 2;
return this;
}
/**
* <code>optional .carkot.Error error = 2;</code>
*/
public Builder setError(
proto.car.ErrorP.Error.Builder builderForValue) {
if (errorBuilder_ == null) {
response_ = builderForValue.build();
onChanged();
} else {
errorBuilder_.setMessage(builderForValue.build());
}
responseCase_ = 2;
return this;
}
/**
* <code>optional .carkot.Error error = 2;</code>
*/
public Builder mergeError(proto.car.ErrorP.Error value) {
if (errorBuilder_ == null) {
if (responseCase_ == 2 &&
response_ != proto.car.ErrorP.Error.getDefaultInstance()) {
response_ = proto.car.ErrorP.Error.newBuilder((proto.car.ErrorP.Error) response_)
.mergeFrom(value).buildPartial();
} else {
response_ = value;
}
onChanged();
} else {
if (responseCase_ == 2) {
errorBuilder_.mergeFrom(value);
}
errorBuilder_.setMessage(value);
}
responseCase_ = 2;
return this;
}
/**
* <code>optional .carkot.Error error = 2;</code>
*/
public Builder clearError() {
if (errorBuilder_ == null) {
if (responseCase_ == 2) {
responseCase_ = 0;
response_ = null;
onChanged();
}
} else {
if (responseCase_ == 2) {
responseCase_ = 0;
response_ = null;
}
errorBuilder_.clear();
}
return this;
}
/**
* <code>optional .carkot.Error error = 2;</code>
*/
public proto.car.ErrorP.Error.Builder getErrorBuilder() {
return getErrorFieldBuilder().getBuilder();
}
/**
* <code>optional .carkot.Error error = 2;</code>
*/
public proto.car.ErrorP.ErrorOrBuilder getErrorOrBuilder() {
if ((responseCase_ == 2) && (errorBuilder_ != null)) {
return errorBuilder_.getMessageOrBuilder();
} else {
if (responseCase_ == 2) {
return (proto.car.ErrorP.Error) response_;
}
return proto.car.ErrorP.Error.getDefaultInstance();
} }
} }
/** /**
* <code>optional string uid = 1;</code> * <code>optional .carkot.Error error = 2;</code>
*/ */
public Builder setUid( private com.google.protobuf.SingleFieldBuilder<
java.lang.String value) { proto.car.ErrorP.Error, proto.car.ErrorP.Error.Builder, proto.car.ErrorP.ErrorOrBuilder>
if (value == null) { getErrorFieldBuilder() {
throw new NullPointerException(); if (errorBuilder_ == null) {
} if (!(responseCase_ == 2)) {
response_ = proto.car.ErrorP.Error.getDefaultInstance();
uid_ = value; }
errorBuilder_ = new com.google.protobuf.SingleFieldBuilder<
proto.car.ErrorP.Error, proto.car.ErrorP.Error.Builder, proto.car.ErrorP.ErrorOrBuilder>(
(proto.car.ErrorP.Error) response_,
getParentForChildren(),
isClean());
response_ = null;
}
responseCase_ = 2;
onChanged();;
return errorBuilder_;
}
/**
* <code>optional int32 uid = 1;</code>
*/
public int getUid() {
if (responseCase_ == 1) {
return (java.lang.Integer) response_;
}
return 0;
}
/**
* <code>optional int32 uid = 1;</code>
*/
public Builder setUid(int value) {
responseCase_ = 1;
response_ = value;
onChanged(); onChanged();
return this; return this;
} }
/** /**
* <code>optional string uid = 1;</code> * <code>optional int32 uid = 1;</code>
*/ */
public Builder clearUid() { public Builder clearUid() {
if (responseCase_ == 1) {
uid_ = getDefaultInstance().getUid(); responseCase_ = 0;
onChanged(); response_ = null;
return this; onChanged();
} }
/**
* <code>optional string uid = 1;</code>
*/
public Builder setUidBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
uid_ = value;
onChanged();
return this; return this;
} }
public final Builder setUnknownFields( public final Builder setUnknownFields(
@@ -978,10 +1166,11 @@ public final class ConnectP {
descriptor; descriptor;
static { static {
java.lang.String[] descriptorData = { java.lang.String[] descriptorData = {
"\n\rconnect.proto\022\006carkot\"-\n\021ConnectionReq" + "\n\rconnect.proto\022\006carkot\032\013error.proto\"-\n\021" +
"uest\022\n\n\002ip\030\001 \001(\t\022\014\n\004port\030\002 \001(\005\"!\n\022Connec" + "ConnectionRequest\022\n\n\002ip\030\001 \001(\t\022\014\n\004port\030\002 " +
"tionResponse\022\013\n\003uid\030\001 \001(\tB\025\n\tproto.carB\010" + "\001(\005\"O\n\022ConnectionResponse\022\036\n\005error\030\002 \001(\013" +
"ConnectPb\006proto3" "2\r.carkot.ErrorH\000\022\r\n\003uid\030\001 \001(\005H\000B\n\n\010resp" +
"onseB\025\n\tproto.carB\010ConnectPb\006proto3"
}; };
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
@@ -994,6 +1183,7 @@ public final class ConnectP {
com.google.protobuf.Descriptors.FileDescriptor com.google.protobuf.Descriptors.FileDescriptor
.internalBuildGeneratedFileFrom(descriptorData, .internalBuildGeneratedFileFrom(descriptorData,
new com.google.protobuf.Descriptors.FileDescriptor[] { new com.google.protobuf.Descriptors.FileDescriptor[] {
proto.car.ErrorP.getDescriptor(),
}, assigner); }, assigner);
internal_static_carkot_ConnectionRequest_descriptor = internal_static_carkot_ConnectionRequest_descriptor =
getDescriptor().getMessageTypes().get(0); getDescriptor().getMessageTypes().get(0);
@@ -1006,7 +1196,8 @@ public final class ConnectP {
internal_static_carkot_ConnectionResponse_fieldAccessorTable = new internal_static_carkot_ConnectionResponse_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable( com.google.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_carkot_ConnectionResponse_descriptor, internal_static_carkot_ConnectionResponse_descriptor,
new java.lang.String[] { "Uid", }); new java.lang.String[] { "Error", "Uid", "Response", });
proto.car.ErrorP.getDescriptor();
} }
// @@protoc_insertion_point(outer_class_scope) // @@protoc_insertion_point(outer_class_scope)
+555
View File
@@ -0,0 +1,555 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: error.proto
package proto.car;
public final class ErrorP {
private ErrorP() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
}
public interface ErrorOrBuilder extends
// @@protoc_insertion_point(interface_extends:carkot.Error)
com.google.protobuf.MessageOrBuilder {
/**
* <code>optional string errorMessage = 1;</code>
*/
java.lang.String getErrorMessage();
/**
* <code>optional string errorMessage = 1;</code>
*/
com.google.protobuf.ByteString
getErrorMessageBytes();
/**
* <code>optional int32 errorCode = 2;</code>
*/
int getErrorCode();
}
/**
* Protobuf type {@code carkot.Error}
*/
public static final class Error extends
com.google.protobuf.GeneratedMessage implements
// @@protoc_insertion_point(message_implements:carkot.Error)
ErrorOrBuilder {
// Use Error.newBuilder() to construct.
private Error(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
super(builder);
}
private Error() {
errorMessage_ = "";
errorCode_ = 0;
}
@java.lang.Override
public final com.google.protobuf.UnknownFieldSet
getUnknownFields() {
return com.google.protobuf.UnknownFieldSet.getDefaultInstance();
}
private Error(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
this();
int mutable_bitField0_ = 0;
try {
boolean done = false;
while (!done) {
int tag = input.readTag();
switch (tag) {
case 0:
done = true;
break;
default: {
if (!input.skipField(tag)) {
done = true;
}
break;
}
case 10: {
java.lang.String s = input.readStringRequireUtf8();
errorMessage_ = s;
break;
}
case 16: {
errorCode_ = 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 {
makeExtensionsImmutable();
}
}
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return proto.car.ErrorP.internal_static_carkot_Error_descriptor;
}
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
return proto.car.ErrorP.internal_static_carkot_Error_fieldAccessorTable
.ensureFieldAccessorsInitialized(
proto.car.ErrorP.Error.class, proto.car.ErrorP.Error.Builder.class);
}
public static final int ERRORMESSAGE_FIELD_NUMBER = 1;
private volatile java.lang.Object errorMessage_;
/**
* <code>optional string errorMessage = 1;</code>
*/
public java.lang.String getErrorMessage() {
java.lang.Object ref = errorMessage_;
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();
errorMessage_ = s;
return s;
}
}
/**
* <code>optional string errorMessage = 1;</code>
*/
public com.google.protobuf.ByteString
getErrorMessageBytes() {
java.lang.Object ref = errorMessage_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
errorMessage_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
public static final int ERRORCODE_FIELD_NUMBER = 2;
private int errorCode_;
/**
* <code>optional int32 errorCode = 2;</code>
*/
public int getErrorCode() {
return errorCode_;
}
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 (!getErrorMessageBytes().isEmpty()) {
com.google.protobuf.GeneratedMessage.writeString(output, 1, errorMessage_);
}
if (errorCode_ != 0) {
output.writeInt32(2, errorCode_);
}
}
public int getSerializedSize() {
int size = memoizedSize;
if (size != -1) return size;
size = 0;
if (!getErrorMessageBytes().isEmpty()) {
size += com.google.protobuf.GeneratedMessage.computeStringSize(1, errorMessage_);
}
if (errorCode_ != 0) {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(2, errorCode_);
}
memoizedSize = size;
return size;
}
private static final long serialVersionUID = 0L;
public static proto.car.ErrorP.Error parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static proto.car.ErrorP.Error parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static proto.car.ErrorP.Error parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data);
}
public static proto.car.ErrorP.Error parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return PARSER.parseFrom(data, extensionRegistry);
}
public static proto.car.ErrorP.Error parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessage
.parseWithIOException(PARSER, input);
}
public static proto.car.ErrorP.Error parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessage
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static proto.car.ErrorP.Error parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessage
.parseDelimitedWithIOException(PARSER, input);
}
public static proto.car.ErrorP.Error parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessage
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static proto.car.ErrorP.Error parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessage
.parseWithIOException(PARSER, input);
}
public static proto.car.ErrorP.Error parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessage
.parseWithIOException(PARSER, input, extensionRegistry);
}
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
public static Builder newBuilder(proto.car.ErrorP.Error 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.GeneratedMessage.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* Protobuf type {@code carkot.Error}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessage.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:carkot.Error)
proto.car.ErrorP.ErrorOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
getDescriptor() {
return proto.car.ErrorP.internal_static_carkot_Error_descriptor;
}
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
return proto.car.ErrorP.internal_static_carkot_Error_fieldAccessorTable
.ensureFieldAccessorsInitialized(
proto.car.ErrorP.Error.class, proto.car.ErrorP.Error.Builder.class);
}
// Construct using proto.car.ErrorP.Error.newBuilder()
private Builder() {
maybeForceBuilderInitialization();
}
private Builder(
com.google.protobuf.GeneratedMessage.BuilderParent parent) {
super(parent);
maybeForceBuilderInitialization();
}
private void maybeForceBuilderInitialization() {
if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
}
}
public Builder clear() {
super.clear();
errorMessage_ = "";
errorCode_ = 0;
return this;
}
public com.google.protobuf.Descriptors.Descriptor
getDescriptorForType() {
return proto.car.ErrorP.internal_static_carkot_Error_descriptor;
}
public proto.car.ErrorP.Error getDefaultInstanceForType() {
return proto.car.ErrorP.Error.getDefaultInstance();
}
public proto.car.ErrorP.Error build() {
proto.car.ErrorP.Error result = buildPartial();
if (!result.isInitialized()) {
throw newUninitializedMessageException(result);
}
return result;
}
public proto.car.ErrorP.Error buildPartial() {
proto.car.ErrorP.Error result = new proto.car.ErrorP.Error(this);
result.errorMessage_ = errorMessage_;
result.errorCode_ = errorCode_;
onBuilt();
return result;
}
public Builder mergeFrom(com.google.protobuf.Message other) {
if (other instanceof proto.car.ErrorP.Error) {
return mergeFrom((proto.car.ErrorP.Error)other);
} else {
super.mergeFrom(other);
return this;
}
}
public Builder mergeFrom(proto.car.ErrorP.Error other) {
if (other == proto.car.ErrorP.Error.getDefaultInstance()) return this;
if (!other.getErrorMessage().isEmpty()) {
errorMessage_ = other.errorMessage_;
onChanged();
}
if (other.getErrorCode() != 0) {
setErrorCode(other.getErrorCode());
}
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 {
proto.car.ErrorP.Error parsedMessage = null;
try {
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
parsedMessage = (proto.car.ErrorP.Error) e.getUnfinishedMessage();
throw e.unwrapIOException();
} finally {
if (parsedMessage != null) {
mergeFrom(parsedMessage);
}
}
return this;
}
private java.lang.Object errorMessage_ = "";
/**
* <code>optional string errorMessage = 1;</code>
*/
public java.lang.String getErrorMessage() {
java.lang.Object ref = errorMessage_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
errorMessage_ = s;
return s;
} else {
return (java.lang.String) ref;
}
}
/**
* <code>optional string errorMessage = 1;</code>
*/
public com.google.protobuf.ByteString
getErrorMessageBytes() {
java.lang.Object ref = errorMessage_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
errorMessage_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>optional string errorMessage = 1;</code>
*/
public Builder setErrorMessage(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
errorMessage_ = value;
onChanged();
return this;
}
/**
* <code>optional string errorMessage = 1;</code>
*/
public Builder clearErrorMessage() {
errorMessage_ = getDefaultInstance().getErrorMessage();
onChanged();
return this;
}
/**
* <code>optional string errorMessage = 1;</code>
*/
public Builder setErrorMessageBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
errorMessage_ = value;
onChanged();
return this;
}
private int errorCode_ ;
/**
* <code>optional int32 errorCode = 2;</code>
*/
public int getErrorCode() {
return errorCode_;
}
/**
* <code>optional int32 errorCode = 2;</code>
*/
public Builder setErrorCode(int value) {
errorCode_ = value;
onChanged();
return this;
}
/**
* <code>optional int32 errorCode = 2;</code>
*/
public Builder clearErrorCode() {
errorCode_ = 0;
onChanged();
return this;
}
public final Builder setUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return this;
}
public final Builder mergeUnknownFields(
final com.google.protobuf.UnknownFieldSet unknownFields) {
return this;
}
// @@protoc_insertion_point(builder_scope:carkot.Error)
}
// @@protoc_insertion_point(class_scope:carkot.Error)
private static final proto.car.ErrorP.Error DEFAULT_INSTANCE;
static {
DEFAULT_INSTANCE = new proto.car.ErrorP.Error();
}
public static proto.car.ErrorP.Error getDefaultInstance() {
return DEFAULT_INSTANCE;
}
private static final com.google.protobuf.Parser<Error>
PARSER = new com.google.protobuf.AbstractParser<Error>() {
public Error parsePartialFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return new Error(input, extensionRegistry);
}
};
public static com.google.protobuf.Parser<Error> parser() {
return PARSER;
}
@java.lang.Override
public com.google.protobuf.Parser<Error> getParserForType() {
return PARSER;
}
public proto.car.ErrorP.Error getDefaultInstanceForType() {
return DEFAULT_INSTANCE;
}
}
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_carkot_Error_descriptor;
private static final
com.google.protobuf.GeneratedMessage.FieldAccessorTable
internal_static_carkot_Error_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\013error.proto\022\006carkot\"0\n\005Error\022\024\n\014errorM" +
"essage\030\001 \001(\t\022\021\n\terrorCode\030\002 \001(\005B\023\n\tproto" +
".carB\006ErrorPb\006proto3"
};
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_carkot_Error_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_carkot_Error_fieldAccessorTable = new
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_carkot_Error_descriptor,
new java.lang.String[] { "ErrorMessage", "ErrorCode", });
}
// @@protoc_insertion_point(outer_class_scope)
}
File diff suppressed because it is too large Load Diff
+27 -101
View File
@@ -13,14 +13,9 @@ public final class RouteDoneP {
com.google.protobuf.MessageOrBuilder { com.google.protobuf.MessageOrBuilder {
/** /**
* <code>optional string uid = 1;</code> * <code>optional int32 uid = 1;</code>
*/ */
java.lang.String getUid(); int getUid();
/**
* <code>optional string uid = 1;</code>
*/
com.google.protobuf.ByteString
getUidBytes();
} }
/** /**
* Protobuf type {@code carkot.RouteDone} * Protobuf type {@code carkot.RouteDone}
@@ -34,7 +29,7 @@ public final class RouteDoneP {
super(builder); super(builder);
} }
private RouteDone() { private RouteDone() {
uid_ = ""; uid_ = 0;
} }
@java.lang.Override @java.lang.Override
@@ -62,10 +57,9 @@ public final class RouteDoneP {
} }
break; break;
} }
case 10: { case 8: {
java.lang.String s = input.readStringRequireUtf8();
uid_ = s; uid_ = input.readInt32();
break; break;
} }
} }
@@ -92,37 +86,12 @@ public final class RouteDoneP {
} }
public static final int UID_FIELD_NUMBER = 1; public static final int UID_FIELD_NUMBER = 1;
private volatile java.lang.Object uid_; private int uid_;
/** /**
* <code>optional string uid = 1;</code> * <code>optional int32 uid = 1;</code>
*/ */
public java.lang.String getUid() { public int getUid() {
java.lang.Object ref = uid_; return uid_;
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();
uid_ = s;
return s;
}
}
/**
* <code>optional string uid = 1;</code>
*/
public com.google.protobuf.ByteString
getUidBytes() {
java.lang.Object ref = uid_;
if (ref instanceof java.lang.String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
uid_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
} }
private byte memoizedIsInitialized = -1; private byte memoizedIsInitialized = -1;
@@ -137,8 +106,8 @@ public final class RouteDoneP {
public void writeTo(com.google.protobuf.CodedOutputStream output) public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException { throws java.io.IOException {
if (!getUidBytes().isEmpty()) { if (uid_ != 0) {
com.google.protobuf.GeneratedMessage.writeString(output, 1, uid_); output.writeInt32(1, uid_);
} }
} }
@@ -147,8 +116,9 @@ public final class RouteDoneP {
if (size != -1) return size; if (size != -1) return size;
size = 0; size = 0;
if (!getUidBytes().isEmpty()) { if (uid_ != 0) {
size += com.google.protobuf.GeneratedMessage.computeStringSize(1, uid_); size += com.google.protobuf.CodedOutputStream
.computeInt32Size(1, uid_);
} }
memoizedSize = size; memoizedSize = size;
return size; return size;
@@ -267,7 +237,7 @@ public final class RouteDoneP {
} }
public Builder clear() { public Builder clear() {
super.clear(); super.clear();
uid_ = ""; uid_ = 0;
return this; return this;
} }
@@ -307,9 +277,8 @@ public final class RouteDoneP {
public Builder mergeFrom(proto.car.RouteDoneP.RouteDone other) { public Builder mergeFrom(proto.car.RouteDoneP.RouteDone other) {
if (other == proto.car.RouteDoneP.RouteDone.getDefaultInstance()) return this; if (other == proto.car.RouteDoneP.RouteDone.getDefaultInstance()) return this;
if (!other.getUid().isEmpty()) { if (other.getUid() != 0) {
uid_ = other.uid_; setUid(other.getUid());
onChanged();
} }
onChanged(); onChanged();
return this; return this;
@@ -337,71 +306,28 @@ public final class RouteDoneP {
return this; return this;
} }
private java.lang.Object uid_ = ""; private int uid_ ;
/** /**
* <code>optional string uid = 1;</code> * <code>optional int32 uid = 1;</code>
*/ */
public java.lang.String getUid() { public int getUid() {
java.lang.Object ref = uid_; return uid_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
uid_ = s;
return s;
} else {
return (java.lang.String) ref;
}
} }
/** /**
* <code>optional string uid = 1;</code> * <code>optional int32 uid = 1;</code>
*/ */
public com.google.protobuf.ByteString public Builder setUid(int value) {
getUidBytes() {
java.lang.Object ref = uid_;
if (ref instanceof String) {
com.google.protobuf.ByteString b =
com.google.protobuf.ByteString.copyFromUtf8(
(java.lang.String) ref);
uid_ = b;
return b;
} else {
return (com.google.protobuf.ByteString) ref;
}
}
/**
* <code>optional string uid = 1;</code>
*/
public Builder setUid(
java.lang.String value) {
if (value == null) {
throw new NullPointerException();
}
uid_ = value; uid_ = value;
onChanged(); onChanged();
return this; return this;
} }
/** /**
* <code>optional string uid = 1;</code> * <code>optional int32 uid = 1;</code>
*/ */
public Builder clearUid() { public Builder clearUid() {
uid_ = getDefaultInstance().getUid(); uid_ = 0;
onChanged();
return this;
}
/**
* <code>optional string uid = 1;</code>
*/
public Builder setUidBytes(
com.google.protobuf.ByteString value) {
if (value == null) {
throw new NullPointerException();
}
checkByteStringIsUtf8(value);
uid_ = value;
onChanged(); onChanged();
return this; return this;
} }
@@ -469,7 +395,7 @@ public final class RouteDoneP {
static { static {
java.lang.String[] descriptorData = { java.lang.String[] descriptorData = {
"\n\017routeDone.proto\022\006carkot\"\030\n\tRouteDone\022\013" + "\n\017routeDone.proto\022\006carkot\"\030\n\tRouteDone\022\013" +
"\n\003uid\030\001 \001(\tB\027\n\tproto.carB\nRouteDonePb\006pr" + "\n\003uid\030\001 \001(\005B\027\n\tproto.carB\nRouteDonePb\006pr" +
"oto3" "oto3"
}; };
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =