29 namespace fletchgen::srec {
71 static std::optional<Record>
FromString(
const std::string &line);
98 default:
throw std::domain_error(
"SREC data records can only have 16, 24 or 32-bit address fields.");
103 std::string
ToString(
bool line_feed =
false);
106 [[nodiscard]]
inline uint32_t
address()
const {
return address_; }
108 [[nodiscard]]
inline size_t size()
const {
return size_; }
110 [[nodiscard]]
inline uint8_t *
data()
const {
return data_; }
114 Type type_ = RESERVED;
118 uint32_t address_ = 0;
120 uint8_t *data_ =
nullptr;
125 uint8_t byte_count();
130 inline void PutHex(std::stringstream &stream, uint32_t val,
int characters = 2) {
131 stream << std::uppercase << std::hex << std::setfill(
'0') << std::setw(characters) << val;
147 File(uint32_t start_address,
const uint8_t *
data,
size_t size,
const std::string &header_str =
"HDR");
153 explicit File(std::istream *input);
159 void write(std::ostream *output);
169 void ToBuffer(uint8_t **buffer,
size_t *size);
Structure to build up a single Record of an SREC file.
static Record Header(const std::string &header_str="HDR", uint16_t address=0)
Create an SREC header Record.
Type
The SREC Record type.
static constexpr size_t MAX_DATA_BYTES
Maximum number of data bytes per Record.
Record(const Record &rec)
SREC Record copy constructor.
size_t size() const
Return the size in bytes of this record.
uint32_t address() const
Return the address of this record.
uint8_t * data() const
Return the data source pointer of this record.
std::string ToString(bool line_feed=false)
Return the SREC Record string.
static Record Data(uint32_t srec_address, const uint8_t *data, size_t size)
Create an SREC data Record.
~Record()
Record destructor.
static std::optional< Record > FromString(const std::string &line)
Attempt to construct a Record from a string.
std::shared_ptr< Type > data(int width)
Fletcher data.
Structure to build up an SREC file with multiple Record lines.
void ToBuffer(uint8_t **buffer, size_t *size)
Convert an SREC file to a raw buffer.
std::vector< Record > records
SREC records in this file.
void write(std::ostream *output)
Write the SREC file to an output stream.