Skip to content

Commit

Permalink
Add protocol server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chronoxor committed Jan 7, 2022
1 parent 8c3b4b6 commit e7d4b30
Show file tree
Hide file tree
Showing 8 changed files with 468 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/proto_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class SimpleProtoSession : public CppServer::Asio::TCPSession, public FBE::simpl
simple::SimpleResponse response;
response.id = request.id;
response.Hash = (uint32_t)hasher(request.Message);
response.Length = (uint32_t)request.Message.size();
send(response);
}

Expand Down
3 changes: 2 additions & 1 deletion performance/proto_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class ProtoSession : public TCPSession, public FBE::simple::Sender, public FBE::
// Send response
simple::SimpleResponse response;
response.id = request.id;
response.Hash = (uint32_t)request.Message.size();
response.Hash = 0;
response.Length = (uint32_t)request.Message.size();
send(response);
}

Expand Down
6 changes: 5 additions & 1 deletion proto/simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ std::ostream& operator<<(std::ostream& stream, const SimpleRequest& value)

SimpleResponse::SimpleResponse()
: id(FBE::uuid_t::sequential())
, Length((uint32_t)0ull)
, Hash((uint32_t)0ull)
{}

SimpleResponse::SimpleResponse(const FBE::uuid_t& arg_id, uint32_t arg_Hash)
SimpleResponse::SimpleResponse(const FBE::uuid_t& arg_id, uint32_t arg_Length, uint32_t arg_Hash)
: id(arg_id)
, Length(arg_Length)
, Hash(arg_Hash)
{}

Expand All @@ -79,13 +81,15 @@ void SimpleResponse::swap(SimpleResponse& other) noexcept
{
using std::swap;
swap(id, other.id);
swap(Length, other.Length);
swap(Hash, other.Hash);
}

std::ostream& operator<<(std::ostream& stream, const SimpleResponse& value)
{
stream << "SimpleResponse(";
stream << "id="; stream << "\"" << value.id << "\"";
stream << ",Length="; stream << value.Length;
stream << ",Hash="; stream << value.Hash;
stream << ")";
return stream;
Expand Down
2 changes: 2 additions & 0 deletions proto/simple.fbe
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ message SimpleResponse
{
// Response Id
uuid [id] = uuid1;
// Calculated message length
uint32 Length;
// Calculated message hash
uint32 Hash;
}
Expand Down
3 changes: 2 additions & 1 deletion proto/simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ namespace simple {
struct SimpleResponse
{
FBE::uuid_t id;
uint32_t Length;
uint32_t Hash;

size_t fbe_type() const noexcept { return 2; }

SimpleResponse();
SimpleResponse(const FBE::uuid_t& arg_id, uint32_t arg_Hash);
SimpleResponse(const FBE::uuid_t& arg_id, uint32_t arg_Length, uint32_t arg_Hash);
SimpleResponse(const SimpleResponse& other) = default;
SimpleResponse(SimpleResponse&& other) = default;
~SimpleResponse() = default;
Expand Down
18 changes: 17 additions & 1 deletion proto/simple_models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,15 @@ size_t SimpleRequestModel::deserialize(::simple::SimpleRequest& value) const noe

FieldModel<::simple::SimpleResponse>::FieldModel(FBEBuffer& buffer, size_t offset) noexcept : _buffer(buffer), _offset(offset)
, id(buffer, 4 + 4)
, Hash(buffer, id.fbe_offset() + id.fbe_size())
, Length(buffer, id.fbe_offset() + id.fbe_size())
, Hash(buffer, Length.fbe_offset() + Length.fbe_size())
{}

size_t FieldModel<::simple::SimpleResponse>::fbe_body() const noexcept
{
size_t fbe_result = 4 + 4
+ id.fbe_size()
+ Length.fbe_size()
+ Hash.fbe_size()
;
return fbe_result;
Expand All @@ -256,6 +258,7 @@ size_t FieldModel<::simple::SimpleResponse>::fbe_extra() const noexcept

size_t fbe_result = fbe_body()
+ id.fbe_extra()
+ Length.fbe_extra()
+ Hash.fbe_extra()
;

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

if ((fbe_current_size + Length.fbe_size()) > fbe_struct_size)
return true;
if (!Length.verify())
return false;
fbe_current_size += Length.fbe_size();

if ((fbe_current_size + Hash.fbe_size()) > fbe_struct_size)
return true;
if (!Hash.verify())
Expand Down Expand Up @@ -351,6 +360,12 @@ void FieldModel<::simple::SimpleResponse>::get_fields(::simple::SimpleResponse&
fbe_value.id = FBE::uuid_t::sequential();
fbe_current_size += id.fbe_size();

if ((fbe_current_size + Length.fbe_size()) <= fbe_struct_size)
Length.get(fbe_value.Length);
else
fbe_value.Length = (uint32_t)0ull;
fbe_current_size += Length.fbe_size();

if ((fbe_current_size + Hash.fbe_size()) <= fbe_struct_size)
Hash.get(fbe_value.Hash);
else
Expand Down Expand Up @@ -396,6 +411,7 @@ void FieldModel<::simple::SimpleResponse>::set(const ::simple::SimpleResponse& f
void FieldModel<::simple::SimpleResponse>::set_fields(const ::simple::SimpleResponse& fbe_value) noexcept
{
id.set(fbe_value.id);
Length.set(fbe_value.Length);
Hash.set(fbe_value.Hash);
}

Expand Down
1 change: 1 addition & 0 deletions proto/simple_models.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class FieldModel<::simple::SimpleResponse>

public:
FieldModel<FBE::uuid_t> id;
FieldModel<uint32_t> Length;
FieldModel<uint32_t> Hash;
};

Expand Down
Loading

0 comments on commit e7d4b30

Please sign in to comment.