|
354 | 354 | { |
355 | 355 | assert(packet.length >= N); |
356 | 356 | } |
357 | | -body |
| 357 | +do |
358 | 358 | { |
359 | 359 | return cast(string)packet.consume(N); |
360 | 360 | } |
|
365 | 365 | { |
366 | 366 | assert(packet.length >= N); |
367 | 367 | } |
368 | | -body |
| 368 | +do |
369 | 369 | { |
370 | 370 | auto result = packet[0..N]; |
371 | 371 | packet = packet[N..$]; |
|
404 | 404 | { |
405 | 405 | static assert(N == T.sizeof); |
406 | 406 | } |
407 | | -body |
| 407 | +do |
408 | 408 | { |
409 | 409 | enforce!MYXProtocol(packet.length, "Supplied byte array is zero length"); |
410 | 410 | uint length = packet.front; |
|
427 | 427 | { |
428 | 428 | static assert(N == T.sizeof); |
429 | 429 | } |
430 | | -body |
| 430 | +do |
431 | 431 | { |
432 | 432 | return toDate(packet.consume(5)); |
433 | 433 | } |
|
438 | 438 | assert(packet.length); |
439 | 439 | assert(N == T.sizeof); |
440 | 440 | } |
441 | | -body |
| 441 | +do |
442 | 442 | { |
443 | 443 | auto numBytes = packet.consume!ubyte(); |
444 | 444 | if(numBytes == 0) |
|
468 | 468 | { |
469 | 469 | static assert(T.sizeof >= N, T.stringof~" not large enough to store "~to!string(N)~" bytes"); |
470 | 470 | } |
471 | | -body |
| 471 | +do |
472 | 472 | { |
473 | 473 | return packet.length >= N; |
474 | 474 | } |
|
481 | 481 | static assert(T.sizeof >= N, T.stringof~" not large enough to store "~to!string(N)~" bytes"); |
482 | 482 | assert(packet.hasEnoughBytes!(T,N), "packet not long enough to contain all bytes needed for "~T.stringof); |
483 | 483 | } |
484 | | -body |
| 484 | +do |
485 | 485 | { |
486 | 486 | T value = 0; |
487 | 487 | static if(N == 8) // 64 bit |
|
518 | 518 | static assert(T.sizeof >= N, T.stringof~" not large enough to store "~to!string(N)~" bytes"); |
519 | 519 | assert(packet.hasEnoughBytes!(T,N), "packet not long enough to contain all bytes needed for "~T.stringof); |
520 | 520 | } |
521 | | -body |
| 521 | +do |
522 | 522 | { |
523 | 523 | // The uncommented line triggers a template deduction error, |
524 | 524 | // so we need to store a temporary first |
|
548 | 548 | static assert((is(T == float) && N == float.sizeof) |
549 | 549 | || is(T == double) && N == double.sizeof); |
550 | 550 | } |
551 | | -body |
| 551 | +do |
552 | 552 | { |
553 | 553 | T result = 0; |
554 | 554 | (cast(ubyte*)&result)[0..T.sizeof] = packet[0..T.sizeof]; |
|
562 | 562 | static assert((is(T == float) && N == float.sizeof) |
563 | 563 | || is(T == double) && N == double.sizeof); |
564 | 564 | } |
565 | | -body |
| 565 | +do |
566 | 566 | { |
567 | 567 | return packet.consume(T.sizeof).decode!T(); |
568 | 568 | } |
|
785 | 785 | { |
786 | 786 | assert(packet.length >= 1, "packet has to include at least the LCB length byte"); |
787 | 787 | } |
788 | | -body |
| 788 | +do |
789 | 789 | { |
790 | 790 | auto lcb = packet.decodeLCBHeader(); |
791 | 791 | if(lcb.isNull || lcb.isIncomplete) |
|
809 | 809 | { |
810 | 810 | assert(packet.length >= 1, "packet has to include at least the LCB length byte"); |
811 | 811 | } |
812 | | -body |
| 812 | +do |
813 | 813 | { |
814 | 814 | LCB lcb; |
815 | 815 | lcb.numBytes = getNumLCBBytes(packet.front); |
|
849 | 849 | { |
850 | 850 | assert(packet.length >= 1, "packet has to include at least the LCB length byte"); |
851 | 851 | } |
852 | | -body |
| 852 | +do |
853 | 853 | { |
854 | 854 | auto lcb = packet.decodeLCBHeader(); |
855 | 855 | if(lcb.isNull || lcb.isIncomplete) |
|
879 | 879 | { |
880 | 880 | assert(packet.length >= 1, "LCS packet needs to store at least the LCB header"); |
881 | 881 | } |
882 | | -body |
| 882 | +do |
883 | 883 | { |
884 | 884 | auto lcb = packet.consumeIfComplete!LCB(); |
885 | 885 | assert(!lcb.isIncomplete); |
|
898 | 898 | { |
899 | 899 | assert(n <= array.length); |
900 | 900 | } |
901 | | -body |
| 901 | +do |
902 | 902 | { |
903 | 903 | array = array[n..$]; |
904 | 904 | return array; |
|
921 | 921 | else |
922 | 922 | assert(array.length >= T.sizeof, "Not enough space to unpack "~T.stringof); |
923 | 923 | } |
924 | | -body |
| 924 | +do |
925 | 925 | { |
926 | 926 | static if(T.sizeof >= 1) |
927 | 927 | { |
@@ -957,7 +957,7 @@ out(result) |
957 | 957 | { |
958 | 958 | assert(result.length >= 1); |
959 | 959 | } |
960 | | -body |
| 960 | +do |
961 | 961 | { |
962 | 962 | ubyte[] t; |
963 | 963 | if (!l) |
|
1122 | 1122 | // packet should include header, and possibly data |
1123 | 1123 | assert(packet.length >= 4); |
1124 | 1124 | } |
1125 | | -body |
| 1125 | +do |
1126 | 1126 | { |
1127 | 1127 | auto dataLength = packet.length - 4; // don't include header in calculated size |
1128 | 1128 | assert(dataLength <= uint.max); |
|
1137 | 1137 | // Length is always a 24-bit int |
1138 | 1138 | assert(dataLength <= 0xffff_ffff_ffff); |
1139 | 1139 | } |
1140 | | -body |
| 1140 | +do |
1141 | 1141 | { |
1142 | 1142 | dataLength.packInto!(uint, true)(packet); |
1143 | 1143 | packet[3] = packetNumber; |
|
0 commit comments