public void WriteToBuffer(byte[] buffer, int startIndex) { BufferConverter.WriteBytes(NtpTimestamp, buffer, startIndex, true); BufferConverter.WriteBytes(RtpTimestamp, buffer, startIndex + 8, true); BufferConverter.WriteBytes(PacketCount, buffer, startIndex + 12, true); BufferConverter.WriteBytes(OctetCount, buffer, startIndex + 16, true); return; }
public void WriteToBuffer(byte[] buffer, int startIndex) { BufferConverter.WriteBytes(Src, buffer, startIndex, true); int offset = startIndex + 4; foreach (var item in ItemsToWrite) { if (item == SdesItemType.PrivateExtensions) { foreach (var pvtExt in PrivateExtensionsToWrite) { byte[] prefix = utf8Encoder.GetBytes(pvtExt); byte[] value = PrivateExtensions[pvtExt]; buffer[offset] = (byte)SdesItemType.PrivateExtensions; buffer[offset + 1] = (byte)(value.Length + prefix.Length + 1); buffer[offset + 2] = (byte)(prefix.Length); Buffer.BlockCopy(prefix, 0, buffer, offset + 3, prefix.Length); Buffer.BlockCopy(value, 0, buffer, offset + 3 + prefix.Length, value.Length); offset += 3 + prefix.Length + value.Length; } } else { buffer[offset] = (byte)item; byte[] value = null; switch (item) { case SdesItemType.CName: value = cName; break; case SdesItemType.Name: value = name; break; case SdesItemType.Email: value = email; break; case SdesItemType.Phone: value = phone; break; case SdesItemType.Loc: value = loc; break; case SdesItemType.Tool: value = tool; break; case SdesItemType.Note: value = note; break; } if (value == null) { throw new Exception("SDES data has no value for " + item.ToString() + ". Provide a value or remove it from " + nameof(ItemsToWrite) + "."); } Buffer.BlockCopy(value, 0, buffer, offset + 2, value.Length); } } }
public void ReadFromBuffer(byte[] buffer, int startIndex) { Src = BufferConverter.ToUInt32(buffer, startIndex, true); int offset = startIndex + 4; while (offset < buffer.Length) { byte[] value = new byte[buffer[offset + 1]]; Buffer.BlockCopy(buffer, offset + 2, value, 0, value.Length); switch ((SdesItemType)buffer[offset]) { case SdesItemType.CName: cName = value; break; case SdesItemType.Name: name = value; break; case SdesItemType.Email: email = value; break; case SdesItemType.Phone: phone = value; break; case SdesItemType.Loc: loc = value; break; case SdesItemType.Tool: tool = value; break; case SdesItemType.Note: note = value; break; case SdesItemType.PrivateExtensions: byte prefixLength = value[0]; string extPrefix = utf8Encoder.GetString(value, 1, prefixLength); byte[] extValue = new byte[value.Length - prefixLength - 1]; Buffer.BlockCopy(value, 1 + prefixLength, extValue, 0, extValue.Length); PrivateExtensions[extPrefix] = extValue; break; default: System.Diagnostics.Debug.WriteLine("Unknown SDES Type " + buffer[offset] + " received."); return; } offset += 2 + value.Length; } }