Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ GetPreambleLength()

static int System.Net.Http.HttpContent.GetPreambleLength ( ArraySegment< byte > buffer,
Encoding encoding )
inlinestaticprivateinherited

Definition at line 764 of file HttpContent.cs.

765 {
766 byte[] array = buffer.Array;
767 int offset = buffer.Offset;
768 int count = buffer.Count;
769 switch (encoding.CodePage)
770 {
771 case 65001:
772 if (count < 3 || array[offset] != 239 || array[offset + 1] != 187 || array[offset + 2] != 191)
773 {
774 return 0;
775 }
776 return 3;
777 case 12000:
778 if (count < 4 || array[offset] != byte.MaxValue || array[offset + 1] != 254 || array[offset + 2] != 0 || array[offset + 3] != 0)
779 {
780 return 0;
781 }
782 return 4;
783 case 1200:
784 if (count < 2 || array[offset] != byte.MaxValue || array[offset + 1] != 254)
785 {
786 return 0;
787 }
788 return 2;
789 case 1201:
790 if (count < 2 || array[offset] != 254 || array[offset + 1] != byte.MaxValue)
791 {
792 return 0;
793 }
794 return 2;
795 default:
796 {
797 byte[] preamble = encoding.GetPreamble();
798 if (!BufferHasPrefix(buffer, preamble))
799 {
800 return 0;
801 }
802 return preamble.Length;
803 }
804 }
805 }
static bool BufferHasPrefix(ArraySegment< byte > buffer, byte[] prefix)
virtual int CodePage
Definition Encoding.cs:515
virtual byte[] GetPreamble()
Definition Encoding.cs:689

References System.array, System.buffer, System.Net.Http.HttpContent.BufferHasPrefix(), System.Text.Encoding.CodePage, System.count, System.Text.Encoding.GetPreamble(), and System.offset.

Referenced by System.Net.Http.HttpContent.ReadBufferAsString().