eldenmoon commented on code in PR #51766:
URL: https://github.com/apache/doris/pull/51766#discussion_r2160616270


##########
be/src/util/jsonb_document.h:
##########
@@ -587,315 +650,213 @@ class JsonbValue {
     //Whether to include the jsonbvalue rhs
     bool contains(JsonbValue* rhs) const;
 
-    // get the raw byte array of the value
-    const char* getValuePtr() const;
-
     // find the JSONB value by JsonbPath
     JsonbValue* findValue(JsonbPath& path, hDictFind handler);
     friend class JsonbDocument;
 
-protected:
-    JsonbType type_; // type info
-
-    JsonbValue();
+    JsonbType type; // type info
+
+    char payload[0]; // payload, which is the packed bytes of the value
+
+    /**
+    * @brief Unpacks the underlying Jsonb binary content as a pointer to type 
`T`.
+    *
+    * @tparam T A POD (Plain Old Data) type that must satisfy the 
`JsonbPodType` concept.
+    *           This ensures that `T` is trivially copyable, standard-layout, 
and safe to
+    *           reinterpret from raw bytes without invoking undefined behavior.
+    *
+    * @return A pointer to a `const T` object, interpreted from the internal 
buffer.
+    *
+    * @note The caller must ensure that the current JsonbValue actually 
contains data
+    *       compatible with type `T`, otherwise the result is undefined.
+    */
+    template <JsonbPodType T>
+    const T* unpack() const {
+        static_assert(is_pod_v<T>, "T must be a POD type");
+        return reinterpret_cast<const T*>(payload);
+    }
+
+    // /**
+    // * @brief Unpacks the underlying Jsonb binary content as a pointer to 
type `T`.

Review Comment:
   useless code?



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