Skip to content

add "object" type in protobuf to support js dynamic object #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pomelo-dotnetClient/src/protobuf/MsgDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ private JsonObject decodeMsg(JsonObject msg, JsonObject proto, int length)
object _name;
if (!msg.TryGetValue(name.ToString(), out _name))
{
msg.Add(name.ToString(), new List<object>());
msg.Add(name.ToString(), new JsonArray());
}
object value_type;
if (msg.TryGetValue(name.ToString(), out _name) && ((JsonObject)(value)).TryGetValue("type", out value_type))
{
decodeArray((List<object>)_name, value_type.ToString(), proto);
decodeArray((JsonArray)_name, value_type.ToString(), proto);
}
break;
}
Expand Down Expand Up @@ -148,6 +148,8 @@ private object decodeProp(string type, JsonObject proto)
return this.decodeDouble();
case "string":
return this.decodeString();
case "object":
return SimpleJson.SimpleJson.DeserializeObject(this.decodeString());
default:
return this.decodeObject(type, proto);
}
Expand Down
7 changes: 4 additions & 3 deletions pomelo-dotnetClient/src/protobuf/MsgEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ private int encodeMsg(byte[] buffer, int offset, JsonObject proto, JsonObject ms
object msg_key;
if (msg.TryGetValue(key, out msg_key))
{
if (((List<object>)msg_key).Count > 0)
if (((JsonArray)msg_key).Count > 0)
{
offset = encodeArray((List<object>)msg_key, (JsonObject)value, offset, buffer, proto);
offset = encodeArray((JsonArray)msg_key, (JsonObject)value, offset, buffer, proto);
}
}
break;
Expand All @@ -163,7 +163,7 @@ private int encodeMsg(byte[] buffer, int offset, JsonObject proto, JsonObject ms
/// <summary>
/// Encode the array type.
/// </summary>
private int encodeArray(List<object> msg, JsonObject value, int offset, byte[] buffer, JsonObject proto)
private int encodeArray(JsonArray msg, JsonObject value, int offset, byte[] buffer, JsonObject proto)
{
object value_type, value_tag;
if (value.TryGetValue("type", out value_type) && value.TryGetValue("tag", out value_tag))
Expand Down Expand Up @@ -209,6 +209,7 @@ private int encodeProp(object value, string type, int offset, byte[] buffer, Jso
case "double":
this.writeDouble(buffer, ref offset, value);
break;
case "object":
case "string":
this.writeString(buffer, ref offset, value);
break;
Expand Down