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. // } //} }