/// <summary> /// initialize the restriction of target info /// </summary> /// <param name="targetInfo">the target info collection</param> private void InitializeRestriction( ICollection <AV_PAIR> targetInfo ) { // update the MsAvRestrictions of targetInfo // MachineID (32 bytes): A 256-bit random number created at computer // startup to identify the calling machine. Restriction_Encoding restriction = new Restriction_Encoding(); // defines the length, in bytes, of AV_PAIR Value. restriction.Size = 0x30; restriction.MachineID = new byte[NlmpUtility.MACHINE_ID_SIZE]; byte[] restrictionBytes = NlmpUtility.StructGetBytes(restriction); if (NlmpUtility.AvPairContains(targetInfo, AV_PAIR_IDs.MsAvRestrictions)) { NlmpUtility.UpdateAvPair( targetInfo, AV_PAIR_IDs.MsAvRestrictions, (ushort)restrictionBytes.Length, restrictionBytes); } else { NlmpUtility.AddAVPair( targetInfo, AV_PAIR_IDs.MsAvRestrictions, (ushort)restrictionBytes.Length, restrictionBytes); } }
/// <summary> /// marshal the packet struct to bytes array. /// </summary> /// <returns>get the bytes of packet</returns> public override byte[] ToBytes() { byte[] bytes = new byte[Length]; Array.Copy(NlmpUtility.StructGetBytes(this.header), bytes, HeaderLength); Array.Copy(WriteStructToBytes(), 0, bytes, HeaderLength, PayLoadLength); return(bytes); }
/// <summary> /// write the payload to bytes. For all sub class to marshal itself. /// </summary> /// <returns>the bytes of struct</returns> protected override byte[] WriteStructToBytes() { byte[] bytes = NlmpUtility.StructGetBytes(payload); if (PayLoadLength != bytes.Length) { throw new InvalidOperationException("the payload length is not equal to the marshal size!"); } return(bytes); }