Stroika Library 3.0d23
 
Loading...
Searching...
No Matches
MessageStartTextInputStreamBinaryAdapter.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4#ifndef _Stroika_Foundation_IO_Network_HTTP_MessageStartTextInputStreamBinaryAdapter_h_
5#define _Stroika_Foundation_IO_Network_HTTP_MessageStartTextInputStreamBinaryAdapter_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
10
11/**
12 * \file
13 *
14 */
15
16namespace Stroika::Foundation::IO::Network::HTTP::MessageStartTextInputStreamBinaryAdapter {
17
18 /**
19 * This can be used to create a readable stream of strings (readline) - which
20 * consume a BinaryStream (pre-seeked to the right place) - as a series of characters.
21 *
22 * This code respects the format defined in http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html
23 * and doesn't read more than needed (no pre-buffering).
24 * This lack of pre-buffering (peeking) is critical so that the underlying binary stream
25 * only reads the minimal amount needed and will be placed at the right position when handed
26 * to the next process to interpret.
27 *
28 * Though this InputStream::Ptr<Character> is seekable, it only supports seeking backwards over materials
29 * already read. It never allows seeking past its last read point (throws not supported).
30 *
31 * This adpater defines 0 seek offset as the point at which its constructed. And then you can seek to any locaiton
32 * 0 .. up to the max point ever read (with Read).
33 *
34 * \par TODO
35 * @todo Must rewrite this to properly handle other than ASCII characterset on incoming headers
36 * and URL lines - http://stroika-bugs.sophists.com/browse/STK-969
37 *
38 * \note \em Thread-Safety <a href="Thread-Safety.md#C++-Standard-Thread-Safety-For-Envelope-Plus-Must-Externally-Synchronize-Letter">C++-Standard-Thread-Safety-For-Envelope-Plus-Must-Externally-Synchronize-Letter</a>
39 */
40 class Ptr;
41
42 /**
43 */
44 enum ToStringFormat {
45 eAsBytes,
46 eAsString,
47
48 eDEFAULT = eAsString
49 };
50
51 /**
52 */
53 Ptr New (const Streams::InputStream::Ptr<byte>& src);
54
55 /**
56 * Ptr is a copyable smart pointer to a MessageStartTextInputStreamBinaryAdapter.
57 */
58 class Ptr : public Streams::InputStream::Ptr<Characters::Character> {
59 private:
60 using inherited = typename Streams::InputStream::Ptr<Characters::Character>;
61
62 public:
63 Ptr () = default;
64 Ptr (const Ptr&) = default;
66
67 public:
68 /*
69 * Do low level non-blocking reads to assure all the bytes (but not a single byte more) is read in and available to be read in a blocking
70 * fasion.
71 *
72 * Return false if not available, and return true if all read in. This automatically resets the Read seek pointer to 0.
73 *
74 * \note - this returns true EVEN if the header is incomplete on EOF - so the caller can use this as a test to see if its time to try to read the header).
75 */
76 nonvirtual bool AssureHeaderSectionAvailable ();
77
78 public:
79 /**
80 * @see Characters::ToString ()
81 */
82 nonvirtual Characters::String ToString (ToStringFormat format = ToStringFormat::eDEFAULT) const;
83 };
84
85}
86
87#endif /*_Stroika_Foundation_IO_Network_HTTP_MessageStartTextInputStreamBinaryAdapter_h_*/
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
nonvirtual Characters::String ToString(ToStringFormat format=ToStringFormat::eDEFAULT) const
InputStream<>::Ptr is Smart pointer (with abstract Rep) class defining the interface to reading from ...