11using Pomelo . DotNetClient ;
22using System ;
33using System . Collections . Generic ;
4+ using SimpleJson ;
45
56namespace Pomelo . DotNetClient . Test
67{
@@ -9,24 +10,38 @@ public class TransportTest
910 static List < byte [ ] > result = new List < byte [ ] > ( ) ;
1011
1112 public static byte [ ] genBuffer ( int count ) {
12- byte [ ] buffer = new byte [ count + 4 ] ;
13+ int size = count + 6 ;
14+ byte [ ] buffer = new byte [ count + 10 ] ;
1315
1416 //Transporter tp = new Transporter(new Object(), protocol);
1517 buffer [ 0 ] = ( byte ) PackageType . PKG_DATA ;
16- buffer [ 1 ] = Convert . ToByte ( count >> 16 & 0xFF ) ;
17- buffer [ 2 ] = Convert . ToByte ( count >> 8 & 0xFF ) ;
18- buffer [ 3 ] = Convert . ToByte ( count & 0xFF ) ;
19-
18+ buffer [ 1 ] = Convert . ToByte ( size >> 16 & 0xFF ) ;
19+ buffer [ 2 ] = Convert . ToByte ( size >> 8 & 0xFF ) ;
20+ buffer [ 3 ] = Convert . ToByte ( size & 0xFF ) ;
21+
22+ //Generate message head
23+ //Response
24+ buffer [ 4 ] = 4 ;
25+ buffer [ 5 ] = 128 ;
26+ buffer [ 6 ] = 1 ;
27+
28+ //Route length
29+ buffer [ 7 ] = 2 ;
30+
31+ //Route
32+ buffer [ 8 ] = 62 ;
33+ buffer [ 9 ] = 72 ;
34+
2035 Random random = new Random ( ) ;
21- for ( var i = 0 ; i < count ; i ++ ) buffer [ 4 + i ] = ( byte ) random . Next ( 255 ) ;
36+ for ( var i = 0 ; i < count ; i ++ ) buffer [ 10 + i ] = ( byte ) random . Next ( 255 ) ;
2237
2338 return buffer ;
2439 }
2540
2641 public static byte [ ] generateBuffers ( int num , out List < byte [ ] > list ) {
2742 int length = 100 ;
2843 int index = 0 ;
29- byte [ ] result = new byte [ ( length + 4 ) * num ] ;
44+ byte [ ] result = new byte [ ( length + 10 ) * num ] ;
3045 list = new List < byte [ ] > ( ) ;
3146
3247 for ( int i = 0 ; i < num ; i ++ ) {
@@ -50,7 +65,7 @@ public static void Run(){
5065
5166 int offset = 0 ;
5267 while ( offset < buffer . Length ) {
53- int length = 1 ;
68+ int length = 200 ;
5469 length = ( offset + length ) > buffer . Length ? buffer . Length - offset : length ;
5570
5671 tc . processBytes ( buffer , offset , offset + length ) ;
@@ -68,6 +83,17 @@ public static void process(byte[] bytes){
6883 result . Add ( bytes ) ;
6984 //Console.WriteLine("add bytes : {0}", result.Count);
7085 }
86+
87+ public static void protocolProcess ( byte [ ] bytes ) {
88+ JsonObject dict = new JsonObject ( ) ;
89+ JsonObject serverProtos = new JsonObject ( ) ;
90+ JsonObject clientProtos = new JsonObject ( ) ;
91+
92+ MessageProtocol messageProtocol = new MessageProtocol ( dict , serverProtos , clientProtos ) ;
93+ Package pkg = PackageProtocol . decode ( bytes ) ;
94+
95+ messageProtocol . decode ( pkg . body ) ;
96+ }
7197
7298 public static bool check ( List < byte [ ] > list ) {
7399 byte [ ] [ ] origin = list . ToArray ( ) ;
0 commit comments