BufferedSerializeAction.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2005-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #include "BufferedSerializeAction.h"
00018 #include "util/ExpandableBuffer.h"
00019 
00020 namespace oasys {
00021 /******************************************************************************
00022  *
00023  * BufferedSerializeAction
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 } // namespace oasys

Generated on Thu Jun 7 12:54:25 2007 for DTN Reference Implementation by  doxygen 1.5.1