mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
31bb107922
There are three classes avaliable that share the functionality of BufferStream: 1. InputMemoryStream is for reading from static buffers. Example: Bytes input = /* ... */; InputMemoryStream stream { input }; LittleEndian<u32> little_endian_value; input >> little_endian_value; u32 host_endian_value; input >> host_endian_value; SomeComplexStruct complex_struct; input >> Bytes { &complex_struct, sizeof(complex_struct) }; 2. OutputMemoryStream is for writing to static buffers. Example: Array<u8, 4096> buffer; OutputMemoryStream stream; stream << LittleEndian<u32> { 42 }; stream << ReadonlyBytes { &complex_struct, sizeof(complex_struct) }; foo(stream.bytes()); 3. DuplexMemoryStream for writing to dynamic buffers, can also be used as an intermediate buffer by reading from it directly. Example: DuplexMemoryStream stream; stream << NetworkOrdered<u32> { 13 }; stream << NetowkrOrdered<u64> { 22 }; NetworkOrdered<u32> value; stream >> value; ASSERT(value == 13); foo(stream.copy_into_contiguous_buffer()); Unlike BufferStream these streams do not use a fixed endianness (BufferStream used little endian) these have to be explicitly specified. There are helper types in <AK/Endian.h>.
171 lines
3.9 KiB
C++
171 lines
3.9 KiB
C++
/*
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
* list of conditions and the following disclaimer.
|
|
*
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
* and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Types.h>
|
|
|
|
namespace AK {
|
|
|
|
class Bitmap;
|
|
class ByteBuffer;
|
|
class DebugLogStream;
|
|
class IPv4Address;
|
|
class JsonArray;
|
|
class JsonObject;
|
|
class JsonValue;
|
|
class LogStream;
|
|
class SharedBuffer;
|
|
class String;
|
|
class StringBuilder;
|
|
class StringImpl;
|
|
class StringView;
|
|
class URL;
|
|
class FlyString;
|
|
class Utf32View;
|
|
class Utf8View;
|
|
class InputStream;
|
|
class InputMemoryStream;
|
|
class DuplexMemoryStream;
|
|
class OutputStream;
|
|
class InputBitStream;
|
|
class OutputMemoryStream;
|
|
|
|
template<size_t Capacity>
|
|
class CircularDuplexStream;
|
|
|
|
template<typename T>
|
|
class Span;
|
|
|
|
template<typename T, size_t Size>
|
|
struct Array;
|
|
|
|
template<typename Container, typename ValueType>
|
|
class SimpleIterator;
|
|
|
|
using ReadonlyBytes = Span<const u8>;
|
|
using Bytes = Span<u8>;
|
|
|
|
template<typename T>
|
|
class Atomic;
|
|
|
|
template<typename T>
|
|
class SinglyLinkedList;
|
|
|
|
template<typename T>
|
|
class DoublyLinkedList;
|
|
|
|
template<typename T>
|
|
class InlineLinkedList;
|
|
|
|
template<typename T, size_t capacity>
|
|
class CircularQueue;
|
|
|
|
template<typename T>
|
|
struct Traits;
|
|
|
|
template<typename T, typename = Traits<T>>
|
|
class HashTable;
|
|
|
|
template<typename K, typename V, typename = Traits<K>>
|
|
class HashMap;
|
|
|
|
template<typename T>
|
|
class Badge;
|
|
|
|
template<typename>
|
|
class Function;
|
|
|
|
template<typename Out, typename... In>
|
|
class Function<Out(In...)>;
|
|
|
|
template<typename T>
|
|
class NonnullRefPtr;
|
|
|
|
template<typename T>
|
|
class NonnullOwnPtr;
|
|
|
|
template<typename T>
|
|
class Optional;
|
|
|
|
template<typename T>
|
|
class RefPtr;
|
|
|
|
template<typename T>
|
|
class OwnPtr;
|
|
|
|
template<typename T>
|
|
class WeakPtr;
|
|
|
|
template<typename T, size_t inline_capacity = 0>
|
|
class Vector;
|
|
|
|
}
|
|
|
|
using AK::Array;
|
|
using AK::Atomic;
|
|
using AK::Badge;
|
|
using AK::Bitmap;
|
|
using AK::ByteBuffer;
|
|
using AK::Bytes;
|
|
using AK::CircularDuplexStream;
|
|
using AK::CircularQueue;
|
|
using AK::DebugLogStream;
|
|
using AK::DoublyLinkedList;
|
|
using AK::DuplexMemoryStream;
|
|
using AK::FlyString;
|
|
using AK::Function;
|
|
using AK::HashMap;
|
|
using AK::HashTable;
|
|
using AK::InlineLinkedList;
|
|
using AK::InputBitStream;
|
|
using AK::InputMemoryStream;
|
|
using AK::InputStream;
|
|
using AK::IPv4Address;
|
|
using AK::JsonArray;
|
|
using AK::JsonObject;
|
|
using AK::JsonValue;
|
|
using AK::LogStream;
|
|
using AK::NonnullOwnPtr;
|
|
using AK::NonnullRefPtr;
|
|
using AK::Optional;
|
|
using AK::OutputMemoryStream;
|
|
using AK::OutputStream;
|
|
using AK::OwnPtr;
|
|
using AK::ReadonlyBytes;
|
|
using AK::RefPtr;
|
|
using AK::SharedBuffer;
|
|
using AK::SinglyLinkedList;
|
|
using AK::Span;
|
|
using AK::String;
|
|
using AK::StringBuilder;
|
|
using AK::StringImpl;
|
|
using AK::StringView;
|
|
using AK::Traits;
|
|
using AK::URL;
|
|
using AK::Utf32View;
|
|
using AK::Utf8View;
|
|
using AK::Vector;
|