Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
MessageStartTextInputStreamBinaryAdapter.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. 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 MessageStartTextInputStreamBinaryAdapter : public Streams::InputStream<Characters::Character> {
41 // public:
42 class Ptr;
43
44 // public:
45 /**
46 */
47 enum ToStringFormat {
48 eAsBytes,
49 eAsString,
50
51 eDEFAULT = eAsString
52 };
53
54 // public:
55 /**
56 */
57 Ptr New (const Streams::InputStream::Ptr<byte>& src);
58
59 // private:
60 class Rep_;
61 // };
62
63 /**
64 * Ptr is a copyable smart pointer to a MessageStartTextInputStreamBinaryAdapter.
65 */
66 class Ptr : public Streams::InputStream::Ptr<Characters::Character> {
67 private:
68 using inherited = typename Streams::InputStream::Ptr<Characters::Character>;
69
70 public:
71 Ptr () = default;
72 Ptr (const Ptr&) = default;
74
75 public:
76 /*
77 * 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
78 * fasion.
79 *
80 * Return false if not available, and return true if all read in. This automatically resets the Read seek pointer to 0.
81 *
82 * \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).
83 */
84 nonvirtual bool AssureHeaderSectionAvailable ();
85
86 public:
87 /**
88 * @see Characters::ToString ()
89 */
90 nonvirtual Characters::String ToString (ToStringFormat format = ToStringFormat::eDEFAULT) const;
91 };
92
93}
94
95#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 ...