ON_Base64EncodeStream Class Reference

#include <opennurbs_base64.h>

Public Member Functions

 ON_Base64EncodeStream ()
 
virtual ~ON_Base64EncodeStream ()
 
bool Begin ()
 Call Begin() one time to initialize the base64 encoding calculation. Then call In() one or more times to submit the unencoded stream to the base64 encoding calculation. When you reach the end of the unencoded stream, call End(). More...
 
void * CallbackContext () const
 
ON_StreamCallbackFunction CallbackFunction () const
 
bool End ()
 After the last call to In(), call End(). Calling End() may generate one call to the output stream handler with the value of out_buffer_size = 4 to 76. More...
 
bool In (ON__UINT64 in_buffer_size, const void *in_buffer)
 Call In() one or more times to base64 encode a stream of bytes. After the last call to In(), call End(). Calling In() will result in at least in_buffer_size/57 and at most (in_buffer_size+56)/57 calls to to the output stream handler. More...
 
ON__UINT32 InCRC () const
 
ON__UINT64 InSize () const
 
virtual bool Out (void *callback_context, ON__UINT32 out_buffer_size, const char *out_buffer)
 If an explicit base 64 encoded stream output handler is not specified ( CallbackFunction() returns null ), then the virtual Out() function is called to handle the base 64 encoded output stream. As the input stream is encoded, one or more calls to Out() will occur. More...
 
ON__UINT32 OutCRC () const
 
ON__UINT64 OutSize () const
 
bool SetCallback (ON_StreamCallbackFunction callback_function, void *callback_context)
 ON_Base64EncodeStream delivers the base64 encoded stream by calling a base64 encoded stream output handler function. There are two options for specifying the base64 encoded stream output handler function. More...
 

Constructor & Destructor Documentation

◆ ON_Base64EncodeStream()

ON_Base64EncodeStream::ON_Base64EncodeStream ( )

◆ ~ON_Base64EncodeStream()

virtual ON_Base64EncodeStream::~ON_Base64EncodeStream ( )
virtual

Member Function Documentation

◆ Begin()

bool ON_Base64EncodeStream::Begin ( )

Call Begin() one time to initialize the base64 encoding calculation. Then call In() one or more times to submit the unencoded stream to the base64 encoding calculation. When you reach the end of the unencoded stream, call End().

Returns
true if successful, false if an error occured.

◆ CallbackContext()

void* ON_Base64EncodeStream::CallbackContext ( ) const
Returns
Current value of the context pointer passed as the first argument to the base64 encoded stream output handler function.

◆ CallbackFunction()

ON_StreamCallbackFunction ON_Base64EncodeStream::CallbackFunction ( ) const
Returns
Current value of the callback function for handling the base64 encoded stream. If the callback function is null, the the virtual Out() function is used to handle the output stream.

◆ End()

bool ON_Base64EncodeStream::End ( )

After the last call to In(), call End(). Calling End() may generate one call to the output stream handler with the value of out_buffer_size = 4 to 76.

Returns
true if successful, false if an error occured.

◆ In()

bool ON_Base64EncodeStream::In ( ON__UINT64  in_buffer_size,
const void *  in_buffer 
)

Call In() one or more times to base64 encode a stream of bytes. After the last call to In(), call End(). Calling In() will result in at least in_buffer_size/57 and at most (in_buffer_size+56)/57 calls to to the output stream handler.

Parameters
in_buffer_size[in] number of bytes in in_buffer
in_buffer[in]
Returns
true if successful, false if an error occured.

◆ InCRC()

ON__UINT32 ON_Base64EncodeStream::InCRC ( ) const
Returns
Then the returned value is the 32-bit crc of the input stream. The crc is updated every time In() is called before any calls are made to the output stream handler. If the base64 encoding calculation is finished ( End() has been called ), then the returned value is the 32-bit crc of the entire input stream.

◆ InSize()

ON__UINT64 ON_Base64EncodeStream::InSize ( ) const
Returns
Then the returned value is the total number bytes in the input stream. The size is updated every time In() is called before any calls are made to the output stream handler. If the calculation is finished ( End() has been called ), then the returned value is the total number of bytes in the entire input stream.

◆ Out()

virtual bool ON_Base64EncodeStream::Out ( void *  callback_context,
ON__UINT32  out_buffer_size,
const char *  out_buffer 
)
virtual

If an explicit base 64 encoded stream output handler is not specified ( CallbackFunction() returns null ), then the virtual Out() function is called to handle the base 64 encoded output stream. As the input stream is encoded, one or more calls to Out() will occur.

With a possible exception of the last call to Out(), when Out() is called, 57 input bytes have been encoded into 76 output characters with ASCII codes A-Z, a-z, 0-9, +, /.

Parameters
callback_context[in] context pointer set by calling SetCallback(). Typically the context pointer is not used by a virtual override because the context can be added as member variables of the derived class, but it is available if needed.
out_buffer_size[in] number of non-null characters in out_buffer.
out_buffer[in] A null terminated ASCII string that is a base 64 encoding. out_buffer[0...(out_buffer_size-1)] are ASCII characters with values characters with ASCII codes A-Z, a-z, 0-9, +, / and out_buffer[out_buffer_size] = 0.
Returns
True to continue base 64 encodeing and false to cancel the encoding calculation.

◆ OutCRC()

ON__UINT32 ON_Base64EncodeStream::OutCRC ( ) const
Returns
Then the returned value is the 32bit crc of the output stream. The crc is updated immediately after each call to the output stream handler. If the calculation is finished ( End() has been called ), then the returned value is the 32-bit crc of the entire output stream.

◆ OutSize()

ON__UINT64 ON_Base64EncodeStream::OutSize ( ) const
Returns
Then the returned value is the total number characters in the output stream. The size is incremented immediately after each call to the output stream handler. If the base64 encoding calculation is finished ( End() has been called ), then the returned value is the total number of bytes in the entire output stream.

◆ SetCallback()

bool ON_Base64EncodeStream::SetCallback ( ON_StreamCallbackFunction  callback_function,
void *  callback_context 
)

ON_Base64EncodeStream delivers the base64 encoded stream by calling a base64 encoded stream output handler function. There are two options for specifying the base64 encoded stream output handler function.

  1. Overriding the virtual Out() function.
  2. Providing a callback function. SetCallback() is used to specify a callback function to handle the base64 encoded stream and to specify a context pointer to be passed to either option of the handler.
Parameters
callback_function[in] Function to handle sections of the base64 encoded stream. If callback_function is null, then the virtual Out() function will be called. When callback_function is specified, it must return true if the base64 encoding calculation should continue and false to cancel the base64 encoding calculation.
callback_context[in] This value is passed as the first argument when calling callback_function or the virutal Out() function.
Returns
True if successful.

Once base64 encoding has started, it would be unusual to intentionally change the base64 encoded stream output handler, but you can do this if you need to.