Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/ipc/glue/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 2 kB image not shown  

Quelle  SerializeToBytesUtil.h

  Sprache: C
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */


#ifndef mozilla_ipc_SerializeToBytesUtil_h
#define mozilla_ipc_SerializeToBytesUtil_h

#include "chrome/common/ipc_message_utils.h"
#include "chrome/common/ipc_message.h"

namespace mozilla::ipc {

// This file contains a pair of functions which (ab-)use the IPC::ParamTraits
// serializers with a temporary on-stack IPC::Message to serialize &
// de-serialize a value from a byte span.
//
// NOTE: This is _not_ efficient, and is _not_ guaranteed to work for arbitrary
// types! Many IPC serializers depend on the IPC::Message supporting additional
// information, such as attached endpoints and file handles.

template <typename T>
void SerializeToBytesUtil(T&& aValue, nsTArray<char>& aBytes) {
  IPC::Message tmpMessage(MSG_ROUTING_NONE, -1);

  {
    IPC::MessageWriter writer(tmpMessage);
    IPC::WriteParam(&writer, std::forward<T>(aValue));
  }

  MOZ_RELEASE_ASSERT(!tmpMessage.has_any_attachments(),
                     "Value contains attachments (e.g. endpoints, file "
                     "handles) which cannot be serialized as bytes");

  aBytes.SetLength(tmpMessage.size() - IPC::Message::HeaderSize());

  IPC::MessageReader reader(tmpMessage);
  bool readOk = reader.ReadBytesInto(aBytes.Elements(), aBytes.Length());
  MOZ_RELEASE_ASSERT(readOk);
  // Double-check that the entire Message body was used.
  MOZ_RELEASE_ASSERT(!reader.HasBytesAvailable(1));
}

template <typename T>
IPC::ReadResult<T> DeserializeFromBytesUtil(const Span<char>& aBytes) {
  IPC::Message tmpMessage(MSG_ROUTING_NONE, -1);

  {
    IPC::MessageWriter writer(tmpMessage);
    writer.WriteBytes(aBytes.Elements(), aBytes.Length());
  }

  IPC::MessageReader reader(tmpMessage);
  auto rv = IPC::ReadParam<T>(&reader);
  if (rv.isOk() && reader.HasBytesAvailable(1)) {
    // Unexpected trailing data after deserialization.
    return {};
  }
  return rv;
}

}  // namespace mozilla::ipc

#endif  // mozilla_ipc_SerializeToBytesUtil_h

Messung V0.5 in Prozent
C=90 H=95 G=92

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.