bhalchandrap commented on a change in pull request #2439:
URL: https://github.com/apache/thrift/pull/2439#discussion_r706958817



##########
File path: lib/java/src/org/apache/thrift/partial/PartialThriftDeserializer.java
##########
@@ -0,0 +1,337 @@
+/*
+ * 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.thrift.partial;
+
+import org.apache.thrift.partial.Validate;
+
+import org.apache.thrift.TBase;
+import org.apache.thrift.TEnum;
+import org.apache.thrift.TException;
+import org.apache.thrift.TFieldIdEnum;
+import org.apache.thrift.meta_data.EnumMetaData;
+import org.apache.thrift.meta_data.StructMetaData;
+import org.apache.thrift.protocol.TList;
+import org.apache.thrift.protocol.TMap;
+import org.apache.thrift.protocol.TSet;
+import org.apache.thrift.protocol.TType;
+
+/**
+ * Supports partial deserialization of serialized Thrift data.
+ *
+ * The end result of deserialization can be a Thrift object (? extends TBase)
+ * or it could be a different construct. It is achieved by using a
+ * ThriftFieldValueProcessor instance which processes each field value
+ * as it gets deserialized.
+ */
+public class PartialThriftDeserializer<T extends TBase> {
+
+  // Metadata that describes fields to deserialize.
+  private final ThriftMetadata.ThriftStruct metadata;
+
+  // Processor that handles deserialized field values.
+  private final ThriftFieldValueProcessor processor;
+
+  // Partial thrift protocol to use for deserialization.
+  private final PartialThriftProtocol protocol;
+
+  /**
+   * Constructs an instance of PartialThriftDeserializer.
+   *
+   * @param metadata the Metadata that describes fields to deserialize.
+   * @param processor the Processor that handles deserialized field values.
+   * @param protocol the Partial thrift protocol to use for deserialization.
+   */
+  public PartialThriftDeserializer(
+      ThriftMetadata.ThriftStruct metadata,
+      ThriftFieldValueProcessor processor,
+      PartialThriftProtocol protocol) {
+
+    Validate.checkNotNull(metadata, "metadata");
+    Validate.checkNotNull(processor, "processor");
+    Validate.checkNotNull(protocol, "protocol");
+
+    this.metadata = metadata;
+    this.processor = processor;
+    this.protocol = protocol;
+  }
+
+  /**
+   * Gets the Thrift metadata used by this instance.
+   */
+  public ThriftMetadata.ThriftStruct getMetadata() {
+    return this.metadata;
+  }
+
+  /**
+   * Deserializes the given serialized blob.
+   *
+   * @param bytes the serialized blob.
+   * @return deserialized instance.
+   * @throws TException if an error is encountered during deserialization.
+   */
+  public Object deserialize(byte[] bytes) throws TException {

Review comment:
       Hi @fishy, 
   Happy to make changes if I get clarity on the concerns you have and on the 
type of changes you are looking for. 
   
   Based on your comments I believe you prefer adding functionality to existing 
interfaces instead of adding new ones (please confirm since this is my guess). 
If so, how does the following work for you?
   
   1. move common skip*() methods from PartialThriftProtocol.java to 
TProtocol.java.
   2. move encoding specific skip*() methods from PartialThrift*Protocol.java 
to T*Protocol (for example, from PartialThriftBinaryProtocol.java to 
TBinaryProtocol)
   3. get rid of PartialThriftDeserializer.java and add its methods to 
TDeserializer
   
   Would something like the above address your concerns?




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