Skip to content

A header-only template class to access bit-shifted data.

License

Notifications You must be signed in to change notification settings

tmattha/offset_ptr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

offset_ptr

Build Status

Usage

offset_ptr is expected to behave just like a regular pointer. Offsetted data will be written every time flush() is called or when the object is destructed. Check out test/offset_ptr_test.cpp for more examples.

Example

uint8_t raw[2];
raw[0] = 0x00;
raw[1] = 0x00;
const size_t offset = 2;
const uint8_t value = 0xAE; //1010 1110
optr::offset_ptr<uint8_t> int_ptr(raw, offset);
*int_ptr = value;
//raw will look like this: 00{10 1011 10}00 0000 (0x2B80).

Including

As offset_ptr is a template class all implementation is within its .hpp file. Just copy src/offset_ptr.hpp anywhere and use it. offset_ptr requires a compiler supporting at least the C++11 standard.

Use Case

offset_ptr is aimed to streamline the process of reading data from and writing data to bit-shifted raw data. The most common use case would be working with highly fixed-layout bus messages (like CAN frames).

Contributing

File an issue and submit a pull request if you want to.

About

A header-only template class to access bit-shifted data.

Resources

License

Stars

Watchers

Forks

Packages

No packages published