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

Quelle  CapsuleParser.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_net_capsule_parser_h
#define mozilla_net_capsule_parser_h

#include "Capsule.h"
#include "mozilla/Maybe.h"
#include "mozilla/Result.h"
#include "mozilla/Span.h"

namespace mozilla::net {

class CapsuleDecoder;

class CapsuleParser final {
 public:
  class Listener {
   public:
    NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING

    virtual bool OnCapsule(Capsule&& aCapsule) = 0;
    virtual void OnCapsuleParseFailure(nsresult aError) = 0;

   protected:
    virtual ~Listener() = default;
  };

  explicit CapsuleParser(Listener* aListener);
  ~CapsuleParser() = default;
  // Processes incoming data and attempts to parse complete capsules.
  // For each successfully parsed capsule, Listener::OnCapsule is invoked.
  // If there is insufficient data to form a complete capsule, the remaining
  // data is retained in mBuffer. In case a parsing error occurs,
  // OnCapsuleParseFailure is called and any remaining data in mBuffer is
  // discarded.
  bool ProcessCapsuleData(const uint8_t* aData, uint32_t aCount);

  bool IsBufferEmpty() const { return mBuffer.IsEmpty(); }

 private:
  // Indicates whether ProcessCapsuleData is already running.
  bool mProcessing = false;

  RefPtr<Listener> mListener;
  // The buffer used to store data when we don't have enough to parse one
  // capsule.
  nsTArray<uint8_t> mBuffer;
  // Parse one capsule from |aData|.
  // Returns 0 if the complete capsule is not yet available, returns an error if
  // parsing fails, or returns the number of bytes consumed for the successfully
  // parsed capsule.
  Result<size_t, nsresult> ParseCapsuleData(Span<const uint8_t> aData);
  // Parse the payload part of the capsule. Returns the parsed capsule or an
  // error.
  Result<Capsule, nsresult> ParseCapsulePayload(CapsuleDecoder& aDecoder,
                                                CapsuleType aType,
                                                size_t aPayloadLength);
};

// This is mainly used for testing.
class CapsuleParserListener : public CapsuleParser::Listener {
 public:
  NS_INLINE_DECL_REFCOUNTING(CapsuleParserListener, override)

  CapsuleParserListener() = default;
  bool OnCapsule(Capsule&& aCapsule) override;
  void OnCapsuleParseFailure(nsresult aError) override;

  nsTArray<Capsule> GetParsedCapsules() { return std::move(mParsedCapsules); }

  Maybe<nsresult> GetErrorResult() { return mError; }

 private:
  virtual ~CapsuleParserListener() = default;

  nsTArray<Capsule> mParsedCapsules;
  Maybe<nsresult> mError = Nothing();
};

}  // namespace mozilla::net

#endif

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

¤ Dauer der Verarbeitung: 0.4 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.