00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "BufferedSerializeAction.h"
00018 #include "util/ExpandableBuffer.h"
00019
00020 namespace oasys {
00021
00022
00023
00024
00025
00026 BufferedSerializeAction::BufferedSerializeAction(
00027 action_t action,
00028 context_t context,
00029 u_char* buf,
00030 size_t length,
00031 int options)
00032
00033 : SerializeAction(action, context, options),
00034 expandable_buf_(NULL),
00035 buf_(buf), length_(length), offset_(0)
00036 {
00037 }
00038
00039 BufferedSerializeAction::BufferedSerializeAction(
00040 action_t action,
00041 context_t context,
00042 ExpandableBuffer* buf,
00043 int options)
00044
00045 : SerializeAction(action, context, options),
00046 expandable_buf_(buf),
00047 buf_(NULL), length_(0), offset_(0)
00048 {
00049 expandable_buf_->set_len(0);
00050 }
00051
00052 u_char*
00053 BufferedSerializeAction::buf()
00054 {
00055 return (expandable_buf_ ? (u_char*)expandable_buf_->raw_buf() : buf_);
00056 }
00057
00058 size_t
00059 BufferedSerializeAction::length()
00060 {
00061 return (expandable_buf_ ? expandable_buf_->buf_len() : length_);
00062 }
00063
00064 size_t
00065 BufferedSerializeAction::offset()
00066 {
00067 return (expandable_buf_ ? expandable_buf_->len() : offset_);
00068 }
00069
00075 u_char*
00076 BufferedSerializeAction::next_slice(size_t length)
00077 {
00078 u_char* ret;
00079
00080 if (error())
00081 return NULL;
00082
00083 if (expandable_buf_ != NULL) {
00084 ret = (u_char*)expandable_buf_->tail_buf(length);
00085 expandable_buf_->incr_len(length);
00086 return ret;
00087 }
00088
00089 if (offset_ + length > length_) {
00090 signal_error();
00091 return NULL;
00092 }
00093
00094 ret = &buf_[offset_];
00095 offset_ += length;
00096 return ret;
00097 }
00098
00099 }