xml binary internal support & code optimize
This commit is contained in:
18
deps/oblib/src/common/object/ob_object.h
vendored
18
deps/oblib/src/common/object/ob_object.h
vendored
@ -1062,24 +1062,6 @@ public:
|
|||||||
bool has_lob_header_; // for observer 4.0 compatibility
|
bool has_lob_header_; // for observer 4.0 compatibility
|
||||||
};
|
};
|
||||||
|
|
||||||
// mock xml binary header for test;
|
|
||||||
class ObMockXmlBinHeader {
|
|
||||||
public:
|
|
||||||
ObMockXmlBinHeader(bool is_unparsed, bool is_document) :
|
|
||||||
is_unparsed_(is_unparsed), is_document_(is_document), reserved_(0) {}
|
|
||||||
~ObMockXmlBinHeader(){};
|
|
||||||
|
|
||||||
TO_STRING_KV(K_(is_unparsed), K_(is_document), K_(reserved));
|
|
||||||
union {
|
|
||||||
uint32_t flag_;
|
|
||||||
struct {
|
|
||||||
uint32_t is_unparsed_: 1;
|
|
||||||
uint32_t is_document_: 1;
|
|
||||||
uint32_t reserved_: 30;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ObObjPrintParams
|
struct ObObjPrintParams
|
||||||
{
|
{
|
||||||
ObObjPrintParams (const ObTimeZoneInfo *tz_info, ObCollationType cs_type):
|
ObObjPrintParams (const ObTimeZoneInfo *tz_info, ObCollationType cs_type):
|
||||||
|
|||||||
@ -87,7 +87,7 @@ int ObStringBuffer::append(const ObString &str)
|
|||||||
int ObStringBuffer::reserve(const uint64_t len)
|
int ObStringBuffer::reserve(const uint64_t len)
|
||||||
{
|
{
|
||||||
INIT_SUCC(ret);
|
INIT_SUCC(ret);
|
||||||
const uint64_t need_size = len_ + len + 1; // 1 more byte for C terminating null byte ('\0')
|
const uint64_t need_size = len_ + len + 8; // 1 more byte for C terminating null byte ('\0')
|
||||||
static const uint64_t BIT_PER_BYTE = 8;
|
static const uint64_t BIT_PER_BYTE = 8;
|
||||||
if (OB_ISNULL(allocator_)) {
|
if (OB_ISNULL(allocator_)) {
|
||||||
ret = OB_ERR_NULL_VALUE;
|
ret = OB_ERR_NULL_VALUE;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -2161,7 +2161,7 @@ TEST_F(TestXmlParser, test_ns_attr_simple)
|
|||||||
ASSERT_EQ(ObMulModeNodeType::M_ELEMENT, root_node->type());
|
ASSERT_EQ(ObMulModeNodeType::M_ELEMENT, root_node->type());
|
||||||
ObXmlElement* root = dynamic_cast<ObXmlElement*>(root_node);
|
ObXmlElement* root = dynamic_cast<ObXmlElement*>(root_node);
|
||||||
ASSERT_EQ(1, root->size());
|
ASSERT_EQ(1, root->size());
|
||||||
ASSERT_EQ(2, root->attributes_size());
|
ASSERT_EQ(2, root->attribute_size());
|
||||||
|
|
||||||
// check root attrs
|
// check root attrs
|
||||||
ObXmlAttribute* attr1 = NULL;
|
ObXmlAttribute* attr1 = NULL;
|
||||||
@ -2213,7 +2213,7 @@ TEST_F(TestXmlParser, test_ns_attr_before_simple)
|
|||||||
ASSERT_EQ(ObMulModeNodeType::M_ELEMENT, root_node->type());
|
ASSERT_EQ(ObMulModeNodeType::M_ELEMENT, root_node->type());
|
||||||
ObXmlElement* root = dynamic_cast<ObXmlElement*>(root_node);
|
ObXmlElement* root = dynamic_cast<ObXmlElement*>(root_node);
|
||||||
ASSERT_EQ(1, root->size());
|
ASSERT_EQ(1, root->size());
|
||||||
ASSERT_EQ(2, root->attributes_size());
|
ASSERT_EQ(2, root->attribute_size());
|
||||||
|
|
||||||
// check root attrs
|
// check root attrs
|
||||||
ObXmlAttribute* attr1 = NULL;
|
ObXmlAttribute* attr1 = NULL;
|
||||||
@ -2263,7 +2263,7 @@ TEST_F(TestXmlParser, test_ns_default_elem)
|
|||||||
ObXmlNode* root_node = doc->at(0);
|
ObXmlNode* root_node = doc->at(0);
|
||||||
ASSERT_EQ(ObMulModeNodeType::M_ELEMENT, root_node->type());
|
ASSERT_EQ(ObMulModeNodeType::M_ELEMENT, root_node->type());
|
||||||
ObXmlElement* root = dynamic_cast<ObXmlElement*>(root_node);
|
ObXmlElement* root = dynamic_cast<ObXmlElement*>(root_node);
|
||||||
ASSERT_EQ(2, root->attributes_size());
|
ASSERT_EQ(2, root->attribute_size());
|
||||||
ASSERT_EQ(1, root->size());
|
ASSERT_EQ(1, root->size());
|
||||||
|
|
||||||
// check root attrs
|
// check root attrs
|
||||||
|
|||||||
@ -173,7 +173,7 @@ TEST_F(TestXmlNodeBase, test_xml_node_element_add_child)
|
|||||||
element1.set_ns(&ns);
|
element1.set_ns(&ns);
|
||||||
element1.set_prefix(ns.get_key());
|
element1.set_prefix(ns.get_key());
|
||||||
ASSERT_EQ(element1.size(), 2);
|
ASSERT_EQ(element1.size(), 2);
|
||||||
ASSERT_EQ(element1.attributes_size(), 1);
|
ASSERT_EQ(element1.attribute_size(), 1);
|
||||||
element1.update_attribute(&attr2, 0);
|
element1.update_attribute(&attr2, 0);
|
||||||
// ASSERT_EQ(element1.get_attribute().at(0).get_value(), "sttr2_value");
|
// ASSERT_EQ(element1.get_attribute().at(0).get_value(), "sttr2_value");
|
||||||
ObString key_res1;
|
ObString key_res1;
|
||||||
@ -676,7 +676,7 @@ TEST_F(TestXmlNodeBase, test_xml_node_element_add_well_from)
|
|||||||
ASSERT_EQ(ObMulModeNodeType::M_ELEMENT, element1.type());
|
ASSERT_EQ(ObMulModeNodeType::M_ELEMENT, element1.type());
|
||||||
ObString emelent1= "emelent1";
|
ObString emelent1= "emelent1";
|
||||||
ObString emelent2= "emelent2";
|
ObString emelent2= "emelent2";
|
||||||
ASSERT_EQ(content.attributes_size(), 0);
|
ASSERT_EQ(content.attribute_size(), 0);
|
||||||
element1.set_key(emelent1);
|
element1.set_key(emelent1);
|
||||||
element2.set_key(emelent2);
|
element2.set_key(emelent2);
|
||||||
ASSERT_EQ(element1.get_key(), "emelent1");
|
ASSERT_EQ(element1.get_key(), "emelent1");
|
||||||
@ -699,7 +699,7 @@ TEST_F(TestXmlNodeBase, test_xml_node_element_add_well_from)
|
|||||||
element1.add_attribute(&attr1);
|
element1.add_attribute(&attr1);
|
||||||
element2.add_attribute(&attr1);
|
element2.add_attribute(&attr1);
|
||||||
ASSERT_EQ(element1.size(), 2);
|
ASSERT_EQ(element1.size(), 2);
|
||||||
ASSERT_EQ(element1.attributes_size(), 1);
|
ASSERT_EQ(element1.attribute_size(), 1);
|
||||||
|
|
||||||
comment.set_text(cdata1);
|
comment.set_text(cdata1);
|
||||||
int res = cdata.compare(cdata1, res);
|
int res = cdata.compare(cdata1, res);
|
||||||
|
|||||||
@ -83,8 +83,8 @@ public:
|
|||||||
|
|
||||||
virtual ~TXmlNodeBase() {}
|
virtual ~TXmlNodeBase() {}
|
||||||
|
|
||||||
int64_t size() const { return ObLibContainerNode::size(); }
|
int64_t size() { return ObLibContainerNode::size(); }
|
||||||
int64_t count() const { return size(); }
|
int64_t count() { return size(); }
|
||||||
|
|
||||||
const common::ObString& get_key()
|
const common::ObString& get_key()
|
||||||
{
|
{
|
||||||
@ -99,6 +99,10 @@ public:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_ns_value(ObString &ns_value) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int get_value(ObString& value, int64_t index = -1) override
|
int get_value(ObString& value, int64_t index = -1) override
|
||||||
{
|
{
|
||||||
INIT_SUCC(ret);
|
INIT_SUCC(ret);
|
||||||
@ -111,6 +115,8 @@ public:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_standalone(uint16_t standalone) { }
|
||||||
|
|
||||||
// 用于确定key是否匹配
|
// 用于确定key是否匹配
|
||||||
int compare(const ObString& key, int& res) {
|
int compare(const ObString& key, int& res) {
|
||||||
UNUSED(key);
|
UNUSED(key);
|
||||||
@ -118,6 +124,16 @@ public:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual int64_t attribute_size() { return 0; }
|
||||||
|
virtual int64_t attribute_count() { return 0; }
|
||||||
|
ObString get_version() { return ObString(); }
|
||||||
|
ObString get_prefix() { return ObString(); }
|
||||||
|
ObString get_encoding() { return ObString(); }
|
||||||
|
uint16_t get_standalone() { return 0; }
|
||||||
|
ObIMulModeBase* attribute_at(int64_t pos) { return nullptr; }
|
||||||
|
bool has_flags(ObMulModeNodeFlag flag) { return false; }
|
||||||
|
bool get_unparse() { return false; }
|
||||||
|
bool get_is_empty() { return false; }
|
||||||
// 返回节点具体类型
|
// 返回节点具体类型
|
||||||
// 例如:json返回jsonInt,jsonDouble
|
// 例如:json返回jsonInt,jsonDouble
|
||||||
// xml 返回xmlElment, XmlAttribute
|
// xml 返回xmlElment, XmlAttribute
|
||||||
|
|||||||
@ -203,7 +203,7 @@ int ObXmlTreeTextWriter::visit_xml_element(ObXmlElement* node) {
|
|||||||
buffer_.append("<");
|
buffer_.append("<");
|
||||||
append_qname(node->get_prefix(), node->get_key());
|
append_qname(node->get_prefix(), node->get_key());
|
||||||
|
|
||||||
for (int i = 0; OB_SUCC(ret) && i < node->attributes_size(); ++i) {
|
for (int i = 0; OB_SUCC(ret) && i < node->attribute_size(); ++i) {
|
||||||
ObXmlAttribute* attr = NULL;
|
ObXmlAttribute* attr = NULL;
|
||||||
if (OB_FAIL(node->get_attribute(attr, i))) {
|
if (OB_FAIL(node->get_attribute(attr, i))) {
|
||||||
LOG_WARN("get attr failed", K(ret), K(i));
|
LOG_WARN("get attr failed", K(ret), K(i));
|
||||||
|
|||||||
Reference in New Issue
Block a user