CopyableBuffer::CopyableBuffer(const openpal::RSlice& buffer) : mpBuff(new uint8_t[buffer.Size()]), mSize(buffer.Size()) { openpal::WSlice dest(mpBuff, mSize); buffer.CopyTo(dest); }
void SocketChannel::BeginWriteImpl(const openpal::RSlice& buffer) { auto callback = [this](const std::error_code & ec, size_t num) { this->OnWriteCallback(ec, num); }; asio::async_write(socket, asio::buffer(buffer, buffer.Size()), this->executor->strand.wrap(callback)); }
bool NumParser::Read(uint16_t& num, openpal::RSlice& buffer) const { if (buffer.Size() < size) { return false; } else { num = pReadFun(buffer); return true; } }
APDUHeaderParser::Result<APDUHeader> APDUHeaderParser::ParseRequest(const openpal::RSlice& apdu, openpal::Logger* logger) { if (apdu.Size() < APDUHeader::REQUEST_SIZE) { FORMAT_LOGGER_BLOCK(logger, flags::WARN, "Request fragment with insufficient size of %u bytes", apdu.Size()); return Result<APDUHeader>::Error(); } return Result<APDUHeader>::Ok(APDUHeader(AppControlField(apdu[0]), FunctionCodeFromType(apdu[1])), apdu.Skip(APDUHeader::REQUEST_SIZE)); }
bool DecoderImpl::IsResponse(const openpal::RSlice& data) { if (data.Size() < 2) { return false; } switch (FunctionCodeFromType(data[1])) { case (FunctionCode::RESPONSE): case (FunctionCode::UNSOLICITED_RESPONSE): case (FunctionCode::AUTH_RESPONSE): return true; default: return false; } }
ParseResult NumParser::ParseRange(openpal::RSlice& buffer, Range& range, openpal::Logger* pLogger) const { if (buffer.Size() < (2 * static_cast<uint32_t>(size))) { SIMPLE_LOGGER_BLOCK(pLogger, flags::WARN, "Not enough data for start / stop"); return ParseResult::NOT_ENOUGH_DATA_FOR_RANGE; } else { range.start = this->ReadNum(buffer); range.stop = this->ReadNum(buffer); if (range.IsValid()) { return ParseResult::OK; } else { FORMAT_LOGGER_BLOCK(pLogger, flags::WARN, "start (%u) > stop (%u)", range.start, range.stop); return ParseResult::BAD_START_STOP; } } }
uint16_t CRC::CalcCrc(const openpal::RSlice& view) { return CalcCrc(view, view.Size()); }