From 8e4277f7187130d994e0e628c810e83d3af3bd9e Mon Sep 17 00:00:00 2001 From: Tianzi Cai Date: Thu, 25 Feb 2021 09:51:27 -0800 Subject: [PATCH] samples: add some comments (#538) * samples: add some comments * skil line length check in generated file * shorten paths --- samples/checkstyle-suppressions.xml | 2 +- .../main/java/pubsub/CreateAvroSchemaExample.java | 2 +- .../main/java/pubsub/PublishAvroRecordsExample.java | 2 +- .../java/pubsub/PublishProtobufMessagesExample.java | 2 +- samples/snippets/src/main/java/utilities/State.java | 12 ++++++++++++ .../snippets/src/main/java/utilities/StateProto.java | 11 +++++++++++ 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/samples/checkstyle-suppressions.xml b/samples/checkstyle-suppressions.xml index c1ab01fe8..2d134a8c2 100644 --- a/samples/checkstyle-suppressions.xml +++ b/samples/checkstyle-suppressions.xml @@ -30,5 +30,5 @@ - + \ No newline at end of file diff --git a/samples/snippets/src/main/java/pubsub/CreateAvroSchemaExample.java b/samples/snippets/src/main/java/pubsub/CreateAvroSchemaExample.java index 7e340cd29..1b93b7fbe 100644 --- a/samples/snippets/src/main/java/pubsub/CreateAvroSchemaExample.java +++ b/samples/snippets/src/main/java/pubsub/CreateAvroSchemaExample.java @@ -54,7 +54,7 @@ public static void createAvroSchemaExample(String projectId, String schemaId, St projectName, Schema.newBuilder() .setName(schemaName.toString()) - .setType(com.google.pubsub.v1.Schema.Type.AVRO) + .setType(Schema.Type.AVRO) .setDefinition(avscSource) .build(), schemaId); diff --git a/samples/snippets/src/main/java/pubsub/PublishAvroRecordsExample.java b/samples/snippets/src/main/java/pubsub/PublishAvroRecordsExample.java index 0bfed04e5..aa7d571c9 100644 --- a/samples/snippets/src/main/java/pubsub/PublishAvroRecordsExample.java +++ b/samples/snippets/src/main/java/pubsub/PublishAvroRecordsExample.java @@ -56,7 +56,7 @@ public static void publishAvroRecordsExample(String projectId, String topicId) encoding = topicAdminClient.getTopic(topicName).getSchemaSettings().getEncoding(); } - // Create an object of an avro-tools-generated class. + // Instantiate an avro-tools-generated class defined in `us-states.avsc`. State state = State.newBuilder().setName("Alaska").setPostAbbr("AK").build(); Publisher publisher = null; diff --git a/samples/snippets/src/main/java/pubsub/PublishProtobufMessagesExample.java b/samples/snippets/src/main/java/pubsub/PublishProtobufMessagesExample.java index c1cdba1d7..b08682e3f 100644 --- a/samples/snippets/src/main/java/pubsub/PublishProtobufMessagesExample.java +++ b/samples/snippets/src/main/java/pubsub/PublishProtobufMessagesExample.java @@ -56,7 +56,7 @@ public static void publishProtobufMessagesExample(String projectId, String topic Publisher publisher = null; - // Create an object of an avro-tools-generated class. + // Instantiate a protoc-generated class defined in `us-states.proto`. State state = State.newBuilder().setName("Alaska").setPostAbbr("AK").build(); block: diff --git a/samples/snippets/src/main/java/utilities/State.java b/samples/snippets/src/main/java/utilities/State.java index a3d837e85..87ce59223 100644 --- a/samples/snippets/src/main/java/utilities/State.java +++ b/samples/snippets/src/main/java/utilities/State.java @@ -19,6 +19,18 @@ * *

DO NOT EDIT DIRECTLY */ + +/** + * This file is created using Avro tools. + * + * To download, visit https://avro.apache.org/releases.html#Download + * + * Run the following command from the `samples/snippets` directory to + * generate this class: + * + *`java -jar /location/to/your/avro-tools-1.10.1.jar compile schema src/main/resources/us-states.avsc src/main/java/` + */ + package utilities; import org.apache.avro.message.BinaryMessageDecoder; diff --git a/samples/snippets/src/main/java/utilities/StateProto.java b/samples/snippets/src/main/java/utilities/StateProto.java index 7afab1ca2..be57ce7b7 100644 --- a/samples/snippets/src/main/java/utilities/StateProto.java +++ b/samples/snippets/src/main/java/utilities/StateProto.java @@ -17,6 +17,17 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: us-states.proto +/** + * This file is created using protoc. + * + * To download, visit https://developers.google.com/protocol-buffers/docs/downloads + * + * Run the following command from the `samples/snippets` directory to + * generate this class: + * + *`protoc --proto_path=src/main/resources/ --java_out=src/main/java/ src/main/resources/us-states.proto` + */ + package utilities; public final class StateProto {