1. C# / Говнокод #11960

    +134

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public static byte[] ConvertToMessage(Stream stream)
            {
                int length = (int) stream.Length;
                byte[] buffer = new byte[length + 4];
                buffer[0] = (byte) (length & 0xff);
                buffer[1] = (byte) ((length & 0xff00) >> 8);
                buffer[2] = (byte) ((length & 0xff0000) >> 16);
                buffer[3] = (byte) ((length & 0xff000000L) >> 24);
                stream.Read(buffer, 4, length);
                return buffer;
            }

    А товарищи знают толк в извращенствах

    Запостил: Yukiakze, 19 Октября 2012

    Комментарии (2) RSS

    • Разве в шарпе нет какого-нибудь аналога явовского ByteBuffer'а?
      Ответить
      • Раз уж там Stream
        http://msdn.microsoft.com/en-us/library/system.io.stream.beginread.aspx
        Ответить

    Добавить комментарий