public Serialize ( byte buffer, int offset ) : int | ||
buffer | byte | The buffer to serialize to |
offset | int | The offset to begin serializing |
Результат | int |
/// <summary> /// Sends a bvlc message /// </summary> /// <param name="mac">The BACnet mac address of the destination device</param> /// <param name="message"></param> private void _sendMessage(Mac mac, IBvlcMessage message) { // TODO: constant for buffer size, or // lease buffers from the UDPAsyncServer instance IPEndPoint ep = IPUtils.MacToIPEndPoint(mac); byte[] buffer = new byte[1500]; int offset = 0; BvlcHeader header = null; header = new BvlcHeader(); header.Function = message.Function; header.Length = 0; offset = header.Serialize(buffer, offset); offset = message.Serialize(buffer, offset); // patch the length in now that it is known buffer[2] = (byte)(offset << 8); buffer[3] = (byte)(offset); _server.Send(ep, buffer, offset); }
/// <summary> /// Sends a netgram out of this port /// </summary> /// <param name="netgram">The netgram to send</param> public void SendNetgram(OutboundNetgram netgram) { IPEndPoint ep = null; byte[] buffer = new byte[1500]; int offset = 0; BvlcHeader header = new BvlcHeader(); IBvlcMessage message = null; if (netgram.Destination.IsBroadcast()) { ep = IPUtils.MacToIPEndPoint(_bbmdMac); header.Function = FunctionCode.OriginalUnicastNpdu; //header.Function = FunctionCode.OriginalBroadcastNpdu; header.Length = 0; message = new OriginalBroadcastNpduMessage(); } else { ep = IPUtils.MacToIPEndPoint(netgram.Destination); header.Function = FunctionCode.OriginalUnicastNpdu; header.Length = 0; message = new OriginalUnicastNpduMessage(); } offset = header.Serialize(buffer, offset); offset = message.Serialize(buffer, offset); offset = netgram.Content.Serialize(buffer, offset); // patch the length buffer[2] = (byte)(offset << 8); buffer[3] = (byte)(offset); lock(this._lock) { if (_server != null) { _server.Send(ep, buffer, offset); } } }