Git Product home page Git Product logo

xpack's People

Contributors

freehawkzk avatar gongxiangshun avatar kevin-ren97 avatar willkk avatar xiezhaokai avatar xyz347 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xpack's Issues

含转义符 string encode结果格式错误

elidedText 字段原文: ヽ市キ華虐蒙i川 鯨 | 根据 《幼ブL\n‐\ぷ弄始吋同: | 九、写―写。 | 替\niSBヽ 978-7-53,4-6579
Encode 结果:
{
"elidedText": "ヽ市キ華虐蒙i川 鯨 | 根据 《幼ブL\n‐\ぷ弄始吋同: | 九、写―写。 | 替\niSBヽ 978-7-53,4-6579"
}
错误: 转义符未进行处理
修复:
writer.h 442行添加
else if (escape[static_cast(c)] == '\') {
PutUnsafe(*os_, '\');
}

结构体重命名

项目主页上介绍了怎么对结构体的成员变量重命名 那是否可以对结构体重命名呢

struct TimeSpan
{
    string startTime;
    string endTime;
    XPACK(O(startTime, endTime));
};
struct CMSearchDescription
{
    string           searchID;
    vector<TimeSpan> timeSpanList;
    XPACK(O(searchID, timeSpanList))
};

在最后的xml中,结构体TimeSpan对应的是timeSpan标签,我又不想在代码中将结构体名改为timeSpan,有什么办法吗

发布下新版本可以吗

您好,非常感谢技术的沟通,在支持pcdata后,能发布一个新版本吗,因为我是通过conan来引用的xpack库,但是最新的1.0.5的版本还没有master上的功能呢

空数组出错

json文本为:{"data":{"info":[]}}时,解析会出错。在document.h的IsArray出错。
struct Info
{
int base, Id;
XPACK(O(base, Id));
};
struct dataInfo
{
std::vector data;
XPACK(O(data));
};
dataInfo sInfo;
xpack::json::decode("{"data":{"info":[]}}", sInfo);

容器限制

为什么没在设计中看到有关于容器限制相关,实际生产中一些string stl等 异常报文也是要重点考虑的呢

Silent error with overflowed integer

Hello,

Thanks for this great library. While using it, I encounterd an error with overflowed integer. I was able to reproduce this on json-data.cpp with a large integer.

* limitations under the License.
*/

#include <iostream>
#include "xpack/json.h"
#include <string>

using namespace std;

struct Example {
    string type;
    xpack::JsonData data;
    XPACK(O(type, data));
};

struct Range {
    int min;
    int max;
    XPACK(O(min, max));
};

struct User {
    int id;
    string name;
    XPACK(O(id, name));
};

static void test(const std::string &data) {
    Example e;
    xpack::json::decode(data, e);
    if (e.type == "range") {
        Range r;
        e.data.Get(r);
    } else if (e.type == "user") {
	User u;
	e.data.Get(u);
	cout << u.id << endl;
    } else {

    }

}

int main(int argc, char *argv[]) {
    (void)argc;
    (void)argv;

    string s1 = "{\"type\":\"range\", \"data\":{\"min\":12, \"max\":33}}";
    string s2 = "{\"type\":\"user\", \"data\":{\"id\":123344343434343435, \"name\":\"xpack\"}}";
    test(s1);
    test(s2);
    
    return 0;
}

With a large number in the id of s2, no error was reported (I tried with a larger number and an error indicting not integer is given, which I think should be the correct behavior), but the output is -545967093.

I'm using the latest version of the library on Ubuntu 20.04LTS.

请教一个继承的问题

两个struct属继承关系

struct A {
    string t1;
    XPACK(O(t1));
};

struct B : public A{
    string t2;
    XPACK(I(A), O(t2));
};

现在我有一个函数,接受的是A类型,但传递的是B类型,转成JSON字符串后B类型的数据丢了?

VOID invoke(A a)
{
    string data = xpack::json::encode(a); // data 没有 t2 ?
}

B b = {0};
b.t1 = "111";
b.t2 = "222";

invoke(b);

能否加一下xpack::json::decode(rapidjson::Value*, T&)

json.h中有decode(std::string&, T&),可以满足字符串到对象的解析。但在实际应用中,可能需要对复杂结构体中的部分Value对象解析到Object中。参考现有代码,加起来应该比较简单,比如:

    template <class T>
    static void decode(const rapidjson::Value* value_data, T &val) {
        JsonDecoder doc(value_data);
        doc.decode(NULL, val, NULL);
    }

enum class Enum : int64_t解析会出错

enum class Enum : int64_t 类型的枚举解析会出错,解析出来是个很大的值, 如果是enum class Enum : int 不会出错,是哪里的bug 吗

XPACK_OUT解析过大结构体时出现段错误

目前是将xpack的解析json功能用于构造测试用例。代码中有一个结构体比较大,有3892616byte,在执行用例的时候出现了段错误。尝试减少结构体成员个数,发现3568232byte可以正常运行,但是目前不知道明确的边界。
这个结构体之前在ut测试中一直存在,区别只是第一次将其放到了json文件中,所以怀疑是不是xpack哪个地方产生了对结构体大小的限制。

clang 16.0.0-x86_64-pc-windows-msvc下编译不过

问题如题.
在windows下,使用 clang 16.0.0-x86_64-pc-windows-msvc编译报错.
报错信息如下:

[build] 正在启动生成
[proc] 执行命令: chcp
[proc] 执行命令: "D:\Program Files\CMake\bin\cmake.EXE" --build d:/temp/xpack-clang/build --config Debug --target all --
[build] [1/2  50% :: 0.683] Building CXX object CMakeFiles/xpack-clang.dir/main.cpp.obj
[build] FAILED: CMakeFiles/xpack-clang.dir/main.cpp.obj 
[build] C:\LLVM\bin\clang++.exe  -ID:/temp/xpack-clang/include/xpack -g -Xclang -gcodeview -O0 -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -MD -MT CMakeFiles/xpack-clang.dir/main.cpp.obj -MF CMakeFiles\xpack-clang.dir\main.cpp.obj.d -o CMakeFiles/xpack-clang.dir/main.cpp.obj -c D:/temp/xpack-clang/main.cpp
[build] D:/temp/xpack-clang/main.cpp:9:3: error: use of undeclared identifier 'X_PACK_L1_ENCODE'
[build]   XPACK(M(age, name));
[build]   ^
[build] D:/temp/xpack-clang/include/xpack/xpack.h:191:45: note: expanded from macro 'XPACK'
[build]     X_PACK_ENCODE_BEGIN X_PACK_N(X_PACK_L1, X_PACK_L1_ENCODE, __VA_ARGS__) return __x_pack_ret; }
[build]                                             ^
[build] D:/temp/xpack-clang/include/xpack/xencoder.h:150:16: note: in instantiation of function template specialization 'xpack::XEncoder<xpack::JsonWriter>::encode_struct<person>' requested here
[build]         return encode_struct(key, val, ext);
[build]                ^
[build] D:/temp/xpack-clang/include/xpack/json_encoder.h:273:12: note: in instantiation of function template specialization 'xpack::XEncoder<xpack::JsonWriter>::encode<person>' requested here
[build]         en.encode(NULL, val, NULL);
[build]            ^
[build] D:/temp/xpack-clang/include/xpack\json.h:50:19: note: in instantiation of function template specialization 'xpack::JsonEncoder::encode<person>' requested here
[build]         return en.encode(val);
[build]                   ^
[build] D:/temp/xpack-clang/main.cpp:17:29: note: in instantiation of function template specialization 'xpack::json::encode<person>' requested here
[build]   std::cout << xpack::json::encode(p) << std::endl;
[build]                             ^
[build] 1 error generated.
[build] ninja: build stopped: subcommand failed.
[proc] 命令“"D:\Program Files\CMake\bin\cmake.EXE" --build d:/temp/xpack-clang/build --config Debug --target all --”已退出,代码为 1
[driver] 生成完毕: 00:00:00.753
[build] 生成已完成,退出代码为 1

xpack.h中vscode显示该宏X_PACK_L1_ENCODE是启用的 请问该如何解决?

customize basetype's serialisation

Dear developer,
How could I do if I wanna to customize basetype's serialisation? For example, if I want to convert an int to its hex string representation during serialize or deserialize, current xtype.cpp cannot do this, its just warning "already defined" when I write template.
Any suggestions well be welcome.

xml解析

你好,请问以下xml节点,结构体的XPACK怎么写

文件1网址base64加密
文件2网址base64加密

注:url是数组成员,带attr,但内容是直接给节点的

util.h报错

错误提示:错误 C4146 一元负运算符应用于无符号类型,结果仍为无符号类型 \xpack\util.h 89

Is it possible to add support for enum key based std::map?

Currently Im using the following workaround.

// std::map<enum, T>
template <typename TK, typename TV>
struct is_xpack_xtype<std::map<TK, TV>> {
    static bool const value = true;
};

template <class OBJ, typename TK, typename TV>
bool xpack_xtype_decode(OBJ& obj, const char* key, std::map<TK, TV>& val, const Extend* ext) {
    if constexpr (std::is_enum_v<TK>) {
        std::map<int64_t, TV> tmp;
        if (!obj.decode(key, tmp, ext)) {
            return false;
        }
        val.clear();
        for (auto&& item : tmp) {
            val[item.first] = item.second;
        }
        return true;
    } else {
        static_assert(false, "std::map with this key type is not supported to decode");
        return false;
    }
}

