Skip to content

Commit

Permalink
Merge pull request #21 from cisco/paulej_encoding_length
Browse files Browse the repository at this point in the history
Allow one to check required buffer size for encoding
  • Loading branch information
paulej authored Apr 4, 2023
2 parents 45ad0e2 + e726533 commit 8b0ceb2
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 99 deletions.
11 changes: 1 addition & 10 deletions include/data_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,7 @@ namespace gs
*/
class DataBufferException : public std::runtime_error
{
public:
explicit DataBufferException(const std::string &what_arg) :
std::runtime_error(what_arg)
{
}

explicit DataBufferException(const char *what_arg) :
std::runtime_error(what_arg)
{
}
using std::runtime_error::runtime_error;
};

// DataBuffer object declaration
Expand Down
11 changes: 1 addition & 10 deletions include/gs_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,7 @@ namespace gs
// DecoderException exception definition
class DecoderException : public std::runtime_error
{
public:
explicit DecoderException(const std::string &what_arg) :
std::runtime_error(what_arg)
{
}

explicit DecoderException(const char *what_arg) :
std::runtime_error(what_arg)
{
}
using std::runtime_error::runtime_error;
};

// Game State Decoder object
Expand Down
11 changes: 1 addition & 10 deletions include/gs_deserializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,7 @@ namespace gs
// DeserializerException exception definition
class DeserializerException : public std::runtime_error
{
public:
explicit DeserializerException(const std::string &what_arg) :
std::runtime_error(what_arg)
{
}

explicit DeserializerException(const char *what_arg) :
std::runtime_error(what_arg)
{
}
using std::runtime_error::runtime_error;
};

// Game State Deserializer object
Expand Down
18 changes: 8 additions & 10 deletions include/gs_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,7 @@ namespace gs
// EncoderException exception definition
class EncoderException : public std::runtime_error
{
public:
explicit EncoderException(const std::string &what_arg) :
std::runtime_error(what_arg)
{
}

explicit EncoderException(const char *what_arg) :
std::runtime_error(what_arg)
{
}
using std::runtime_error::runtime_error;
};

// Return result from Encode() calls, which is a count of objects and
Expand Down Expand Up @@ -105,6 +96,13 @@ class Encoder
EncodeResult Encode(DataBuffer &data_buffer,
const UnknownObject &value);

// Determine the required buffer length to encode objects
template <typename T>
EncodeResult GetEncodeLength(const T &value)
{
return Encode(null_buffer, value);
}

// Ensure no implicit conversions calling Encode
template <typename T>
EncodeResult Encode(DataBuffer &data_buffer, const T &value) = delete;
Expand Down
11 changes: 1 addition & 10 deletions include/gs_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,7 @@ namespace gs
// SerializerException exception definition
class SerializerException : public std::runtime_error
{
public:
explicit SerializerException(const std::string &what_arg) :
std::runtime_error(what_arg)
{
}

explicit SerializerException(const char *what_arg) :
std::runtime_error(what_arg)
{
}
using std::runtime_error::runtime_error;
};

// Game State Serializer object
Expand Down
28 changes: 14 additions & 14 deletions src/gs_api_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ int GSSerializeObject(GS_Encoder_Context_Internal &context,
if (object.parent_present) object1.parent = gs::ObjectID{object.parent};

// Serialize the object
auto [object_count,
octet_count] = context.encoder.Encode(context.data_buffer, object1);
auto [object_count, octet_count] =
context.encoder.Encode(context.data_buffer, object1);

return static_cast<int>(object_count);
}
Expand Down Expand Up @@ -453,8 +453,8 @@ int GSSerializeObject(GS_Encoder_Context_Internal &context,
if (object.ipd_present) head1.ipd = gs::HeadIPD1{object.ipd.ipd};

// Serialize the object
auto [object_count,
octet_count] = context.encoder.Encode(context.data_buffer, head1);
auto [object_count, octet_count] =
context.encoder.Encode(context.data_buffer, head1);

return static_cast<int>(object_count);
}
Expand Down Expand Up @@ -493,8 +493,8 @@ int GSSerializeObject(GS_Encoder_Context_Internal &context,
SerializeCopy(object.rotation, hand1.rotation);

// Serialize the object
auto [object_count,
octet_count] = context.encoder.Encode(context.data_buffer, hand1);
auto [object_count, octet_count] =
context.encoder.Encode(context.data_buffer, hand1);

return static_cast<int>(object_count);
}
Expand Down Expand Up @@ -555,8 +555,8 @@ int GSSerializeObject(GS_Encoder_Context_Internal &context,
}

// Serialize the object
auto [object_count,
octet_count] = context.encoder.Encode(context.data_buffer, mesh1);
auto [object_count, octet_count] =
context.encoder.Encode(context.data_buffer, mesh1);

return static_cast<int>(object_count);
}
Expand Down Expand Up @@ -601,8 +601,8 @@ int GSSerializeObject(GS_Encoder_Context_Internal &context,
SerializeCopy(object.pinky, hand2.pinky);

// Serialize the object
auto [object_count,
octet_count] = context.encoder.Encode(context.data_buffer, hand2);
auto [object_count, octet_count] =
context.encoder.Encode(context.data_buffer, hand2);

return static_cast<int>(object_count);
}
Expand Down Expand Up @@ -640,8 +640,8 @@ int GSSerializeObject(GS_Encoder_Context_Internal &context,
object.data + object.data_length);

// Serialize the object
auto [object_count,
octet_count] = context.encoder.Encode(context.data_buffer, unknown);
auto [object_count, octet_count] =
context.encoder.Encode(context.data_buffer, unknown);

return static_cast<int>(object_count);
}
Expand Down Expand Up @@ -676,8 +676,8 @@ int GSSerializeObject(GS_Encoder_Context_Internal &context,
head_ipd1.ipd.value = object.ipd;

// Serialize the object
auto [object_count,
octet_count] = context.encoder.Encode(context.data_buffer, head_ipd1);
auto [object_count, octet_count] =
context.encoder.Encode(context.data_buffer, head_ipd1);

return static_cast<int>(object_count);
}
Expand Down
Loading

0 comments on commit 8b0ceb2

Please sign in to comment.