Skip to content

Commit

Permalink
add reference to contribution guide and simplify example usage
Browse files Browse the repository at this point in the history
  • Loading branch information
farukeryilmaz committed Dec 10, 2023
1 parent 39df190 commit 19aacae
Showing 1 changed file with 26 additions and 41 deletions.
67 changes: 26 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,31 @@ Header-only C++20 library designed for efficient and flexible binary serializati
This is just one example among many possible scenarios demonstrating the diverse applications and versatility of `BytePack`. It provides a glimpse into the project's potential, encouraging users to explore a wide range of other use cases.
```cpp
// Sample struct for a conceptual usage scenario
struct GPSData {
std::uint32_t timestamp; // UNIX timestamp
double latitude; // Latitude in degrees
double longitude; // Longitude in degrees
float altitude; // Altitude in meters
std::uint16_t numSatellites; // Number of satellites in view
char deviceID[16]; // Device ID

void serialize(bytepack::binary_stream<>& stream) const {
stream.write(timestamp);
stream.write(latitude);
stream.write(longitude);
stream.write(altitude);
stream.write(numSatellites);
stream.write(deviceID);
}

void deserialize(bytepack::binary_stream<>& stream) {
stream.read(timestamp);
stream.read(latitude);
stream.read(longitude);
stream.read(altitude);
stream.read(numSatellites);
stream.read(deviceID);
}
struct SensorData {
std::uint64_t timestamp; // Time of measurement
double value; // Measured value
char sensor_id[16]; // Identifier of the sensor

void serialize(bytepack::binary_stream<>& stream) const {
stream.write(timestamp);
stream.write(value);
stream.write(sensor_id);
}

void deserialize(bytepack::binary_stream<>& stream) {
stream.read(timestamp);
stream.read(value);
stream.read(sensor_id);
}
};

GPSData gpsData{ 1701037875, 36.8805426411, 30.6692287448, 123.456f, 12, "GPS-DEVICE-1" };
SensorData sensorData{ 1701037875, 23.6, "Sensor-001" };

// default endian is big-endian (network byte order). you can change the endianness by passing
// the endian type as a template parameter, e.g. `bytepack::binary_stream<std::endian::little>`
bytepack::binary_stream serializationStream(1024); // 1024 is the buffer size in bytes
// Default endianness is big-endian (network byte order).
// little-endian configuration: `bytepack::binary_stream<std::endian::little>`
bytepack::binary_stream serializationStream(64); // 64 is the buffer size in bytes

gpsData.serialize(serializationStream);
sensorData.serialize(serializationStream);

bytepack::buffer_view buffer = serializationStream.data();

Expand All @@ -70,8 +61,8 @@ std::size_t dataSize = buffer.size(); // returns the serialized data size in byt
// e.g. `bytepack::buffer_view buffer(dataPtr, dataSize);`
bytepack::binary_stream deserializationStream(buffer);

GPSData gpsData_{};
gpsData_.deserialize(deserializationStream);
SensorData sensorData_{};
sensorData_.deserialize(deserializationStream);
```
## Requirements
Expand All @@ -82,26 +73,20 @@ gpsData_.deserialize(deserializationStream);
- **macOS:** `Xcode 14.3` or higher.
## Installation
Simply clone the repository or download the `bytepack.hpp` file and include it in your project.
Simply clone the repository or [download](https://github.com/farukeryilmaz/bytepack/blob/main/include/bytepack/bytepack.hpp) the `bytepack.hpp` file and include it in your project.
```bash
git clone https://github.com/farukeryilmaz/bytepack.git
```
If you want to run the tests, clone the repository with submodules (Catch2 v2.x):
```bash
git clone --recursive https://github.com/farukeryilmaz/bytepack.git
```
If the repository was cloned non-recursively previously, use `git submodule update --init` to clone the necessary submodules.

Include the library in your C++ project:
```cpp
#include "bytepack/bytepack.hpp"
```

## Design Philosophy
BytePack doesn't enforce any standardization, versioning, or the use of Interface Description Language (IDL) in serialization, providing you with the freedom to define your data structures and protocols. This approach is ideal when interfacing with systems where data formats and protocols are defined externally, as is often the case in standards like IEEE 12207, Interface Control Documents (ICD), Interface Design Description (IDD), and other industry-specific specifications. It allows you to seamlessly integrate BytePack into diverse projects, accommodating a wide range of requirements and compliance standards.
BytePack is a C++ library crafted with a clear focus on simplicity and flexibility in binary serialization, primarily for network communication. It does not enforce any standardization, versioning, or the use of Interface Description Language (IDL) in serialization, providing you with the freedom to define your data structures and protocols. This approach is ideal when interfacing with systems where data formats and protocols are defined externally, as is often the case in standards like IEEE 12207, Interface Control Documents (ICD), Interface Design Description (IDD), and other industry-specific specifications. It allows you to seamlessly integrate BytePack into diverse projects, accommodating a wide range of requirements and compliance standards.

## Contributions and Feedback
Contributions are welcome! If you encounter issues, have suggestions, or want to contribute to the development of the library, please feel free to open issues and submit pull requests.
Contributions are welcome! If you encounter issues, have suggestions, or want to contribute to the development of the library, please read the [Contribution Guideline](CONTRIBUTING.md).

For any questions, feedback, or inquiries, you can also reach out to me directly:
- **Email:** `faruk [at] farukeryilmaz [dot] com`
Expand Down

0 comments on commit 19aacae

Please sign in to comment.