public override object ReadObject(Hessian2Reader reader, ObjectDefinition definition) { var result = new JavaStackTrace(); reader.AddRef(result); foreach (var key in definition.Fields) { switch (key) { case "declaringClass": result.DeclaringClass = reader.ReadString(); break; case "methodName": result.MethodName = reader.ReadString(); break; case "fileName": result.FileName = reader.ReadString(); break; case "lineNumber": result.LineNumber = reader.ReadInt(); break; } } return(result); }
public override object ReadMap(Hessian2Reader reader) { var result = new JavaStackTrace(); reader.AddRef(result); while (!reader.HasEnd()) { var key = reader.ReadString(); switch (key) { case "declaringClass": result.DeclaringClass = reader.ReadString(); break; case "methodName": result.MethodName = reader.ReadString(); break; case "fileName": result.FileName = reader.ReadString(); break; case "lineNumber": result.LineNumber = reader.ReadInt(); break; } } reader.ReadToEnd(); return(result); }
public override object ReadObject(Hessian2Reader reader) { var tag = reader.ReadListStart(); switch (tag) { case Constants.Null: return(null); case Constants.VariableList: return(ReadList(reader, -1)); case Constants.VariableUnTypeList: return(ReadList(reader, -1)); case Constants.FixedList: reader.ReadType(); return(ReadList(reader, reader.ReadInt())); case Constants.FixedUnTypeList: return(ReadList(reader, reader.ReadInt())); case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77: reader.ReadType(); return(ReadList(reader, tag - 0x70)); case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f: return(ReadList(reader, tag - 0x78)); default: throw new HessianException($"unknown code {(char)tag} where read type {Type.FullName}"); } }
public override object ReadList(Hessian2Reader reader, int length) { if (length >= 0) { switch (_type) { case BasicType.BoolArray: return(ReadArray(reader, length, reader.ReadBool)); case BasicType.SByteArray: return(ReadArray(reader, length, () => (sbyte)reader.ReadInt())); case BasicType.ShortArray: return(ReadArray(reader, length, reader.ReadShort)); case BasicType.UShortArray: return(ReadArray(reader, length, () => (ushort)reader.ReadInt())); case BasicType.IntArray: return(ReadArray(reader, length, reader.ReadInt)); case BasicType.UIntArray: return(ReadArray(reader, length, () => (uint)reader.ReadLong())); case BasicType.LongArray: return(ReadArray(reader, length, reader.ReadLong)); case BasicType.FloatArray: return(ReadArray(reader, length, reader.ReadFloat)); case BasicType.DoubleArray: return(ReadArray(reader, length, reader.ReadDouble)); case BasicType.StringArray: return(ReadArray(reader, length, reader.ReadString)); case BasicType.DateArray: return(ReadArray(reader, length, reader.ReadDate)); case BasicType.ObjectArray: return(ReadArray(reader, length, reader.ReadObject)); } } else { switch (_type) { case BasicType.BoolArray: return(ReadList(reader, reader.ReadBool)); case BasicType.SByteArray: return(ReadList(reader, () => (sbyte)reader.ReadInt())); case BasicType.ShortArray: return(ReadList(reader, reader.ReadShort)); case BasicType.UShortArray: return(ReadList(reader, () => (ushort)reader.ReadInt())); case BasicType.IntArray: return(ReadList(reader, reader.ReadInt)); case BasicType.UIntArray: return(ReadList(reader, () => (uint)reader.ReadLong())); case BasicType.LongArray: return(ReadList(reader, reader.ReadLong)); case BasicType.FloatArray: return(ReadList(reader, reader.ReadFloat)); case BasicType.DoubleArray: return(ReadList(reader, reader.ReadDouble)); case BasicType.StringArray: return(ReadList(reader, reader.ReadString)); case BasicType.DateArray: return(ReadList(reader, reader.ReadDate)); case BasicType.ObjectArray: return(ReadList(reader, reader.ReadObject)); } } throw new NotSupportedException(); }
public override object ReadObject(Hessian2Reader reader) { switch (_type) { case BasicType.Null: return(reader.ReadObject()); case BasicType.Bool: return(reader.ReadBool()); case BasicType.Byte: return((byte)reader.ReadInt()); case BasicType.SByte: return((sbyte)reader.ReadInt()); case BasicType.Short: return(reader.ReadShort()); case BasicType.UShort: return((ushort)reader.ReadInt()); case BasicType.Int: return(reader.ReadInt()); case BasicType.UInt: return((uint)reader.ReadLong()); case BasicType.Long: return(reader.ReadLong()); case BasicType.Float: return(reader.ReadFloat()); case BasicType.Double: return(reader.ReadDouble()); case BasicType.Char: var str = reader.ReadString(); return(string.IsNullOrEmpty(str) ? (char)0 : str[0]); case BasicType.CharArray: var charsString = reader.ReadString(); return(string.IsNullOrEmpty(charsString) ? new char[0] : charsString.ToCharArray()); case BasicType.String: return(reader.ReadString()); case BasicType.Date: return(reader.ReadDate()); case BasicType.ByteArray: return(reader.ReadBytes()); case BasicType.Object: return(reader.ReadObject()); case BasicType.BoolArray: case BasicType.ShortArray: case BasicType.IntArray: case BasicType.LongArray: case BasicType.FloatArray: case BasicType.StringArray: case BasicType.DoubleArray: case BasicType.SByteArray: case BasicType.UShortArray: case BasicType.UIntArray: case BasicType.DateArray: case BasicType.ObjectArray: return(reader.ReadObject()); default: throw new ArgumentOutOfRangeException(); } }
public static Response DecodeResponse(Stream inputStream) { var resHeader = new byte[16]; inputStream.ReadBytes(resHeader); if ((resHeader[2] & RequestFlag) != 0) { throw new ArgumentException("decode response fail. the stream is not response."); } var response = new Response { ResponseId = resHeader.ReadLong(4), Status = resHeader[3], IsEvent = (resHeader[2] & EventFlag) != 0, IsTwoWay = (resHeader[2] & TwowayFlag) != 0 }; var request = RequestTasks.GetRequestTask(response.ResponseId); var bodyLength = resHeader.ReadInt(12); var body = new byte[bodyLength]; inputStream.ReadBytes(body); var reader = new Hessian2Reader(new MemoryStream(body)); if (response.IsOk) { if (response.IsEvent) { response.Result = reader.ReadObject(); } else { var resultType = request?.Request.ReturnType; var flag = (byte)reader.ReadInt(); switch (flag) { case Response.Null: break; case Response.Value: response.Result = reader.ReadObject(resultType); break; case Response.Exception: response.Error = reader.ReadObject <JavaException>(); break; case Response.NullWithAttachment: response.Attachments = reader.ReadObject <Dictionary <string, string> >(); break; case Response.ValueWithAttachment: response.Result = reader.ReadObject(resultType); response.Attachments = reader.ReadObject <Dictionary <string, string> >(); break; case Response.ExceptionWithAttachment: response.Error = reader.ReadObject <JavaException>(); response.Attachments = reader.ReadObject <Dictionary <string, string> >(); break; default: throw new IOException("Unknown result flag, expect '0' '1' '2', get " + flag); } } } else { response.ErrorMessage = reader.ReadString(); response.Error = new Exception(response.ErrorMessage); } request?.Task.TrySetResult(response); return(response); }