{"id":306693,"date":"2020-07-09T15:01:04","date_gmt":"2020-07-09T15:01:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=306693"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=306693","title":{"rendered":"\u0418\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u043e\u0442 boilerplate \u043a\u043e\u0434\u0430 \u0432 Protocol Buffers 2"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/510310\/\">\u0415\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0435 \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u0432\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u043c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 Protoloc Buffers \u043e\u0442 Google. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0435\u0433\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438. \u0418 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e boilerplate \u043a\u043e\u0434\u0430, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u0438 \u0431\u0443\u0434\u0435\u043c \u0431\u043e\u0440\u043e\u0442\u044c\u0441\u044f.<br \/>  <a name=\"habracut\"><\/a><br \/>  Protobuff \u2014 \u044d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430 \u2014 \u0432\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0435 \u0441\u043e\u0441\u0442\u0430\u0432 \u0432\u0430\u0448\u0435\u0433\u043e API \u0432 .proto \u0444\u0430\u0439\u043b\u0435, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432, \u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0430 Java \u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0430 C# \u0438\u043b\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442. \u0422\u0430\u043a \u043a\u0430\u043a \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e API \u0434\u043b\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0441\u0438\u0441\u0442\u0435\u043c \u2014 \u043b\u043e\u0433\u0438\u0447\u043d\u0435\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u0434\u043b\u044f Java.<\/p>\n<p>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"plaintext\">syntax = &quot;proto2&quot;;  option java_multiple_files = true; package org.example.api;  message Person { \/\/\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043d\u0443\u0436\u043d\u044b\u043c\u0438 \u043d\u0430\u043c \u043f\u043e\u043b\u044f\u043c\u0438   required int32 id = 1; \/\/ \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u043f\u043e\u043b\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435   required string name = 2; \/\/ \u0438\u043c\u044f, \u043f\u043e\u043b\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435   optional int32 age = 3; \/\/ \u0432\u043e\u0437\u0440\u0430\u0441\u0442, \u043f\u043e\u043b\u0435 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 } <\/code><\/pre>\n<p>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u0441 \u0442\u0430\u043a\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c:<\/p>\n<pre><code class=\"java\">public interface PersonOrBuilder extends     \/\/ @@protoc_insertion_point(interface_extends:org.example.api.Person)     com.google.protobuf.MessageOrBuilder {     boolean hasId();   int getId();    boolean hasName();   java.lang.String getName();   com.google.protobuf.ByteString getNameBytes();    boolean hasAge();   int getAge(); } <\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043f\u043e\u0432\u0441\u044e\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b (\u0447\u0442\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0434\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438). \u041d\u043e \u043f\u043e\u043b\u0435 <b>age<\/b> \u0443 \u043d\u0430\u0441 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435, \u043d\u043e \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043c\u0435\u0435\u0442 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0418\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0438 \u043f\u043e\u0440\u0430\u0436\u0434\u0430\u0435\u0442 \u043a\u0443\u0447\u0443 boilerplate \u043a\u043e\u0434\u0430, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u0438 \u0431\u0443\u0434\u0435\u043c \u0431\u043e\u0440\u043e\u0442\u044c\u0441\u044f.<\/p>\n<pre><code class=\"java\">Integer johnAge = john.hasAge() ? john.getAge() : null; <\/code><\/pre>\n<p>  \u0410 \u0432\u0435\u0434\u044c \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c:<\/p>\n<pre><code class=\"java\">Integer johnAge = john.age().orElse(null); \/\/ \u0437\u0434\u0435\u0441\u044c age() - \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 Optional&lt;Integer&gt; <\/code><\/pre>\n<p>  Protocol Buffers \u0438\u043c\u0435\u0435\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e plugins, \u0438 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 Java, \u0447\u0442\u043e \u043c\u044b \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c.<\/p>\n<p>  \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f protobuf?<\/p>\n<p>  \u042d\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u044b\u0439 \u0444\u0430\u0439\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0438\u0442\u0430\u0435\u0442 \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 PluginProtos.CodeGeneratorRequest, \u043d\u0430 \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 PluginProtos.CodeGeneratorResponse \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0435\u0433\u043e \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0442\u043e\u043a.<\/p>\n<pre><code class=\"java\">public static void main(String[] args) throws IOException {         PluginProtos.CodeGeneratorRequest codeRequest = PluginProtos.CodeGeneratorRequest.parseFrom(System.in);         PluginProtos.CodeGeneratorResponse codeResponse;         try {             codeResponse = generate(codeRequest);         } catch (Exception e) {             codeResponse = PluginProtos.CodeGeneratorResponse.newBuilder()                     .setError(e.getMessage())                     .build();         }         codeResponse.writeTo(System.out);     } <\/code><\/pre>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0433\u0435\u043d\u0435\u043d\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c?<\/p>\n<p>  PluginProtos.CodeGeneratorResponse \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0430\u0431\u043e\u0440 PluginProtos.CodeGeneratorResponse.File.<br \/>  \u041a\u0430\u0436\u0434\u044b\u0439 \u00abfile\u00bb \u2014 \u044d\u0442\u043e \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e. \u041e\u043d \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437:<\/p>\n<pre><code class=\"plaintext\">String name; \/\/ \u0438\u043c\u044f \u0444\u0430\u0439\u043b\u0430, \u0437\u0434\u0435\u0441\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0435\u0433\u043e package String content; \/\/ \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430 String insertionPoint; \/\/ \u0422\u043e\u0447\u043a\u0430 \u0432\u0441\u0442\u0430\u0432\u043a\u0438 <\/code><\/pre>\n<p>  \u0421\u0430\u043c\u043e\u0435 \u0432\u0430\u0436\u043d\u043e\u0435 \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u0432 \u2014 \u043c\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0437\u0430\u043d\u043e\u0432\u043e \u2014 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <b>insertionPoint<\/b>. \u0415\u0441\u043b\u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443 \u0432\u044b\u0448\u0435 \u2014 \u043c\u044b \u0442\u0430\u043c \u0443\u0432\u0438\u0434\u0438\u043c:<\/p>\n<pre><code class=\"plaintext\"> \/\/ @@protoc_insertion_point(interface_extends:org.example.api.Person) <\/code><\/pre>\n<p>  \u0438\u043c\u0435\u043d\u043d\u043e \u0432 \u044d\u0442\u0438 \u043c\u0435\u0441\u0442\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u043a\u043e\u0434. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0434\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043a\u043b\u0430\u0441\u0441\u0430 \u0443 \u043d\u0430\u0441 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f. \u041e\u0442 \u044d\u0442\u043e\u0433\u043e \u0438 \u0431\u0443\u0434\u0435\u043c \u043e\u0442\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0442\u044c\u0441\u044f. \u041a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443? \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u043d\u043e\u0432\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441 default \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u2014 <\/p>\n<pre><code class=\"java\">public interface PersonOptional extends PersonOrBuilder {   default Optional&lt;Integer&gt; age() {     return hasAge() ? Optional.of(getAge()) : Optional.empty();   } } <\/code><\/pre>\n<p>  \u0430 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 Person \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e PersonOrBuilder, \u043d\u043e \u0438 PersonOptional<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041a\u043e\u0434 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043d\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">@Builder public class InterfaceWriter {      private static final Map&lt;DescriptorProtos.FieldDescriptorProto.Type, Class&lt;?&gt;&gt; typeToClassMap = ImmutableMap.&lt;DescriptorProtos.FieldDescriptorProto.Type, Class&lt;?&gt;&gt;builder()             .put(TYPE_DOUBLE, Double.class)             .put(TYPE_FLOAT, Float.class)             .put(TYPE_INT64, Long.class)             .put(TYPE_UINT64, Long.class)             .put(TYPE_INT32, Integer.class)             .put(TYPE_FIXED64, Long.class)             .put(TYPE_FIXED32, Integer.class)             .put(TYPE_BOOL, Boolean.class)             .put(TYPE_STRING, String.class)             .put(TYPE_UINT32, Integer.class)             .put(TYPE_SFIXED32, Integer.class)             .put(TYPE_SINT32, Integer.class)             .put(TYPE_SFIXED64, Long.class)             .put(TYPE_SINT64, Long.class)             .build();      private final String packageName;     private final String className;     private final List&lt;DescriptorProtos.FieldDescriptorProto&gt; fields;      public String getCode() {         List&lt;MethodSpec&gt; methods = fields.stream().map(field -&gt; {             ClassName fieldClass;             if (typeToClassMap.containsKey(field.getType())) {                 fieldClass = ClassName.get(typeToClassMap.get(field.getType()));             } else {                 int lastIndexOf = StringUtils.lastIndexOf(field.getTypeName(), '.');                 fieldClass = ClassName.get(field.getTypeName().substring(1, lastIndexOf), field.getTypeName().substring(lastIndexOf + 1));             }              return MethodSpec.methodBuilder(field.getName())                     .addModifiers(Modifier.DEFAULT, Modifier.PUBLIC)                     .returns(ParameterizedTypeName.get(ClassName.get(Optional.class), fieldClass))                     .addStatement(&quot;return has$N() ? $T.of(get$N()) : $T.empty()&quot;, capitalize(field.getName()), Optional.class, capitalize(field.getName()), Optional.class)                     .build();         }).collect(Collectors.toList());          TypeSpec generatedInterface = TypeSpec.interfaceBuilder(className + &quot;Optional&quot;)                 .addSuperinterface(ClassName.get(packageName, className + &quot;OrBuilder&quot;))                 .addModifiers(Modifier.PUBLIC)                 .addMethods(methods)                 .build();          return JavaFile.builder(packageName, generatedInterface).build().toString();     } } <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0435\u0440\u043d\u0435\u043c \u0438\u0437 \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/p>\n<pre><code class=\"java\"> PluginProtos.CodeGeneratorResponse.File.newBuilder() \/\/ \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u043d\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c InsertionPoint, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u0442\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b                     .setName(String.format(&quot;%s\/%sOptional.java&quot;, clazzPackage.replaceAll(&quot;\\\\.&quot;, &quot;\/&quot;), clazzName)) .setContent(InterfaceWriter.builder().packageName(clazzPackage).className(clazzName).fields(optionalFields).build().getCode())                     .build();  PluginProtos.CodeGeneratorResponse.File.newBuilder()                             .setName(String.format(&quot;%s\/%s.java&quot;, clazzPackage.replaceAll(&quot;\\\\.&quot;, &quot;\/&quot;), clazzName))                             .setInsertionPoint(String.format(&quot;message_implements:%s.%s&quot;, clazzPackage, clazzName)) \/\/ \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0437\u0430\u0434\u0430\u0435\u043c \u043c\u0435\u0441\u0442\u043e - \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f message - \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u043c\u0443 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043d\u043e\u0432\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430                             .setContent(String.format(&quot; %s.%sOptional, &quot;, clazzPackage, clazzName))                             .build(), <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u043d\u043e\u0432\u044b\u0439 \u043f\u043b\u0430\u0433\u0438\u043d? \u2014 \u0447\u0435\u0440\u0435\u0437 maven, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0438 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u043d\u0430\u0448 \u043f\u043b\u0430\u0433\u0438\u043d:<\/p>\n<pre><code class=\"xml\">&lt;plugin&gt;                 &lt;groupId&gt;org.xolstice.maven.plugins&lt;\/groupId&gt;                 &lt;artifactId&gt;protobuf-maven-plugin&lt;\/artifactId&gt;                 &lt;version&gt;0.6.1&lt;\/version&gt;                 &lt;extensions&gt;true&lt;\/extensions&gt;                 &lt;configuration&gt;                     &lt;pluginId&gt;java8&lt;\/pluginId&gt;                     &lt;protoSourceRoot&gt;${basedir}\/src\/main\/proto&lt;\/protoSourceRoot&gt;                     &lt;protocPlugins&gt;                         &lt;protocPlugin&gt;                             &lt;id&gt;java8&lt;\/id&gt;                             &lt;groupId&gt;org.example.protobuf&lt;\/groupId&gt;                             &lt;artifactId&gt;optional-plugin&lt;\/artifactId&gt;                             &lt;version&gt;1.0-SNAPSHOT&lt;\/version&gt;                             &lt;mainClass&gt;org.example.proto2plugin.OptionalPlugin&lt;\/mainClass&gt;                         &lt;\/protocPlugin&gt;                     &lt;\/protocPlugins&gt;                 &lt;\/configuration&gt;             &lt;\/plugin&gt; <\/code><\/pre>\n<p>  \u041d\u043e \u043c\u043e\u0436\u043d\u043e \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0435\u0433\u043e \u0438\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u2014 \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0448 \u043f\u043b\u0430\u0433\u0438\u043d, \u0430 \u043f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u043d\u044b\u0439 java \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 (\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 \u0444\u0430\u0439\u043b \u2014 protoc-gen-java8 (\u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0441\u0442\u043e bash-\u0441\u043a\u0440\u0438\u043f\u0442).<\/p>\n<pre><code class=\"bash\">protoc -I=.\/src\/main\/resources\/ --java_out=.\/src\/main\/java\/  --java8_out=.\/src\/main\/java\/ .\/src\/main\/resources\/example.proto  <\/code><\/pre>\n<p>  \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/github.com\/LyubinskiyPavel\/proto2-optional\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/510310\/\"> https:\/\/habr.com\/ru\/post\/510310\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/510310\/\">\u0415\u0441\u043b\u0438 \u0432\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0435 \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e \u0432\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u043c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 Protoloc Buffers \u043e\u0442 Google. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0435\u0433\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438. \u0418 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e boilerplate \u043a\u043e\u0434\u0430, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u0438 \u0431\u0443\u0434\u0435\u043c \u0431\u043e\u0440\u043e\u0442\u044c\u0441\u044f.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-306693","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/306693","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=306693"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/306693\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=306693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=306693"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=306693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}