| 322 | | if (s.Length > 0) |
| 323 | | { |
| 324 | | try |
| 325 | | { |
| 326 | | int i = int.Parse(s); |
| 327 | | // Console.WriteLine(" i:" + i); |
| 328 | | oM.Values.Add(i); |
| 329 | | } |
| 330 | | catch |
| | 340 | if ( s.StartsWith( "<" ) ) |
| | 341 | { |
| | 342 | ArrayList byteList = new ArrayList(); |
| | 343 | if (s.Length > 1) |
| | 344 | ExtractBytesFromString(byteList, s.Substring(1)); |
| | 345 | while (sE.MoveNext()) |
| | 346 | { |
| | 347 | string a = (string)sE.Current; |
| | 348 | |
| | 349 | ExtractBytesFromString(byteList, a); |
| | 350 | |
| | 351 | if ( a.EndsWith( ">" ) ) |
| | 352 | break; |
| | 353 | } |
| | 354 | |
| | 355 | byte[] byteArray = new byte[ byteList.Count ]; |
| | 356 | int index = 0; |
| | 357 | foreach ( byte b in byteList ) |
| | 358 | byteArray[ index++ ] = (byte)b; |
| | 359 | |
| | 360 | oM.Values.Add( byteArray ); |
| | 361 | } |
| | 362 | else |
| | 363 | { |
| | 364 | if (s.Length > 0) |
| 469 | | tag.Append("?"); |
| | 511 | if ( o is byte[] ) |
| | 512 | { |
| | 513 | tag.Append("b"); |
| | 514 | byte[] byteArray = (byte[])o; |
| | 515 | int len = byteArray.Length; |
| | 516 | packet[index++] = (byte)((len >> 24) & 0xFF); |
| | 517 | packet[index++] = (byte)((len >> 16) & 0xFF); |
| | 518 | packet[index++] = (byte)((len >> 8) & 0xFF); |
| | 519 | packet[index++] = (byte)((len) & 0xFF); |
| | 520 | Array.Copy(byteArray, 0, packet, index, len); |
| | 521 | index += len; |
| | 522 | int pad = len % 4; |
| | 523 | if (pad != 0) |
| | 524 | { |
| | 525 | pad = 4 - pad; |
| | 526 | while (pad-- > 0) |
| | 527 | packet[index++] = 0; |
| | 528 | } |
| | 529 | } |
| | 530 | else |
| | 531 | tag.Append("?"); |
| | 651 | } |
| | 652 | |
| | 653 | /// <summary> |
| | 654 | /// Extracts a blob from a packet. Used internally. |
| | 655 | /// </summary> |
| | 656 | /// <param name="packet">The packet of bytes to be parsed.</param> |
| | 657 | /// <param name="start">The index of where to start looking in the packet.</param> |
| | 658 | /// <param name="length">The length of the packet.</param> |
| | 659 | /// <returns>The string</returns> |
| | 660 | private static byte[] ExtractBlob(byte[] packet, int start, int length) |
| | 661 | { |
| | 662 | int index = start; |
| | 663 | int blobSize = ( packet[index++] << 24 ) + ( packet[index++] << 16 ) + ( packet[index++] << 8 ) + packet[index++]; |
| | 664 | byte[] b = new byte[ blobSize ]; |
| | 665 | int blobIndex = 0; |
| | 666 | while (blobSize-- > 0 && index < length) |
| | 667 | { |
| | 668 | b[ blobIndex ] = packet[ index ]; |
| | 669 | blobIndex++; |
| | 670 | index++; |
| | 671 | } |
| | 672 | return b; |
| | 716 | |
| | 717 | private static void ExtractBytesFromString(ArrayList byteList, string s) |
| | 718 | { |
| | 719 | int nibbleCount = 0; |
| | 720 | int v = 0; |
| | 721 | // look at each character |
| | 722 | foreach (char c in s) |
| | 723 | { |
| | 724 | // if the character is 0-9, a-f or A-F add it to v left shifting whatever was in there by a nibble |
| | 725 | if (c >= '0' && c <= '9') |
| | 726 | { |
| | 727 | v = ( v << 4 ) + (int)(c - '0'); |
| | 728 | nibbleCount++; |
| | 729 | } |
| | 730 | else |
| | 731 | { |
| | 732 | if (c >= 'a' && c <= 'f') |
| | 733 | { |
| | 734 | v = (v << 4) + (int)(c - 'a') + 10; |
| | 735 | nibbleCount++; |
| | 736 | } |
| | 737 | else |
| | 738 | { |
| | 739 | if (c >= 'A' && c <= 'F') |
| | 740 | { |
| | 741 | v = (v << 4) + (int)(c - 'A') + 10; |
| | 742 | nibbleCount++; |
| | 743 | } |
| | 744 | else |
| | 745 | { |
| | 746 | // if there is a digit in v, and we just got a non-digit then we're done |
| | 747 | if ( nibbleCount > 0 ) |
| | 748 | nibbleCount++; |
| | 749 | } |
| | 750 | } |
| | 751 | } |
| | 752 | if (nibbleCount == 2) |
| | 753 | { |
| | 754 | byteList.Add((byte)v); |
| | 755 | v = 0; |
| | 756 | nibbleCount = 0; |
| | 757 | } |
| | 758 | } |
| | 759 | // if at the end of it all, we were left with a hanging nibble, save it |
| | 760 | if (nibbleCount > 0) |
| | 761 | byteList.Add((byte)v); |
| | 762 | } |