Skip to content

Commit e7d4b30

Browse files
committed
Add protocol server tests
1 parent 8c3b4b6 commit e7d4b30

File tree

8 files changed

+468
-4
lines changed

8 files changed

+468
-4
lines changed

examples/proto_server.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class SimpleProtoSession : public CppServer::Asio::TCPSession, public FBE::simpl
6363
simple::SimpleResponse response;
6464
response.id = request.id;
6565
response.Hash = (uint32_t)hasher(request.Message);
66+
response.Length = (uint32_t)request.Message.size();
6667
send(response);
6768
}
6869

performance/proto_server.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class ProtoSession : public TCPSession, public FBE::simple::Sender, public FBE::
3333
// Send response
3434
simple::SimpleResponse response;
3535
response.id = request.id;
36-
response.Hash = (uint32_t)request.Message.size();
36+
response.Hash = 0;
37+
response.Length = (uint32_t)request.Message.size();
3738
send(response);
3839
}
3940

proto/simple.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ std::ostream& operator<<(std::ostream& stream, const SimpleRequest& value)
5151

5252
SimpleResponse::SimpleResponse()
5353
: id(FBE::uuid_t::sequential())
54+
, Length((uint32_t)0ull)
5455
, Hash((uint32_t)0ull)
5556
{}
5657

57-
SimpleResponse::SimpleResponse(const FBE::uuid_t& arg_id, uint32_t arg_Hash)
58+
SimpleResponse::SimpleResponse(const FBE::uuid_t& arg_id, uint32_t arg_Length, uint32_t arg_Hash)
5859
: id(arg_id)
60+
, Length(arg_Length)
5961
, Hash(arg_Hash)
6062
{}
6163

@@ -79,13 +81,15 @@ void SimpleResponse::swap(SimpleResponse& other) noexcept
7981
{
8082
using std::swap;
8183
swap(id, other.id);
84+
swap(Length, other.Length);
8285
swap(Hash, other.Hash);
8386
}
8487

8588
std::ostream& operator<<(std::ostream& stream, const SimpleResponse& value)
8689
{
8790
stream << "SimpleResponse(";
8891
stream << "id="; stream << "\"" << value.id << "\"";
92+
stream << ",Length="; stream << value.Length;
8993
stream << ",Hash="; stream << value.Hash;
9094
stream << ")";
9195
return stream;

proto/simple.fbe

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ message SimpleResponse
3131
{
3232
// Response Id
3333
uuid [id] = uuid1;
34+
// Calculated message length
35+
uint32 Length;
3436
// Calculated message hash
3537
uint32 Hash;
3638
}

proto/simple.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,13 @@ namespace simple {
8585
struct SimpleResponse
8686
{
8787
FBE::uuid_t id;
88+
uint32_t Length;
8889
uint32_t Hash;
8990

9091
size_t fbe_type() const noexcept { return 2; }
9192

9293
SimpleResponse();
93-
SimpleResponse(const FBE::uuid_t& arg_id, uint32_t arg_Hash);
94+
SimpleResponse(const FBE::uuid_t& arg_id, uint32_t arg_Length, uint32_t arg_Hash);
9495
SimpleResponse(const SimpleResponse& other) = default;
9596
SimpleResponse(SimpleResponse&& other) = default;
9697
~SimpleResponse() = default;

proto/simple_models.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,15 @@ size_t SimpleRequestModel::deserialize(::simple::SimpleRequest& value) const noe
231231

232232
FieldModel<::simple::SimpleResponse>::FieldModel(FBEBuffer& buffer, size_t offset) noexcept : _buffer(buffer), _offset(offset)
233233
, id(buffer, 4 + 4)
234-
, Hash(buffer, id.fbe_offset() + id.fbe_size())
234+
, Length(buffer, id.fbe_offset() + id.fbe_size())
235+
, Hash(buffer, Length.fbe_offset() + Length.fbe_size())
235236
{}
236237

237238
size_t FieldModel<::simple::SimpleResponse>::fbe_body() const noexcept
238239
{
239240
size_t fbe_result = 4 + 4
240241
+ id.fbe_size()
242+
+ Length.fbe_size()
241243
+ Hash.fbe_size()
242244
;
243245
return fbe_result;
@@ -256,6 +258,7 @@ size_t FieldModel<::simple::SimpleResponse>::fbe_extra() const noexcept
256258

257259
size_t fbe_result = fbe_body()
258260
+ id.fbe_extra()
261+
+ Length.fbe_extra()
259262
+ Hash.fbe_extra()
260263
;
261264

@@ -297,6 +300,12 @@ bool FieldModel<::simple::SimpleResponse>::verify_fields(size_t fbe_struct_size)
297300
return false;
298301
fbe_current_size += id.fbe_size();
299302

303+
if ((fbe_current_size + Length.fbe_size()) > fbe_struct_size)
304+
return true;
305+
if (!Length.verify())
306+
return false;
307+
fbe_current_size += Length.fbe_size();
308+
300309
if ((fbe_current_size + Hash.fbe_size()) > fbe_struct_size)
301310
return true;
302311
if (!Hash.verify())
@@ -351,6 +360,12 @@ void FieldModel<::simple::SimpleResponse>::get_fields(::simple::SimpleResponse&
351360
fbe_value.id = FBE::uuid_t::sequential();
352361
fbe_current_size += id.fbe_size();
353362

363+
if ((fbe_current_size + Length.fbe_size()) <= fbe_struct_size)
364+
Length.get(fbe_value.Length);
365+
else
366+
fbe_value.Length = (uint32_t)0ull;
367+
fbe_current_size += Length.fbe_size();
368+
354369
if ((fbe_current_size + Hash.fbe_size()) <= fbe_struct_size)
355370
Hash.get(fbe_value.Hash);
356371
else
@@ -396,6 +411,7 @@ void FieldModel<::simple::SimpleResponse>::set(const ::simple::SimpleResponse& f
396411
void FieldModel<::simple::SimpleResponse>::set_fields(const ::simple::SimpleResponse& fbe_value) noexcept
397412
{
398413
id.set(fbe_value.id);
414+
Length.set(fbe_value.Length);
399415
Hash.set(fbe_value.Hash);
400416
}
401417

proto/simple_models.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class FieldModel<::simple::SimpleResponse>
166166

167167
public:
168168
FieldModel<FBE::uuid_t> id;
169+
FieldModel<uint32_t> Length;
169170
FieldModel<uint32_t> Hash;
170171
};
171172

0 commit comments

Comments
 (0)