public void UnpackFromMessage(Unpacker unpacker) { unpacker.ReadInt32(out count); unpacker.ReadString(out data); }
public void UnpackFromMessage( Unpacker unpacker ) { // Unpack fields are here: // temp variables long id; string name; // It should be packed as array because we use hand-made packing implementation above. if ( !unpacker.IsArrayHeader ) { throw new SerializationException( "Is not in array header." ); } // Check items count. if ( UnpackHelpers.GetItemsCount( unpacker ) != 2 ) { throw new SerializationException( $"Array length should be 2, but {UnpackHelpers.GetItemsCount( unpacker )}" ); } // Unpack fields here: if ( !unpacker.ReadInt64( out id ) ) { throw new SerializationException( "Property Id is not found." ); } this.Id = id; if ( !unpacker.ReadString( out name ) ) { throw new SerializationException( "Property Name is not found." ); } this.Name = name; // ...Instead, you can unpack from map as follows: //if ( !unpacker.IsMapHeader ) //{ // throw SerializationExceptions.NewIsNotMapHeader(); //} //// Check items count. //if ( UnpackHelpers.GetItemsCount( unpacker ) != 2 ) //{ // throw SerializationExceptions.NewUnexpectedArrayLength( 2, UnpackHelpers.GetItemsCount( unpacker ) ); //} //// Unpack fields here: //for ( int i = 0; i < 2 /* known count of fields */; i++ ) //{ // // Unpack and verify key of entry in map. // string key; // if ( !unpacker.ReadString( out key ) ) // { // // Missing key, incorrect. // throw SerializationExceptions.NewUnexpectedEndOfStream(); // } // switch ( key ) // { // case "Id": // { // if ( !unpacker.ReadInt64( out id ) ) // { // throw SerializationExceptions.NewMissingProperty( "Id" ); // } // // this.Id = id; // break; // } // case "Name": // { // if ( !unpacker.ReadString( out name ) ) // { // throw SerializationExceptions.NewMissingProperty( "Name" ); // } // // this.Name = name; // break; // } // // Note: You should ignore unknown fields for forward compatibility. // } //} }
/// <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; } } } }