Giter Site home page Giter Site logo

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

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

from buttonrpc_cpp14.

Comments (2)

madadaaa avatar madadaaa commented on May 20, 2024

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

from buttonrpc_cpp14.

madadaaa avatar madadaaa commented on May 20, 2024

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

`
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));
}`

from buttonrpc_cpp14.

Related Issues (10)

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.