template <class OBJ, typename TK, typename TV>
bool xpack_xtype_encode(OBJ& obj, const char* key, const std::map<TK, TV>& val, const Extend* ext) {
    if constexpr (std::is_enum_v<TK>) {
        std::map<TK, TV> tmp;
        for (auto&& item : val) {
            tmp[item.first] = item.second;
        }
        return obj.encode(key, tmp, ext);
    } else {
        static_assert(false, "std::map with this key type is not supported to encode");
        return false;
    }
}

解析Json时,是否添加对UTF8-Bom文件的支持

是否能添加对UTF8-Bom文件的支持 xpack\json_decoder.h

 JsonDecoder(const std::string& str, bool isfile=false):xdoc_type(NULL, ""),_doc(new rapidjson::Document),_val(_doc) {
    std::string err;
    std::string data;

    do {
        if (isfile) {
            std::ifstream fs(str.c_str(), std::ifstream::binary);
            if (!fs) {
                err = "Open file["+str+"] fail.";
                break;
            }
            std::string _tmp((std::istreambuf_iterator<char>(fs)), std::istreambuf_iterator<char>());


            if (_tmp[0] == '\xEF' && _tmp[1] == '\xBB' && _tmp[2] == '\xBF')//if this formate is utf8-bom
            {
                data = _tmp.substr(3, _tmp.length() - 3);
            }
            else
            {
                data.swap(_tmp);
            }


            _doc->Parse(data);
        } else  {
            _doc->Parse(str);
        }

xhas

请问原来x2struct中提供的xhas()方法在xpack中是否有替代函数?

后面是否考虑支持std::optional,开发者可通过判成员是否为std::nullopt,达到类似调用xhas()的目的。

extend.h报错

error:xpack\extend.h(47): error C2039: “set”: 不是“std”的成员
solution:include

windows 10, VS2017 x64

decode错误时提示Error类型

是否考虑在decode出错时增加 Error Enum 类型。来表示诸如 "值类型错误/ErrorValueType",“缺少必须的域/MissingmandatoryFiled”等解析错误?

或者将rapidxml/rapidJson 解析时的返回值透传回来,类似如下

 bool isSuccess = false;
    try
    {
        isSuccess = xpack::json::decode(content.toStdString(), j);
    }
    catch (const std::exception& e)
    {
        LOGERROR("decode error ");
    }

    return isSuccess;

解析map嵌套结构体bug

map的value类型是结构体,解析有问题。
示例:

struct value {
  int a;
  XPACK(O(a));
};
std::map<std::string, value>  map;
xpack::json::decode("{\"123\":{\"a\":1011}, \"234\":{}}", map);
cout << map.size() << ',' << map["123"].a << ',' << map["234"].a << endl;

后面空的234的a跟前面123里面的a值一样,看起来是内部实现复用了结构体成员。

union支持情况

您好 请问XPACK是否支持union类型变量 如果不支持 有什么替代解决方案 非常感谢

int64_t encode 结果有问题

struct JanusResponse {
	std::string janus;
	std::string transaction;		
	int64_t session_id = -1;
	int64_t sender = -1;
	XPACK(O(janus, transaction, session_id, sender));
};

struct CreateSessionData {
	int64_t id;
	XPACK(O(id));
};

struct CreateSessionResponse : public JanusResponse {
	CreateSessionData data;
	XPACK(I(JanusResponse), O(data));
};

std::string js = "{\"janus\":\"success\",\"transaction\":\"RftQMdXKkq6q\",\"data\":{\"id\":6053426257610390}}";
vi::CreateSessionResponse model;
xpack::json::decode(js, model);

std::string result = xpack::json::encode(model);

你好,我发现decode结果是对的,encode的结果是错的,id的值不对。是我的用法不对?
(在x2struct上能正确encode)

return-statement with a value, in function returning ‘void’

json.h:39:82: error: return-statement with a value, in function returning ‘void’ [-fpermissive]
39 | return XDecoder(NULL, (const char*)NULL, node).decode(val, NULL);

there is a error of json.h,
image
the template function return a bool value, but the description of function return void.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.