Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
ByteStream: calculate size from length plus counter
Browse files Browse the repository at this point in the history
Length is decremented / counter incremented when advancing pointer.
  • Loading branch information
anonimal committed Feb 19, 2018
1 parent b3e3c68 commit 6f4e0c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions src/core/util/byte_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

#include "core/util/byte_stream.h"

#include <cstring>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <memory>
#include <sstream>
Expand All @@ -46,11 +46,10 @@ namespace kovri
{
namespace core
{

// Input
ByteStream::ByteStream(const std::uint8_t* data, std::size_t len)
: m_DataPtr(const_cast<std::uint8_t*>(data)), m_Size(len), m_Length(len), m_Counter{}
// TODO(anonimal): remove const cast!
: m_DataPtr(const_cast<std::uint8_t*>(data)), m_Length(len), m_Counter{}
// TODO(anonimal): remove const cast!
{
assert(data || len);

Expand All @@ -62,7 +61,7 @@ ByteStream::ByteStream(const std::uint8_t* data, std::size_t len)

// Output
ByteStream::ByteStream(std::uint8_t* data, std::size_t len)
: m_DataPtr(data), m_Size(len), m_Length(len), m_Counter{}
: m_DataPtr(data), m_Length(len), m_Counter{}
{
assert(data || len);

Expand All @@ -72,8 +71,7 @@ ByteStream::ByteStream(std::uint8_t* data, std::size_t len)
throw std::length_error("ByteStream: null length");
}

ByteStream::ByteStream(std::size_t len)
: m_Size(len), m_Length(len), m_Counter{}
ByteStream::ByteStream(std::size_t len) : m_Length(len), m_Counter{}
{
assert(len);

Expand Down
2 changes: 1 addition & 1 deletion src/core/util/byte_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ByteStream
/// @return Total size
std::size_t Size() const noexcept
{
return m_Size;
return m_Length + m_Counter;
}

/// @brief Get the current position in the stream
Expand Down

0 comments on commit 6f4e0c7

Please sign in to comment.