public void UnpackFromMessage(Unpacker unpacker) { int codeResult; MessagePackObject obj; unpacker.ReadInt32(out codeResult); unpacker.ReadObject(out obj); ParseIProtoResponse(codeResult, obj); unpacker.ReadInt32(out codeResult); unpacker.ReadObject(out obj); ParseIProtoResponse(codeResult, obj); unpacker.ReadInt32(out codeResult); unpacker.ReadObject(out obj); ParseIProtoResponse(codeResult, obj); unpacker.ReadObject(out obj); if (obj.IsDictionary) { var dict = obj.AsDictionary(); if (dict.Keys.Count > 0) { foreach (var key in dict.Keys) { var code = key.AsInt32(); ParseIProtoResponse(code, dict[key]); } } } }
public int PopInt() { int rst = 0; unpacker.ReadInt32(out rst); return(rst); }
protected internal override Version UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Version), 4); } long length = UnpackHelpers.GetItemsCount(unpacker); if (length != 4) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Version), 4); } int major, minor, build, revision; if (!unpacker.ReadInt32(out major)) { SerializationExceptions.ThrowMissingItem(0, unpacker); } if (!unpacker.ReadInt32(out minor)) { SerializationExceptions.ThrowMissingItem(1, unpacker); } if (!unpacker.ReadInt32(out build)) { SerializationExceptions.ThrowMissingItem(2, unpacker); } if (!unpacker.ReadInt32(out revision)) { SerializationExceptions.ThrowMissingItem(3, unpacker); } if (build < 0 && revision < 0) { return(new Version(major, minor)); } else if (revision < 0) { return(new Version(major, minor, build)); } return(new Version(major, minor, build, revision)); }
public static Int32 UnpackInt32Value(Unpacker unpacker, Type objectType, String memberName) { try { Int32 result; if (!unpacker.ReadInt32(out result)) { throw SerializationExceptions.NewFailedToDeserializeMember(objectType, memberName, null); } return(result); } catch (MessageTypeException ex) { throw SerializationExceptions.NewFailedToDeserializeMember(objectType, memberName, ex); } }
public static Int32 UnpackInt32Value( Unpacker unpacker, Type objectType, String memberName ) { try { Int32 result; if ( !unpacker.ReadInt32( out result ) ) { throw SerializationExceptions.NewFailedToDeserializeMember( objectType, memberName, null ); } return result; } catch ( MessageTypeException ex ) { throw SerializationExceptions.NewFailedToDeserializeMember( objectType, memberName, ex ); } }
public static Int32 UnpackInt32Value( Unpacker unpacker, Type objectType, String memberName ) { if ( unpacker == null ) { SerializationExceptions.ThrowArgumentNullException( "unpacker" ); } if ( objectType == null ) { SerializationExceptions.ThrowArgumentNullException( "objectType" ); } if ( memberName == null ) { SerializationExceptions.ThrowArgumentNullException( "memberName" ); } #if ASSERT Contract.Assert( unpacker != null ); Contract.Assert( objectType != null ); Contract.Assert( memberName != null ); #endif // ASSERT // ReSharper disable once RedundantAssignment var ctx = default( UnpackerTraceContext ); InitializeUnpackerTrace( unpacker, ref ctx ); try { Int32 result; if ( !unpacker.ReadInt32( out result ) ) { SerializationExceptions.ThrowFailedToDeserializeMember( objectType, memberName, null ); } Trace( ctx, "ReadDirect", unpacker, memberName ); return result; } catch ( MessageTypeException ex ) { SerializationExceptions.ThrowFailedToDeserializeMember( objectType, memberName, ex ); return default( Int32 ); // never reaches. } }
/// <summary> /// Unpacks the message from a MessagePack object /// This method should not be called directly, use deserialize instead. /// </summary> /// <param name="unpacker">The unpacker</param> public void UnpackFromMessage(Unpacker unpacker) { string dcs, dac, dad, dbd, dbb, day, dau, dag, dai, daj, dak, dcg; int dbc; if (!unpacker.IsMapHeader) { throw SerializationExceptions.NewIsNotMapHeader(); } if (UnpackHelpers.GetItemsCount(unpacker) != MapCount) { throw SerializationExceptions.NewUnexpectedArrayLength(MapCount, UnpackHelpers.GetItemsCount(unpacker)); } for (var i = 0; i < MapCount; i++) { string key; if (!unpacker.ReadString(out key)) { throw SerializationExceptions.NewUnexpectedEndOfStream(); } switch (key) { case "DCS": { if (!unpacker.ReadString(out dcs)) { throw SerializationExceptions.NewMissingProperty("dcs"); } Dcs = dcs; break; } case "DAC": { if (!unpacker.ReadString(out dac)) { throw SerializationExceptions.NewMissingProperty("dac"); } Dac = dac; break; } case "DAD": { if (!unpacker.ReadString(out dad)) { throw SerializationExceptions.NewMissingProperty("dad"); } Dad = dad; break; } case "DBD": { if (!unpacker.ReadString(out dbd)) { throw SerializationExceptions.NewMissingProperty("dbd"); } Dbd = DateTime.Parse(dbd); break; } case "DBB": { if (!unpacker.ReadString(out dbb)) { throw SerializationExceptions.NewMissingProperty("dbb"); } Dbb = DateTime.Parse(dbb); break; } case "DBC": { if (!unpacker.ReadInt32(out dbc)) { throw SerializationExceptions.NewMissingProperty("dbc"); } Dbc = (Sex)dbc; break; } case "DAY": { if (!unpacker.ReadString(out day)) { throw SerializationExceptions.NewMissingProperty("day"); } Day = GetEyeColor(day); break; } case "DAU": { if (!unpacker.ReadString(out dau)) { throw SerializationExceptions.NewMissingProperty("dau"); } Dau = new Height { AnsiFormat = dau }; break; } case "DAG": { if (!unpacker.ReadString(out dag)) { throw SerializationExceptions.NewMissingProperty("dag"); } Dag = dag; break; } case "DAI": { if (!unpacker.ReadString(out dai)) { throw SerializationExceptions.NewMissingProperty("dai"); } Dai = dai; break; } case "DAJ": { if (!unpacker.ReadString(out daj)) { throw SerializationExceptions.NewMissingProperty("daj"); } Daj = daj; break; } case "DAK": { if (!unpacker.ReadString(out dak)) { throw SerializationExceptions.NewMissingProperty("dak"); } Dak = new PostalCode { AnsiFormat = dak }; break; } case "DCG": { if (!unpacker.ReadString(out dcg)) { throw SerializationExceptions.NewMissingProperty("dcg"); } Dcg = dcg; break; } case "ZAA": { if (!unpacker.Read()) { throw SerializationExceptions.NewMissingProperty("zaa"); } var ms = new MemoryStream(unpacker.LastReadData.AsBinary()); Image = Image.FromStream(ms); break; } case "ZAB": { if (!unpacker.Read()) { throw SerializationExceptions.NewMissingProperty("zab"); } Fingerprint = new Fingerprint { AsIsoTemplate = unpacker.LastReadData.AsBinary() }; break; } } } }
private static PresenceMessage DeserializePresenceMessage(Unpacker unpacker) { PresenceMessage message = new PresenceMessage(); long fields; unpacker.ReadMapLength(out fields); string fieldName; for (int i = 0; i < fields; i++) { unpacker.ReadString(out fieldName); switch (fieldName) { case PresenceMessage.ActionPropertyName: { int result; unpacker.ReadInt32(out result); message.Action = (PresenceMessage.ActionType)result; } break; case PresenceMessage.IdPropertyName: { string result; unpacker.ReadString(out result); message.Id = result; } break; case PresenceMessage.ClientIdPropertyName: { string result; unpacker.ReadString(out result); message.ClientId = result; } break; case PresenceMessage.ConnectionIdPropertyName: { string result; unpacker.ReadString(out result); message.ConnectionId = result; } break; case PresenceMessage.TimestampPropertyName: { long result; unpacker.ReadInt64(out result); message.Timestamp = result.FromUnixTimeInMilliseconds(); } break; case PresenceMessage.DataPropertyName: { MessagePackObject result = unpacker.ReadItemData(); message.Data = ParseResult(result); } break; } } return(message); }