-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #367 from Ladicek/protobuf-schema-evolution
Introduce mechanism for specifying protobuf field numbers
- Loading branch information
Showing
29 changed files
with
893 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,12 @@ | |
import io.vertx.codegen.type.TypeInfo; | ||
|
||
import javax.lang.model.element.Element; | ||
import java.lang.annotation.Annotation; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Julien Viet</a> | ||
|
@@ -26,6 +28,16 @@ default List<AnnotationValueInfo> getAnnotations() { | |
return Collections.emptyList(); | ||
} | ||
|
||
default Optional<AnnotationValueInfo> getAnnotation(Class<? extends Annotation> annotationType) { | ||
String annotationName = annotationType.getName(); | ||
for (AnnotationValueInfo annotation : getAnnotations()) { | ||
if (annotation.getName().equals(annotationName)) { | ||
return Optional.of(annotation); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
default Map<String, Object> getVars() { | ||
HashMap<String, Object> vars = new HashMap<>(); | ||
vars.put("helper", new Helper()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
vertx-codegen-processor/src/test/java/io/vertx/test/codegen/testenum/SomeAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.vertx.test.codegen.testenum; | ||
|
||
public @interface SomeAnnotation { | ||
String value(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...protobuf/src/converters/generated/io/vertx/test/codegen/converter/BookProtoConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package io.vertx.test.codegen.converter; | ||
|
||
import com.google.protobuf.CodedOutputStream; | ||
import com.google.protobuf.CodedInputStream; | ||
import java.io.IOException; | ||
import java.time.Instant; | ||
import java.time.ZonedDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Arrays; | ||
import io.vertx.core.json.JsonObject; | ||
import io.vertx.codegen.protobuf.utils.ExpandableIntArray; | ||
import io.vertx.codegen.protobuf.converters.*; | ||
|
||
public class BookProtoConverter { | ||
|
||
public static void fromProto(CodedInputStream input, Book obj) throws IOException { | ||
int tag; | ||
while ((tag = input.readTag()) != 0) { | ||
switch (tag) { | ||
case 10: { | ||
obj.setName(input.readString()); | ||
break; | ||
} | ||
case 26: { | ||
obj.setAuthor(input.readString()); | ||
break; | ||
} | ||
case 82: { | ||
obj.setIsbn(input.readString()); | ||
break; | ||
} | ||
case 162: { | ||
obj.setGenre(input.readString()); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static void toProto(Book obj, CodedOutputStream output) throws IOException { | ||
ExpandableIntArray cache = new ExpandableIntArray(16); | ||
BookProtoConverter.computeSize(obj, cache, 0); | ||
BookProtoConverter.toProto(obj, output, cache, 0); | ||
} | ||
|
||
public static int toProto(Book obj, CodedOutputStream output, ExpandableIntArray cache, int index) throws IOException { | ||
index = index + 1; | ||
if (obj.getName() != null) { | ||
output.writeString(1, obj.getName()); | ||
} | ||
if (obj.getAuthor() != null) { | ||
output.writeString(3, obj.getAuthor()); | ||
} | ||
if (obj.getIsbn() != null) { | ||
output.writeString(10, obj.getIsbn()); | ||
} | ||
if (obj.getGenre() != null) { | ||
output.writeString(20, obj.getGenre()); | ||
} | ||
return index; | ||
} | ||
|
||
public static int computeSize(Book obj) { | ||
ExpandableIntArray cache = new ExpandableIntArray(16); | ||
BookProtoConverter.computeSize(obj, cache, 0); | ||
return cache.get(0); | ||
} | ||
|
||
public static int computeSize(Book obj, ExpandableIntArray cache, final int baseIndex) { | ||
int size = 0; | ||
int index = baseIndex + 1; | ||
if (obj.getName() != null) { | ||
size += CodedOutputStream.computeStringSize(1, obj.getName()); | ||
} | ||
if (obj.getAuthor() != null) { | ||
size += CodedOutputStream.computeStringSize(3, obj.getAuthor()); | ||
} | ||
if (obj.getIsbn() != null) { | ||
size += CodedOutputStream.computeStringSize(10, obj.getIsbn()); | ||
} | ||
if (obj.getGenre() != null) { | ||
size += CodedOutputStream.computeStringSize(20, obj.getGenre()); | ||
} | ||
cache.set(baseIndex, size); | ||
return index; | ||
} | ||
|
||
} |
Oops, something went wrong.