Skip to content

Commit

Permalink
Improved list handling in hessian_ipc
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Stigsen committed Jul 20, 2010
1 parent c1dc19a commit 0255a7f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/hessian_ipc/hessian_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bool Reader::Parse(vector<unsigned char>::const_iterator begin, vector<unsigned
const bool result = ParseValue();
if (!result) return false; // need more input

if (m_result->IsList() || m_result->IsHandle()) {
if (m_state == list_1 || m_state == proxy_handle) {
m_stateStack.push_back(new savedstate(m_state, 0, m_result));
m_state = value_start;
continue;
Expand Down Expand Up @@ -58,17 +58,20 @@ bool Reader::Parse(vector<unsigned char>::const_iterator begin, vector<unsigned
}
case proxy_handle:
s.value->AsInteger() = m_result->GetInt();
m_result = s.value;

needmore = false;
break;
case list_1:
if (m_state == end_marker) needmore = false;
else s.value->AsList().Add(m_result);
break;
default:
throw value_exception("invalid state");
}

m_state = value_start;
if (needmore) break; // Parse more values;
else {
m_state = value_start;
m_result = s.value;
m_stateStack.pop_back();
}
}
Expand Down Expand Up @@ -293,7 +296,9 @@ bool Reader::ParseValue() {

// Variable-length untyped list
case 0x57:
break;
m_state = list_1;
m_result.reset(new List());
return true;

// Fixed-length list
case 'V':
Expand All @@ -313,6 +318,11 @@ bool Reader::ParseValue() {
case 0x7c: case 0x7d: case 0x7e: case 0x7f:
break;

// End marker for list
case 'Z':
m_state = end_marker;
return true;

// Remote Proxy Handle
case 'P':
m_result.reset(new ProxyHandle());
Expand Down
2 changes: 2 additions & 0 deletions src/hessian_ipc/hessian_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ namespace hessian_ipc {
string_data,
string_next,
proxy_handle,
list_1,
end_marker,
value_last
};

Expand Down
13 changes: 12 additions & 1 deletion src/hessian_ipc/hessian_values.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace hessian_ipc {
class String;
class Call;
class Writer;
class List;

enum fault_type {
ProtocolException,
Expand Down Expand Up @@ -131,6 +132,8 @@ namespace hessian_ipc {
virtual Date& AsDate() {throw value_exception("invalid value type");};
virtual String& AsString() {throw value_exception("invalid value type");};
virtual Call& AsCall() {throw value_exception("invalid value type");};
virtual List& AsList() {throw value_exception("invalid value type");};
virtual const List& AsList() const {throw value_exception("invalid value type");};

// dump
virtual void Print(std::string& out) const = 0;
Expand Down Expand Up @@ -278,13 +281,21 @@ namespace hessian_ipc {

// get the value
List& AsList() {return *this;};
const List& AsList() const {return *this;};

bool empty() const {return m_values.empty();};
size_t size() const {return m_values.size();};
const Value& get(size_t n) const {return m_values[n];};

// set value
void Add(auto_ptr<Value> v) {m_values.push_back(v);};

// dump
void Print(string&) const {};
void Write(Writer&) const {};

private:
boost::ptr_vector<Value> m_values;

};

class Call : public Value {
Expand Down

0 comments on commit 0255a7f

Please sign in to comment.