joewitt commented on code in PR #7830:
URL: https://github.com/apache/nifi/pull/7830#discussion_r1343465307


##########
nifi-nar-bundles/nifi-opentelemetry-bundle/nifi-opentelemetry-processors/src/main/java/org/apache/nifi/processors/opentelemetry/encoding/JsonServiceRequestReader.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.nifi.processors.opentelemetry.encoding;
+
+import com.google.protobuf.Message;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+
+/**
+ * Service Request Reader implementation based on JSON Parser supporting 
standard OTLP Request Types
+ */
+public class JsonServiceRequestReader implements ServiceRequestReader {
+    private static final RequestMapper REQUEST_MAPPER = new 
StandardRequestMapper();
+
+    /**
+     * Read Service Request parsed from Buffer
+     *
+     * @param buffer Byte Buffer
+     * @param requestType Request Message Type
+     * @return Service Request read
+     */
+    @Override
+    public <T extends Message> T read(final ByteBuffer buffer, final Class<T> 
requestType) {
+        Objects.requireNonNull(buffer, "Buffer required");
+        final byte[] bytes = getBytes(buffer);
+
+        try {
+            return REQUEST_MAPPER.readValue(bytes, requestType);

Review Comment:
   This request mapper seems to be our code and if so would we not be better 
off passing the byte buffer itself rather than an intermediate copy of the 
contents of the buffer?  I followed the call chain and it seems like we're free 
to use the buffer as is but I might not know the total ownership/lifecycle of 
the byte buffer.  If true though saving on the byte buffer extra copy at 
processing rate would add up.



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

Reply via email to