pandaapo commented on code in PR #4408:
URL: https://github.com/apache/eventmesh/pull/4408#discussion_r1307100991


##########
eventmesh-connectors/eventmesh-connector-pravega/src/main/java/org/apache/eventmesh/connector/pravega/client/PravegaEvent.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.eventmesh.connector.pravega.client;
+
+import org.apache.eventmesh.common.utils.JsonUtils;
+import 
org.apache.eventmesh.connector.pravega.exception.PravegaConnectorException;
+
+import java.io.Serializable;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+
+import io.cloudevents.CloudEvent;
+import io.cloudevents.SpecVersion;
+import io.cloudevents.core.builder.CloudEventBuilder;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+public class PravegaEvent implements Serializable {
+
+    private static final long serialVersionUID = 0L;
+
+    private SpecVersion version;
+    private String topic;
+    private String data;
+    private Map<String, String> extensions = new HashMap<>();
+    private long createTimestamp;
+
+    public static byte[] toByteArray(PravegaEvent pravegaEvent) {
+        return 
JsonUtils.toJSONString(pravegaEvent).getBytes(StandardCharsets.UTF_8);
+    }
+
+    public static PravegaEvent getFromByteArray(byte[] body) {
+        return JsonUtils.parseObject(new String(body, StandardCharsets.UTF_8), 
PravegaEvent.class);
+    }
+
+    public CloudEvent convertToCloudEvent() throws Exception {
+        CloudEventBuilder builder;
+        switch (version) {
+            case V03:
+                builder = CloudEventBuilder.v03();
+                break;
+            case V1:
+                builder = CloudEventBuilder.v1();
+                break;
+            default:
+                throw new PravegaConnectorException(String.format("CloudEvent 
version %s does not support.", version));
+        }

Review Comment:
   Using `CloudEventBuilder#fromSpecVersion(SpecVersion version)` will be more 
concise.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to