Exemplo n.º 1
0
        public static Message read(MixedStream st)
        {
            byte[] len1 = new byte[8];
            st.Read(len1);
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(len1);
            }
            long lenHeader = BitConverter.ToInt64(len1, 0);

            byte[] len2 = new byte[8];
            st.Read(len2);
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(len2);
            }
            long lenAttachments = BitConverter.ToInt64(len2, 0);

            byte[] msg = new byte[lenHeader];
            st.Read(msg);
            string header = Encoding.UTF8.GetString(msg, 0, (int)lenHeader);

            byte[] len3 = new byte[8];
            st.Read(len3);
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(len3);
            }
            long numAttachments = BitConverter.ToInt64(len3, 0);

            Attachment[] rawAttachments = new Attachment[numAttachments];
            if (numAttachments > 0)
            {
                for (int i = 0; i < numAttachments; i++)
                {
                    byte[] attLen = new byte[8];
                    st.Read(attLen);
                    if (BitConverter.IsLittleEndian)
                    {
                        Array.Reverse(attLen);
                    }
                    long lenAtt = BitConverter.ToInt64(attLen, 0);

                    rawAttachments[i] = Attachment.read(st, lenAtt, i + 1);
                }
            }
            return(new Message(header, rawAttachments));
        }
Exemplo n.º 2
0
 public static Attachment read(MixedStream st, long length, int position)
 {
     if (length < AttachmentMemoryLimit)
     {
         byte[] data = new byte[length];
         st.Read(data);
         return(new ArrayAttachment(data, position));
     }
     else
     {
         // TODO: read from stream into FileAttachment
     }
     return(null);
 }