BufferedSerializeAction.cc

Go to the documentation of this file.
00001 #include "BufferedSerializeAction.h"
00002 #include "util/ExpandableBuffer.h"
00003 
00004 namespace oasys {
00005 /******************************************************************************
00006  *
00007  * BufferedSerializeAction
00008  *
00009  *****************************************************************************/
00010 BufferedSerializeAction::BufferedSerializeAction(
00011     action_t  action,
00012     context_t context,
00013     u_char*   buf, 
00014     size_t    length,
00015     int       options)
00016 
00017     : SerializeAction(action, context, options),
00018       expandable_buf_(NULL),
00019       buf_(buf), length_(length), offset_(0)
00020 {
00021 }
00022 
00023 BufferedSerializeAction::BufferedSerializeAction(
00024     action_t          action,
00025     context_t         context,
00026     ExpandableBuffer* buf,
00027     int               options)
00028 
00029     : SerializeAction(action, context, options),
00030       expandable_buf_(buf),
00031       buf_(NULL), length_(0), offset_(0)
00032 {
00033     expandable_buf_->set_len(0);
00034 }
00035 
00036 u_char*
00037 BufferedSerializeAction::buf()
00038 {
00039     return (expandable_buf_ ? (u_char*)expandable_buf_->raw_buf() : buf_);
00040 }
00041 
00042 size_t
00043 BufferedSerializeAction::length()
00044 {
00045     return (expandable_buf_ ? expandable_buf_->buf_len() : length_);
00046 }
00047 
00048 size_t
00049 BufferedSerializeAction::offset()
00050 {
00051     return (expandable_buf_ ? expandable_buf_->len() : offset_);
00052 }
00053 
00059 u_char*
00060 BufferedSerializeAction::next_slice(size_t length)
00061 {
00062     u_char* ret;
00063     
00064     if (error())
00065         return NULL;
00066     
00067     if (expandable_buf_ != NULL) {
00068         ret = (u_char*)expandable_buf_->tail_buf(length);
00069         expandable_buf_->incr_len(length);
00070         return ret;
00071     }
00072     
00073     if (offset_ + length > length_) {
00074         signal_error();
00075         return NULL;
00076     }
00077 
00078     ret = &buf_[offset_];
00079     offset_ += length;
00080     return ret;
00081 }
00082 
00083 } // namespace oasys

Generated on Fri Dec 22 14:47:57 2006 for DTN Reference Implementation by  doxygen 1.5.1