nlib
nn::nlib::Base64OutputStream Class Referencefinal

The class for writing data after encoding it in Base64. More...

#include "nn/nlib/Base64OutputStream.h"

+ Inheritance diagram for nn::nlib::Base64OutputStream:

Public Types

enum  NewLineMode {
  kNewLineModeNone = 0,
  kNewLineModeCrlf,
  kNewLineModeLf
}
 The newline options for the output Base64 text. The default is kNewLineModeNone. More...
 
- Public Types inherited from nn::nlib::OutputStream
enum  BufferingMode {
  kBufferingModeBlockBuffered = 0,
  kBufferingModeLineBuffered,
  kBufferingModeUnbuffered
}
 The buffering mode for OutputStream. More...
 

Public Member Functions

void SetNewLineMode (NewLineMode mode) noexcept
 Sets the newline mode. More...
 
Constructor, Destructor, and Initialization
constexpr Base64OutputStream () noexcept
 Instantiates the object with default parameters (default constructor).
 
errno_t Init (CharOption char_option) noexcept
 Initializes an object. For information on the arguments, see Base64Encoder::CharOption.
 
errno_t Init () noexcept
 Runs Init(Base64Encoder::kBase64Default).
 
virtual ~Base64OutputStream () noexcept override
 Destructor.
 
- Public Member Functions inherited from nn::nlib::OutputConverterStream
errno_t SetStream (OutputStream *ostr) noexcept
 Sets an output stream as the base stream. More...
 
OutputStreamGetStream () const noexcept
 Gets the input stream that will be the base stream. More...
 
- Public Member Functions inherited from nn::nlib::OutputStream
size_t Pos () const noexcept
 Returns the current position in the stream. More...
 
uint64_t Pos64 () const noexcept
 Returns the current position in the stream as a 64-bit integer. More...
 
bool Write (int b) noexcept
 Writes one byte of data to the stream. More...
 
bool Write (const void *p, size_t n) noexcept
 Writes n bytes of data to the stream. More...
 
bool WriteGather (const nlib_fd_iovec *iov, int iovcnt) noexcept
 Writes data from multiple non-continuous buffers to a stream. More...
 
bool Flush () noexcept
 Flushes the stream. More...
 
bool Close () noexcept
 Closes the stream after it has been flushed. Returns true if successful. More...
 
errno_t GetErrorValue () const noexcept
 Gets the error value. More...
 
BufferingMode GetBufferingMode () const noexcept
 Gets the buffering mode.
 
 operator bool () const
 Returns true if the object has been initialized and an error has not occurred inside, or returns false if an error has occurred inside.
 
constexpr OutputStream () noexcept
 Instantiates the object with default parameters (default constructor).
 
virtual ~OutputStream () noexcept
 Destructor.
 

Additional Inherited Members

- Protected Member Functions inherited from nn::nlib::OutputStream
void ResetBuffer (void *p, size_t nbytes) noexcept
 Sets the buffer held by OutputStream. More...
 
void SetError (errno_t e) const noexcept
 Sets an error to OutputStream. More...
 
- Protected Attributes inherited from nn::nlib::OutputStream
BufferingMode m_BufferingMode
 Stores the buffering mode. More...
 

Detailed Description

The class for writing data after encoding it in Base64.

Description
OutputConverterStream is held in the base class. When operating as OutputStream, the data is encoded in Base64. The InputConverterStream::SetStream function sets a stream, and then Base64-converted data is written to this stream.
If Base64OutputStream has been flushed, this stream is flushed after the Base64-converted data is written to it. Any data for which there are no set corresponding Base64 characters is held and not written to this stream.
If Base64OutputStream is closed, this stream is flushed after all data has been written to it and then it is detached. However, this stream is not closed.
Sample code is provided below.
char base64[128];
errno_t e = base64_stream.Init();
SUCCEED_IF(e == 0);
e = base64_stream.SetStream(&os);
SUCCEED_IF(e == 0);
const char* str = "Data to encode step1\nData to encode step2\n";
bool result = base64_stream.Write(str, nlib_strlen(str));
SUCCEED_IF(!!result);
result = base64_stream.Close();
SUCCEED_IF(!!result);
base64[os.Pos64()] = '\0';
result = os.Close();
SUCCEED_IF(!!result);
nlib_printf("converted:\n%s\n", base64);
/*
Output:
RGF0YSB0byBlbmNvZGUgc3RlcDEKRGF0YSB0byBlbmNvZGUgc3RlcDIK
*/
See also
https://www.ietf.org/rfc/rfc2045.txt (RFC2045, Base64)
The transition of the object state.
The overview of the object state transitions is described below:
dot_inline_dotgraph_4.png

Definition at line 24 of file Base64OutputStream.h.

Member Enumeration Documentation

◆ NewLineMode

The newline options for the output Base64 text. The default is kNewLineModeNone.

Enumerator
kNewLineModeNone 

Outputs Base64 text without newline characters. This is the default.

kNewLineModeCrlf 

Sets a newline every 76 characters using CRLF. This is what is expected of RFC 2045.

kNewLineModeLf 

Sets a newline every 76 characters using LF.

Definition at line 28 of file Base64OutputStream.h.

Member Function Documentation

◆ SetNewLineMode()

nn::nlib::Base64OutputStream::SetNewLineMode ( NewLineMode  mode)
noexcept

Sets the newline mode.

Parameters
[in]modeThe newline mode.

The documentation for this class was generated from the following files: