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); } } }