@@ -39,7 +39,7 @@ static size_t const bufferLength = 4096UL;
39
39
// static size_t const chunkMaxBytes = 1000UL;
40
40
static size_t const minChunkHeaderSize = 16 ;
41
41
static size_t const maxChunkHeaderSize = 24 ;
42
- static size_t const defaultMaxChunkSize = 30000 ;
42
+ static size_t const defaultMaxChunkSize = 1024 * 32 ;
43
43
44
44
// ///////////////////////////////////////////////////////////////////////////////////
45
45
// DataStructures
@@ -49,19 +49,11 @@ static size_t const defaultMaxChunkSize = 30000;
49
49
struct ChunkHeader {
50
50
51
51
// data used in the specification
52
- uint32_t _chunkLength; // length of this chunk includig chunkHeader
52
+ uint32_t _chunkLength; // length of chunk content (including chunkHeader)
53
53
uint32_t _chunkX; // number of chunks or chunk number
54
54
uint64_t _messageID; // messageid
55
55
uint64_t _messageLength; // length of total payload
56
56
57
- // Used when receiving the response:
58
- // Offset of start of content of this chunk in
59
- // RequestItem._responseChunkContent.
60
- size_t _responseChunkContentOffset;
61
- // / Content length of this chunk (only used
62
- // / during read operations).
63
- size_t _responseContentLength;
64
-
65
57
// Return length of this chunk (in host byte order)
66
58
inline uint32_t chunkLength () const { return _chunkLength; }
67
59
// Return message ID of this chunk (in host byte order)
@@ -82,101 +74,42 @@ struct ChunkHeader {
82
74
return 0 ; // Not known
83
75
}
84
76
85
- // writeHeaderToVST1_0 write the chunk to the given buffer in VST 1.0 format.
77
+ // writeHeaderToVST1_0 writes the chunk to the given buffer in VST 1.0 format.
86
78
// The length of the buffer is returned.
87
79
size_t writeHeaderToVST1_0 (size_t chunkDataLen, velocypack::Buffer<uint8_t >&) const ;
88
80
89
- // writeHeaderToVST1_1 write the chunk to the given buffer in VST 1.1 format.
81
+ // writeHeaderToVST1_1 writes the chunk to the given buffer in VST 1.1 format.
90
82
// The length of the buffer is returned.
91
83
size_t writeHeaderToVST1_1 (size_t chunkDataLen, velocypack::Buffer<uint8_t >& buffer) const ;
92
84
};
93
85
94
-
95
- // chunkHeaderLength returns the length of a VST chunk header for given
96
- // arguments.
97
- /* inline std::size_t chunkHeaderLength(VSTVersion vstVersion, bool isFirst, bool
98
- isSingle) {
99
- switch (vstVersion) {
100
- case VST1_0:
101
- if (isFirst && !isSingle) {
102
- return maxChunkHeaderSize;
103
- }
104
- return minChunkHeaderSize;
105
- case VST1_1:
106
- return maxChunkHeaderSize;
107
- default:
108
- throw std::logic_error("Unknown VST version");
109
- }
110
- }*/
111
-
112
- // Item that represents a Request in flight
113
- struct RequestItem {
114
- // / ID of this message
115
- MessageID _messageID;
116
- // / Reference to the request we're processing
117
- std::unique_ptr<Request> _request;
118
- // / Callback for when request is done (in error or succeeded)
119
- RequestCallback _callback;
120
F42D
- // / point in time when the message expires
121
- std::chrono::steady_clock::time_point _expires;
122
-
123
- // ======= Request variables =======
124
-
125
- // / Buffer used to hold chunk headers and message header
126
- velocypack::Buffer<uint8_t > _requestMetadata;
127
-
128
- // / Temporary list of buffers goin to be send by the socket.
129
- std::vector<asio_ns::const_buffer> _requestBuffers;
130
-
131
- // ======= Response variables =======
132
-
133
- // / @brief List of chunks that have been received.
134
- std::vector<ChunkHeader> _responseChunks;
135
- // / Buffer containing content of received chunks.
136
- // / Not necessarily in a sorted order!
137
- velocypack::Buffer<uint8_t > _responseChunkContent;
138
- // / The number of chunks we're expecting (0==not know yet).
139
- size_t _responseNumberOfChunks;
140
-
141
- inline MessageID messageID () { return _messageID; }
142
- inline void invokeOnError (Error e) {
143
- _callback (e, std::move (_request), nullptr );
144
- }
145
-
146
- // / prepareForNetwork prepares the internal structures for
147
- // / writing the request to the network.
148
- void prepareForNetwork (VSTVersion);
149
-
150
- // prepare structures with a given message header and payload
151
- void prepareForNetwork (VSTVersion,
152
- asio_ns::const_buffer header,
153
- asio_ns::const_buffer payload);
154
-
155
- // add the given chunk to the list of response chunks.
156
- void addChunk (ChunkHeader&& chunk,
157
- asio_ns::const_buffer const & data);
158
- // try to assembly the received chunks into a response.
159
- // returns NULL if not all chunks are available.
160
- std::unique_ptr<velocypack::Buffer<uint8_t >> assemble ();
161
-
162
- // Flush all memory needed for sending this request.
163
- inline void resetSendData () {
164
- _requestMetadata.clear ();
165
- _requestBuffers.clear ();
166
- }
86
+ struct Chunk {
87
+ ChunkHeader header;
88
+ asio_ns::const_buffer body;
167
89
};
168
90
169
91
namespace message {
170
92
171
- // / @brief creates a slice containing a VST request header.
172
- velocypack::Buffer<uint8_t > requestHeader (RequestHeader const &);
173
- // / @brief creates a slice containing a VST request header.
174
- velocypack::Buffer<uint8_t > responseHeader (ResponseHeader const &);
93
+ // / @brief creates a slice containing a VST request-message header.
94
+ void requestHeader (RequestHeader const &, velocypack::Buffer<uint8_t >&);
95
+ // / @brief creates a slice containing a VST response-message header.
96
+ void responseHeader (ResponseHeader const &, velocypack::Buffer<uint8_t >&);
175
97
// / @brief creates a slice containing a VST auth message with JWT encryption
176
- velocypack::Buffer<uint8_t > authJWT (std::string const & token);
177
- // / @brief creates a slice containing a VST auth message with plain enctyption
178
- velocypack::Buffer<uint8_t > authBasic (std::string const & username,
179
- std::string const & password);
98
+ void authJWT (std::string const & token, velocypack::Buffer<uint8_t >&);
99
+ // / @brief creates a slice containing a VST auth message with plain encryption
100
+ void authBasic (std::string const & username,
101
+ std::string const & password,
102
+ velocypack::Buffer<uint8_t >&);
103
+
104
+ // / @brief take existing buffers and partitions into chunks
105
+ // / @param buffer is containing the metadata. If non-empty this will be used
106
+ // / as a prefix to the payload.
107
+ // / @param payload the payload that is going to be partitioned
108
+ void prepareForNetwork (VSTVersion vstVersion,
109
+ MessageID messageId,
110
+ velocypack::Buffer<uint8_t >& buffer,
111
+ asio_ns::const_buffer payload,
112
+ std::vector<asio_ns::const_buffer>& result);
180
113
}
181
114
182
115
// ///////////////////////////////////////////////////////////////////////////////////
@@ -193,10 +126,10 @@ std::size_t isChunkComplete(uint8_t const* const begin,
193
126
std::size_t const length);
194
127
195
128
// readChunkHeaderVST1_0 reads a chunk header in VST1.0 format.
196
- std::pair<ChunkHeader, asio_ns::const_buffer> readChunkHeaderVST1_0 (uint8_t const *);
129
+ Chunk readChunkHeaderVST1_0 (uint8_t const *);
197
130
198
131
// readChunkHeaderVST1_1 reads a chunk header in VST1.1 format.
199
- std::pair<ChunkHeader, asio_ns::const_buffer> readChunkHeaderVST1_1 (uint8_t const *);
132
+ Chunk readChunkHeaderVST1_1 (uint8_t const *);
200
133
201
134
// / @brief verifies header input and checks correct length
202
135
// / @return message type or MessageType::Undefined on an error
0 commit comments