int marshall(const Msg& inm, mutable_buffer<char> inb) { int newlen=inb.len()-HEAD_SIZE; if(newlen<=0) throw std::runtime_error("marshalling:: provided buffer is too small"); auto it = m_map.find(inm.type()); if(it==m_map.end()) throw std::runtime_error("marshalling:: message type not supported"); *(reinterpret_cast<int*>(inb.addr())) = htonl(inm.type()); int m_len = it->second->marshall(inm,mutable_buffer<char>(inb.addr()+HEAD_SIZE,newlen)); *(reinterpret_cast<unsigned int*>(inb.addr()+sizeof(int))) = htonl(m_len); return m_len+HEAD_SIZE; }
void NetworkManager::Interface::ReceivePacket(mutable_buffer buf, uint32_t len) { //FIXME: We should avoid this copy auto p = pbuf_alloc(PBUF_LINK, len + ETH_PAD_SIZE, PBUF_POOL); kbugon(p == nullptr, "Failed to allocate pbuf"); auto ptr = buf.addr(); bool first = true; for (auto q = p; q != nullptr; q = q->next) { auto add = 0; if (first) { add = ETH_PAD_SIZE; first = false; } memcpy(static_cast<char*>(q->payload) + add, ptr, q->len - add); ptr = static_cast<void*>(static_cast<char*>(ptr) + q->len); } netif_.input(p, &netif_); }
const_buffer(const mutable_buffer<Tp> &other) : m_addr(other.addr()), m_len(other.len()) {}