本文整理汇总了C#中AtomCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# AtomCollection.Add方法的具体用法?C# AtomCollection.Add怎么用?C# AtomCollection.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AtomCollection
的用法示例。
在下文中一共展示了AtomCollection.Add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadAtom
static public Atom ReadAtom(this Stream stream)
{
var header = stream.ReadBytes(8);
var name = new ID4(header, 0);
if (!BitConverter.IsLittleEndian) Array.Reverse(header, 4, 4);
uint len = BitConverter.ToUInt32(header, 4);
if ((len & 0x80000000U)!=0) {
if ((len&0x7FFFFFFF)>1024) {
throw new InvalidDataException("Atom has too many children");
}
var children = new AtomCollection();
for (var i=0; i<(len&0x7FFFFFFF); i++) {
children.Add(stream.ReadAtom());
}
return new Atom(name, children);
}
else {
if (len>1024*1024) {
throw new InvalidDataException("Atom length too long");
}
var value = stream.ReadBytes((int)len);
return new Atom(name, value);
}
}
示例2: CreateBroadcastPacket
/// <summary>
/// 指定したパケットを含むブロードキャストパケットを作成します
/// </summary>
/// <param name="group">配送先グループ</param>
/// <param name="packet">配送するパケット</param>
/// <returns>作成したPCP_BCSTパケット</returns>
private Atom CreateBroadcastPacket(BroadcastGroup group, Atom packet)
{
var bcst = new AtomCollection();
bcst.SetBcstFrom(PeerCast.SessionID);
bcst.SetBcstGroup(group);
bcst.SetBcstHops(0);
bcst.SetBcstTTL(11);
PCPVersion.SetBcstVersion(bcst);
bcst.SetBcstChannelID(Channel.ChannelID);
bcst.Add(packet);
return new Atom(Atom.PCP_BCST, bcst);
}
示例3: ReadAtomAsync
static public async Task<Atom> ReadAtomAsync(this Stream stream, CancellationToken cancel_token)
{
var header = await stream.ReadBytesAsync(8, cancel_token);
var name = new ID4(header, 0);
if (!BitConverter.IsLittleEndian) Array.Reverse(header, 4, 4);
uint len = BitConverter.ToUInt32(header, 4);
if ((len & 0x80000000U)!=0) {
if ((len&0x7FFFFFFF)>1024) {
throw new InvalidDataException("Atom has too many children");
}
var children = new AtomCollection();
for (var i=0; i<(len&0x7FFFFFFF); i++) {
children.Add(await stream.ReadAtomAsync(cancel_token));
}
return new Atom(name, children);
}
else {
if (len>1024*1024) {
throw new InvalidDataException("Atom length too long");
}
var value = await stream.ReadBytesAsync((int)len, cancel_token);
return new Atom(name, value);
}
}