Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc调用的时候,发现字符串长度最长是uint16_t,大概是64k,能否允许传递更长的字符串,比如10M以内,因为代码有点看不懂,我改了几次无法成功 #5

Closed
madadaaa opened this issue May 13, 2020 · 2 comments

Comments

@madadaaa
Copy link

rpc调用的时候,发现字符串长度最长是uint16_t,大概是64k,能否允许传递更长的字符串,比如10M以内,因为代码有点看不懂,我改了几次无法成功

@madadaaa
Copy link
Author

我用的是2010的buttonrpc:
https://github.com/button-chen/buttonrpc

@madadaaa
Copy link
Author

修改了一下,好像是可以了:

`
template
inline void Serializer::output_type(T& t)
{
int len = sizeof(T);
char* d = new char[len];
if (!m_iodevice.is_eof()){
memcpy(d, m_iodevice.current(), len);
m_iodevice.offset(len);
byte_orser(d, len);
t = reinterpret_cast<T>(&d[0]);
}
delete [] d;
}

template<>
inline void Serializer::output_type(std::string& in)
{
int marklen = sizeof(uint32_t);
char* d = new char[marklen];
memcpy(d, m_iodevice.current(), marklen);
byte_orser(d, marklen);
int len = reinterpret_cast<uint32_t>(&d[0]);
m_iodevice.offset(marklen);
delete [] d;
if (len == 0) return;
in.insert(in.begin(), m_iodevice.current(), m_iodevice.current() + len);
m_iodevice.offset(len);
}

template
inline void Serializer::input_type(T t)
{
int len = sizeof(T);
char* d = new char[len];
const char* p = reinterpret_cast<const char*>(&t);
memcpy(d, p, len);
byte_orser(d, len);
m_iodevice.input(d, len);
delete [] d;
}

template<>
inline void Serializer::input_type(std::string in)
{
// 先存入字符串长度
uint32_t len = in.size();
char* p = reinterpret_cast< char*>(&len);
byte_orser(p, sizeof(uint32_t));
m_iodevice.input(p, sizeof(uint32_t));

// 存入字符串
if (len == 0) return;
char* d = new char[len];
memcpy(d, in.c_str(), len);
m_iodevice.input(d, len);
delete [] d;

}

template<>
inline void Serializer::input_type(const char* in)
{
input_typestd::string(std::string(in));
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant