Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
ExternallyOwnedSpanInputStream.h File Reference
#include "Stroika/Foundation/StroikaPreComp.h"
#include <mutex>
#include <vector>
#include "Stroika/Foundation/Common/Common.h"
#include "Stroika/Foundation/Execution/Synchronized.h"
#include "Stroika/Foundation/Memory/BLOB.h"
#include "Stroika/Foundation/Memory/Common.h"
#include "InputStream.h"
#include "ExternallyOwnedSpanInputStream.inl"

Go to the source code of this file.

Namespaces

namespace  Stroika::Foundation
 

Functions

template<typename ELEMENT_TYPE , Memory::ISpanBytesCastable< span< const ELEMENT_TYPE > > FROM_SPAN>
Ptr< ELEMENT_TYPE > Stroika::Foundation::Streams::ExternallyOwnedSpanInputStream::New (FROM_SPAN s)
 ExternallyOwnedSpanInputStream takes a (memory contiguous) sequence of ELEMENT_TYPE objects and exposes it as a InputStream<ELEMENT_TYPE>
 

Detailed Description

Note
Code-Status: Beta

Definition in file ExternallyOwnedSpanInputStream.h.

Function Documentation

◆ New()

template<typename ELEMENT_TYPE , Memory::ISpanBytesCastable< span< const ELEMENT_TYPE > > FROM_SPAN>
Ptr< ELEMENT_TYPE > Stroika::Foundation::Streams::ExternallyOwnedSpanInputStream::New ( FROM_SPAN  s)

ExternallyOwnedSpanInputStream takes a (memory contiguous) sequence of ELEMENT_TYPE objects and exposes it as a InputStream<ELEMENT_TYPE>

ExternallyOwnedSpanInputStream is a subtype of InputStream<ELEMENT_TYPE> but the creator must guarantee, so long as the memory pointed to in the argument has a o lifetime > lifetime of the ExternallyOwnedSpanInputStream object, o and data never changes value

Note
NB: Be VERY careful about using this. It can be assigned to a InputStream::Ptr<ELEMENT_TYPE>, and if its constructor argument is destroyed, it will contain invalid memory references. Use VERY CAREFULLY. If in doubt, use @MemoryStream<ELEMENT_TYPE> - which is MUCH safer (because it copies its CTOR-argument data)

ExternallyOwnedSpanInputStream is Seekable.

See also
MemoryStream
Note
Thread-Safety C++-Standard-Thread-Safety-For-Envelope-Plus-Must-Externally-Synchronize-Letter
Example Usage
InputStream::Ptr<byte> in = ExternallyOwnedSpanInputStream::New<byte> (span{buf});
Example Usage
CallExpectingBinaryInputStreamPtr (ExternallyOwnedSpanInputStream::New<byte> (span{buf})
Example Usage
const char kJSONExample_[] = "{"...;
// JSON Reader takes InputStream::Ptr<byte> argument
auto reader = DataExchange::Variant::JSON::Reader{};
VariantValue v1 = reader.Read (Streams::ExternallyOwnedSpanInputStream::New (span{kJSONExample_}));
VariantValue vSameAs = reader.Read (Streams::ExternallyOwnedSpanInputStream::New (Memory::SpanBytesCast<span<const byte>>(span{kJSONExample_})));

Definition at line 134 of file ExternallyOwnedSpanInputStream.inl.