예제 #1
1
파일: Protobuf.cpp 프로젝트: gitmesen/carla
 std::string Protobuf::Encode(const google::protobuf::MessageLite &message) {
   std::string result;
   DEBUG_ASSERT(message.IsInitialized());
   PrependByteSize(result, message.ByteSize());
   message.AppendToString(&result);
   return result;
 }
예제 #2
0
QByteArray OsmPbfWriterPrivate::packPbfMessageToArray( const google::protobuf::MessageLite &message)
{
    QByteArray result;
    result.resize(message.ByteSize());
    if (!message.SerializeToArray(result.data(), result.size()))
        throw OsmPbfWriter::SerializeException();
    return result;
}
예제 #3
0
파일: hu_aap.cpp 프로젝트: mishaaq/headunit
  int HUServer::hu_aap_unenc_send_message(int retry, int chan, uint16_t messageCode, const google::protobuf::MessageLite& message, int overrideTimeout)
  {
    const int messageSize = message.ByteSize();
    const int requiredSize = messageSize + 2;
    if (temp_assembly_buffer.size() < requiredSize)
    {
      temp_assembly_buffer.resize(requiredSize);
    }

    uint16_t* destMessageCode = reinterpret_cast<uint16_t*>(temp_assembly_buffer.data());
    *destMessageCode++ = htobe16(messageCode);

    if (!message.SerializeToArray(destMessageCode, messageSize))
    {
      loge("AppendToString failed for %s", message.GetTypeName().c_str());
      return -1;
    }

    logd ("Send %s on channel %i %s", message.GetTypeName().c_str(), chan, chan_get(chan));
    //hex_dump("PB:", 80, temp_assembly_buffer.data(), requiredSize);
    return hu_aap_unenc_send(retry, chan, temp_assembly_buffer.data(), requiredSize, overrideTimeout);
  }
예제 #4
0
bool writeDelimitedTo(const google::protobuf::MessageLite& message,
                      google::protobuf::io::ZeroCopyOutputStream* rawOutput) {
  // We create a new coded stream for each message.  Don't worry, this is fast.
  google::protobuf::io::CodedOutputStream output(rawOutput);

  // Write the size.
  const int size = message.ByteSize();
  output.WriteVarint32(size);

  uint8_t* buffer = output.GetDirectBufferForNBytesAndAdvance(size);
  if (buffer != nullptr) {
    // Optimization:  The message fits in one buffer, so use the faster
    // direct-to-array serialization path.
    message.SerializeWithCachedSizesToArray(buffer);
  } else {
    // Slightly-slower path when the message is multiple buffers.
    message.SerializeWithCachedSizes(&output);
    if (output.HadError()) return false;
  }

  return true;
}
예제 #5
0
void ENetEndpoint::sDefaultMessageHandler(ENetEndpoint& endpoint,
                                          const google::protobuf::MessageLite& message) {
  std::cout << endpoint.getIdentifier() << " No handler for: " 
            << message.GetTypeName() << std::endl;
}
예제 #6
0
파일: dbserver.cpp 프로젝트: JoJo2nd/Heart
void ldbDebugServer::sendPacket(ENetPeer* peer, const google::protobuf::MessageLite& msg) {
    auto packet = enet_packet_create(nullptr, msg.ByteSize(), ENET_PACKET_FLAG_RELIABLE);
    msg.SerializeToArray(packet->data, packet->dataLength);
    ldb_mutexsentry sentry(packetMtx_);
    packetsToSend_.emplace_back(peer, packet);
}