lukecwik commented on a change in pull request #12806: URL: https://github.com/apache/beam/pull/12806#discussion_r491178237
########## File path: sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubMessageUtils.java ########## @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.sdk.io.gcp.pubsub; + +import com.google.protobuf.ByteString; +import com.google.protobuf.InvalidProtocolBufferException; +import java.util.Map; +import org.apache.beam.sdk.transforms.SerializableFunction; + +/** Common util functions for converting between PubsubMessage proto and {@link PubsubMessage}. */ +public class PubsubMessageUtils { Review comment: nit: rename classes to `PubsubMessages` ########## File path: sdks/python/apache_beam/io/gcp/pubsub.py ########## @@ -290,21 +290,26 @@ def __init__(self, topic, id_label, with_attributes, timestamp_attribute) @staticmethod - def to_proto_str(element): + def message_to_proto_str(element): # type: (PubsubMessage) -> bytes if not isinstance(element, PubsubMessage): raise TypeError( 'Unexpected element. Type: %s (expected: PubsubMessage), ' 'value: %r' % (type(element), element)) return element._to_proto_str() + @staticmethod + def bytes_to_proto_str(element): + # type: (bytes) -> bytes + msg = pubsub.types.pubsub_pb2.PubsubMessage() + msg.data = element + return msg.SerializeToString() + def expand(self, pcoll): if self.with_attributes: Review comment: Using the Write transform that consumes the Pubsub proto after formatting should be the well known transform represented by the PubSubWritePayload and not the WriteToPubSub transform as it contains an ambiguous input type. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
