1 00:00:05,910 --> 00:00:11,310 So now we can go over to libraries and begin creating our chat protocol. 2 00:00:12,730 --> 00:00:17,230 We want to implement going from the client and from the server. 3 00:00:17,230 --> 00:00:20,860 So we will create two enemies, client and server. 4 00:00:21,220 --> 00:00:26,440 But the first thing we're going to do is add in a couple of use statements that we're going to need. 5 00:00:26,440 --> 00:00:35,320 So we need to add in Saturday and in here we want de serialize and serialize. 6 00:00:36,240 --> 00:00:47,700 We also want to use standard sink and arc and then obviously bring in our utils. 7 00:00:48,180 --> 00:00:51,360 So now we can create our two enemies. 8 00:00:51,780 --> 00:00:54,930 So we'll have our client enum. 9 00:00:57,060 --> 00:01:00,090 Which is going to contain join. 10 00:01:00,630 --> 00:01:02,560 We're going to have a chat. 11 00:01:02,580 --> 00:01:07,440 Name of arc string. 12 00:01:08,790 --> 00:01:16,380 And then we're also going to have a post which is going to be chat name 13 00:01:19,620 --> 00:01:25,650 and contain a message of an arch string. 14 00:01:30,930 --> 00:01:34,860 And then there we go. 15 00:01:35,130 --> 00:01:39,070 And now we want our server enum, 16 00:01:42,960 --> 00:01:44,910 which we're going to have a message. 17 00:01:46,280 --> 00:01:47,870 Which will have a chat name. 18 00:01:53,390 --> 00:01:57,590 And then obviously we'll have a message. 19 00:02:02,220 --> 00:02:04,440 And they will have an air 20 00:02:07,950 --> 00:02:16,590 containing a string so we can make this a little bit more robust format using cargo format, and you'll 21 00:02:16,590 --> 00:02:20,130 see that it'll automatically do it for us. 22 00:02:21,540 --> 00:02:22,830 So now let's. 23 00:02:23,660 --> 00:02:30,770 Test out our set up real quick to make sure we are sending and receiving messages in the JSON format 24 00:02:30,770 --> 00:02:34,430 like we wanted so we can run 25 00:02:37,310 --> 00:02:40,970 test and then we'll say test our client. 26 00:02:43,790 --> 00:02:46,640 And then in here we'll add a use statement. 27 00:02:46,640 --> 00:02:47,630 We'll use. 28 00:02:52,040 --> 00:02:58,250 And I will say let client equal client post. 29 00:03:00,590 --> 00:03:07,970 And then inside here, we're going to have our chat name, which is going to be a new atomic reference 30 00:03:07,970 --> 00:03:13,850 counter and we'll say string from. 31 00:03:15,400 --> 00:03:26,350 We'll just call it chat and then we'll have our message, which will also be a reference counted string 32 00:03:26,350 --> 00:03:30,220 from message sent. 33 00:03:31,330 --> 00:03:31,930 All right. 34 00:03:33,960 --> 00:03:48,780 And that and I will create our JSON message using Saturday JSON to string a reference to our client 35 00:03:49,650 --> 00:03:53,940 and then we will unwrap it. 36 00:03:57,300 --> 00:04:01,720 And now we will assert equals Jason. 37 00:04:01,890 --> 00:04:09,630 And now we want to do create a JSON formatted post manually. 38 00:04:09,630 --> 00:04:11,190 So we'll do that right here. 39 00:04:12,240 --> 00:04:13,500 And it will be. 40 00:04:16,450 --> 00:04:17,470 Post. 41 00:04:21,460 --> 00:04:22,510 Chat. 42 00:04:22,960 --> 00:04:23,740 Name? 43 00:04:27,130 --> 00:04:27,970 Chat. 44 00:04:31,590 --> 00:04:34,350 Now we have our message. 45 00:04:37,730 --> 00:04:41,570 Which is a message sent. 46 00:04:44,050 --> 00:04:46,390 Now we will add. 47 00:04:48,550 --> 00:04:49,420 There we go. 48 00:04:50,320 --> 00:04:53,350 And we will also do assert equals. 49 00:04:54,740 --> 00:04:59,410 It's Saturday json from string. 50 00:04:59,410 --> 00:05:03,640 So we turn it back from a JSON value. 51 00:05:09,920 --> 00:05:20,330 Client Jason Dot unwrap and then make sure it matches our original message, which we created here. 52 00:05:22,790 --> 00:05:25,880 And I want this to be a reference. 53 00:05:26,830 --> 00:05:27,130 All right. 54 00:05:27,130 --> 00:05:28,870 So we see we have some squiggles here. 55 00:05:28,870 --> 00:05:33,400 So it says the trait bound client serialize is not satisfied. 56 00:05:33,760 --> 00:05:41,980 So luckily this is something the compiler tells us and it's actually a really easy fix for us to do. 57 00:05:42,490 --> 00:05:44,600 And it gave me all that. 58 00:05:44,620 --> 00:05:48,640 So now we want to derive a couple of traits. 59 00:05:48,640 --> 00:05:54,490 So we want to derive debug just in case we want to print anything out to the standard output. 60 00:05:54,910 --> 00:05:57,130 We want to derive the serialize. 61 00:05:58,310 --> 00:06:07,660 We want to derive serialize and since we're using assert equals, we actually also want to derive partial 62 00:06:07,700 --> 00:06:09,410 IQ for equality. 63 00:06:09,430 --> 00:06:17,260 That way it knows how to handle our assert equals in this case. 64 00:06:17,260 --> 00:06:20,170 And then I need to also add in. 65 00:06:21,550 --> 00:06:22,810 Collins right there. 66 00:06:24,040 --> 00:06:31,150 So now, if all this works correctly, we should be able to run cargo test and it will compile all of 67 00:06:31,150 --> 00:06:33,760 our dependencies for us, which will take a second. 68 00:06:34,030 --> 00:06:36,910 But then once it's done compiling this. 69 00:06:38,110 --> 00:06:40,090 And it runs our test cases. 70 00:06:40,090 --> 00:06:48,610 We should see that these outputted successfully that they ran okay and it did so we passed our test 71 00:06:48,610 --> 00:06:50,320 client which is great. 72 00:06:50,320 --> 00:07:01,900 So now we verified that we are creating a proper JSON from our message because we explicitly created 73 00:07:01,900 --> 00:07:06,070 a JSON formatted output of our message. 74 00:07:06,070 --> 00:07:15,220 But then we also made sure that when we want to go from JSON back to our string, it matches the original 75 00:07:15,220 --> 00:07:18,670 message which we were able to confirm in this case. 76 00:07:19,090 --> 00:07:24,850 So now that we are done with that, we can begin working on setting up our client.