diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/Makefile b/proto/compiler/google/src/google/protobuf/compiler/kotlin/Makefile index 1909dc79bfb..5aeef5deb81 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/Makefile +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/Makefile @@ -34,6 +34,7 @@ generate: ./protoc --kotlin_out=$$HOME/Downloads/carkot/proto/compiler/protoc-artifacts ./test/nested-msg.proto ./protoc --kotlin_out=$$HOME/Downloads/carkot/proto/compiler/protoc-artifacts ./test/routeDone.proto ./protoc --kotlin_out=$$HOME/Downloads/carkot/proto/compiler/protoc-artifacts ./test/route.proto + ./protoc --kotlin_out=$$HOME/Downloads/carkot/proto/compiler/protoc-artifacts ./test/cross-branch-access.proto debug: gdb --args ./protoc --kotlin_out=$$HOME/Downloads/carkot/proto/compiler/src ./test/addressbook.proto diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc index 33cf56944ca..50d8df11743 100755 Binary files a/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc and b/proto/compiler/google/src/google/protobuf/compiler/kotlin/protoc differ diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.cc b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.cc index 302b1b6499c..e413007bf7b 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.cc +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.cc @@ -328,17 +328,23 @@ void ClassGenerator::generateParseMethods(io::Printer *printer) const { printer->Print(vars, "fun parseFromWithSize(input: CodedInputStream, expectedSize: Int): $builderName$ {\n"); printer->Indent(); - printer->Print("while(parseFieldFrom(input)) {\n"); + + // read while we won't exceed expected amount of bytes + printer->Print("while(getSize() < expectedSize) {\n"); printer->Indent(); - printer->Print("if (getSize() == expectedSize) { break }\n"); - vars["dollar"] = "$"; - printer->Print(vars, - "if (getSize() > expectedSize) { " - "throw InvalidProtocolBufferException(\"Error: expected size of message $dollar$expectedSize, but have read at least $dollar${getSize()}\") " - "}\n"); + + printer->Print("parseFieldFrom(input)\n"); + printer->Outdent(); // while-loop; printer->Print("}\n"); + // check if we read more than expected + vars["dollar"] = "$"; + printer->Print(vars, + "if (getSize() > expectedSize) { " + "throw InvalidProtocolBufferException(\"Error: expected size of message $dollar$expectedSize, but have read at least $dollar${getSize()}\") " + "}\n"); + printer->Print("return this\n"); printer->Outdent(); // function body diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_field_generator.cc b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_field_generator.cc index a1094b6681b..ba059ba5acb 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_field_generator.cc +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_field_generator.cc @@ -194,8 +194,15 @@ void FieldGenerator::generateSerializationCode(io::Printer *printer, bool isRead vars["fieldNumber"] = std::to_string(getFieldNumber()); vars["dollar"] = "$"; + // We will create some temporary variables + // So we place following code into separate block for the sake of hygiene + printer->Print("run {\n"); + printer->Indent(); + // read tag - printer->Print(vars, "input.readTag($fieldNumber$, WireType.LENGTH_DELIMITED)\n"); + if (!noTag) { + printer->Print(vars, "input.readTag($fieldNumber$, WireType.LENGTH_DELIMITED)\n"); + } // read expected size printer->Print(vars, "val expectedSize = input.readInt32NoTag()\n"); @@ -209,6 +216,8 @@ void FieldGenerator::generateSerializationCode(io::Printer *printer, bool isRead "throw InvalidProtocolBufferException (" "\"Expected size $dollar${expectedSize} got $dollar${$fieldName$.getSize()}" "\") }\n"); + printer->Outdent(); + printer->Print("}\n"); } else { vars["fieldNumber"] = std::to_string(getFieldNumber()); diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/Direction.proto b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/Direction.proto new file mode 100644 index 00000000000..ca614a16ea6 --- /dev/null +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/Direction.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; +package carkot; + +option java_package = "proto.car"; +option java_outer_classname = "Direction"; + +message DirectionRequest { + enum Command { + stop = 0; + forward = 1; + backward = 2; + left = 3; + right = 4; + } + Command command = 1; +} + +message DirectionResponse { + int32 code = 1; + string errorMsg = 2; +} diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/connect.proto b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/connect.proto new file mode 100644 index 00000000000..49df5b9aaa9 --- /dev/null +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/connect.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; +package carkot; + +option java_package = "proto.car"; +option java_outer_classname = "Connect"; + +message ConnectionRequest { + string ip = 1; + int32 port = 2; +} + +message ConnectionResponse { + int32 uid = 1; + int32 code = 2; + string errorMsg = 3; + +} diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/cross-branch-access.proto b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/cross-branch-access.proto new file mode 100644 index 00000000000..6afa75ac85d --- /dev/null +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/cross-branch-access.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + +message Grandfather { + message FatherLeft { + message SonLeftLeft { + FatherLeft father = 1; + Grandfather.FatherRight.SonRightLeft brother = 2; + } + + message SonLeftRight { + string foo = 3; + } + } + + message FatherRight { + message SonRightLeft { + string bar = 4; + } + + message SonRightRight { + Grandfather.FatherLeft.SonLeftRight brother = 5; + } + } +} \ No newline at end of file diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/direction.proto b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/direction.proto new file mode 100644 index 00000000000..ca614a16ea6 --- /dev/null +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/direction.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; +package carkot; + +option java_package = "proto.car"; +option java_outer_classname = "Direction"; + +message DirectionRequest { + enum Command { + stop = 0; + forward = 1; + backward = 2; + left = 3; + right = 4; + } + Command command = 1; +} + +message DirectionResponse { + int32 code = 1; + string errorMsg = 2; +} diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/error.proto b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/error.proto new file mode 100644 index 00000000000..6e4e1a4f6f4 --- /dev/null +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/error.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package carkot; + +option java_package = "proto.car"; +option java_outer_classname = "ErrorP"; + +message Error { + string errorMessage = 1; + int32 errorCode = 2; +} diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/location.proto b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/location.proto new file mode 100644 index 00000000000..0d477c8217e --- /dev/null +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/location.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; +package carkot; + +option java_package = "proto.car"; +option java_outer_classname = "Location"; + +message LocationResponse { + + LocationData locationResponseData = 1; + int32 code = 2; + string errorMsg = 3; + + message LocationData { + double x = 1; + double y = 2; + double angle = 3; + } +} diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/route.proto b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/route.proto new file mode 100644 index 00000000000..864845be2f0 --- /dev/null +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/route.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; +package carkot; + +option java_package = "proto.car"; +option java_outer_classname = "Route"; + +message RouteRequest { + repeated WayPoint way_points = 1; + + message WayPoint { + double distance = 2; + double angle_delta = 3; + } +} + +message RouteResponse { + int32 code = 1; + string errorMsg = 2; +} diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/routeDone.proto b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/routeDone.proto new file mode 100644 index 00000000000..5fe75d274f2 --- /dev/null +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/routeDone.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package carkot; + +option java_package = "proto.car"; +option java_outer_classname = "RouteDone"; + +message RouteDoneResponse { + int32 code = 1; + string errorMsg = 2; +} diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/route_done.proto b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/route_done.proto new file mode 100644 index 00000000000..5fe75d274f2 --- /dev/null +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/route_done.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package carkot; + +option java_package = "proto.car"; +option java_outer_classname = "RouteDone"; + +message RouteDoneResponse { + int32 code = 1; + string errorMsg = 2; +}