Exemplo n.º 1
0
        /**
         * Writes bytes to the underlying buffer, with the length of the bytes prepended.
         * @param	bytes
         */
        public void writeBytes(byte[] bytes)
        {
            ushort len = System.UInt16.Parse(bytes.Length.ToString());

            byte[] lenbytes = System.BitConverter.GetBytes(BytesHelper.ReverseBytes(len));

            buffer.AddRange(lenbytes);
            buffer.AddRange(bytes);
        }
Exemplo n.º 2
0
        public object transform(object input)
        {
            byte[]      message = input as byte[];
            List <byte> buffer  = new List <byte>();
            ushort      len     = System.UInt16.Parse(message.Length.ToString());

            byte[] lenbytes = System.BitConverter.GetBytes(BytesHelper.ReverseBytes(len));
            buffer.AddRange(lenbytes);
            buffer.AddRange(message);
            return(buffer.ToArray());
        }
 public object transform(object input)
 {
     byte[] bytes = input as byte[];
     if (bytes.Length >= lengthFieldLength)
     {
         byte[] headbytes = new byte[2];
         headbytes[0] = bytes[0];
         headbytes[1] = bytes[1];
         length       = BitConverter.ToUInt16(headbytes, 0);
         length       = BytesHelper.ReverseBytes(length);
         if (bytes.Length >= length + lengthFieldLength)
         {
             byte[] result = bytes.Skip(lengthFieldLength).Take(length).ToArray();
             return(result);
         }
         return(null);
     }
     return(null);
 }