Bond
 
Loading...
Searching...
No Matches
stream_interface.h
1// Copyright (c) Microsoft. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4#pragma once
5
6#include <bond/core/config.h>
7
8#include <bond/core/blob.h>
9#include <bond/core/detail/mpl.h>
10
11#include <boost/static_assert.hpp>
12
13#include <type_traits>
14
15namespace bond
16{
17
18//
19// input stream concept
20//
21
22#if 0
23class InputStream
24{
25public:
26 // Read overload(s) for arithmetic types
27 template <typename T>
28 void Read(T& value);
29
30 // Read into a memory buffer
31 void Read(void *buffer, uint32_t size);
32
33 // Read into a memory blob
34 void Read(bond::blob& blob, uint32_t size);
35
36 // Skip specified amount of bytes
37 void Skip(std::uint32_t size);
38
39 // Check if EOF is reached
40 bool IsEof() const;
41};
42#endif
43
44
45//
46// input stream functions - overload for custom streams
47//
48
49
50// Returns an object that represents the input stream's current position.
51// Return type is not required to be specifically bond::blob.
52// See GetBufferRange for more details.
53template <typename InputBuffer>
54[[noreturn]] inline blob GetCurrentBuffer(const InputBuffer& /*input*/)
55{
56 BOOST_STATIC_ASSERT_MSG(
57 detail::mpl::always_false<InputBuffer>::value,
58 "GetCurrentBuffer is undefined.");
59}
60
61
62// Returns an object that represents a buffer range. The input arguments are
63// determined by what the GetCurrentBuffer returns for the given input buffer
64// implementation (i.e. not necessarily a blob). The GetBufferRange may return
65// a type different from blob as long as it is understood by the corresponding
66// output buffer associated with the writer (i.e. there is an overloaded Write
67// function that accepts it).
68template <typename Blob>
69[[noreturn]] inline Blob GetBufferRange(const Blob& /*begin*/, const Blob& /*end*/)
70{
71 BOOST_STATIC_ASSERT_MSG(
72 detail::mpl::always_false<Blob>::value,
73 "GetBufferRange is undefined.");
74}
75
76
77//
78// output stream concept
79//
80
81#if 0
82class OutputStream
83{
84public:
85 // Write overload(s) for arithmetic types
86 template<typename T>
87 void Write(const T& value);
88
89 // Write a memory buffer
90 void Write(const void* value, uint32_t size);
91
92 // Write a memory blob
93 void Write(const bond::blob& blob);
94};
95#endif
96
97
98//
99// output stream functions - overload for custom streams
100//
101
102
103// Creates a new output buffer based on an existing one. The result does
104// not need to be the same type. The function is used in the places
105// where a new output buffer needs to be constructed with similar and/or
106// compatible properties as the original one (e.g. while serializing
107// bonded<T> for untagged protocols).
108template <typename OutputBuffer>
109[[noreturn]] inline OutputBuffer CreateOutputBuffer(const OutputBuffer& /*other*/)
110{
111 BOOST_STATIC_ASSERT_MSG(
112 detail::mpl::always_false<OutputBuffer>::value,
113 "CreateOutputBuffer is undefined.");
114}
115
116
117}
Memory blob.
Definition: blob.h:24
namespace bond
Definition: apply.h:17
OutputMemoryStream OutputBuffer
Type alias for memory backed output stream using std::allocator.
Definition: output_buffer.h:386