Ejemplo n.º 1
0
        public void resultingSizeZeroLValue()
        {
            ByteBuffer result = new ByteBuffer(new byte[1024]);

            STUNTypeLengthValue.Value(0, new ByteBuffer(ByteBuffer.ZeroLengthBuffer), ref result);

            Assert.AreEqual(4, result.Position);
        }
Ejemplo n.º 2
0
        public void lengthPosition()
        {
            ByteBuffer result = new ByteBuffer(new byte[1024]);

            STUNTypeLengthValue.Value(0, new ByteBuffer(new byte[257]), ref result);

            Assert.AreEqual(0, result[0]);
            Assert.AreEqual(0, result[1]);
            Assert.AreEqual(1, result[2]);
            Assert.AreEqual(1, result[3]);
        }
Ejemplo n.º 3
0
        public void resultingSizeThreeLValue()
        {
            ByteBuffer result = new ByteBuffer(new byte[1024]);

            STUNTypeLengthValue.Value(0, new ByteBuffer(new byte[] { 0xff, 0xff, 0xff }), ref result);

            Assert.AreEqual(8, result.Position);
            Assert.AreEqual(0xff, result[4]);
            Assert.AreEqual(0xff, result[5]);
            Assert.AreEqual(0xff, result[6]);
            Assert.AreEqual(0, result[7]);
        }
Ejemplo n.º 4
0
 public void FillAttributesArray(List <STUNAttr> attributes)
 {
     buffer.Rewind();
     buffer.SkipBytes(STUNMessageBuilder.HEADER_LENGTH);
     while (buffer.Position < STUNMessageBuilder.HEADER_LENGTH + length)
     {
         STUNAttribute type;
         ushort        length;
         STUNTypeLengthValue.ReadTypeLength(ref buffer, out type, out length);
         STUNAttr attr = new STUNAttr(type, new ByteBuffer(buffer.data, buffer.absPosition, length), new ByteBuffer(buffer.data, buffer.absOffset, buffer.Length));
         buffer.Position += length;
         STUNTypeLengthValue.AddPadding(ref buffer);
         attributes.Add(attr);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Add a value to the STUN message.
 /// </summary>
 /// <param name="type">The message type</param>
 /// <param name="value">The message value</param>
 /// <returns>This builder, never null</returns>
 public void WriteAttribute(int type, byte[] value)
 {
     STUNTypeLengthValue.Value(type, value, ref buffer);
     UpdateHeaderAttributesLength(ref buffer, buffer.Position);
 }