internal Packet(RequestHeader header, ReplyHeader replyHeader, IRecord request, IRecord response, byte[] data, ZooKeeper.WatchRegistration watchRegistration, string serverPath, string clientPath) { this.header = header; this.replyHeader = replyHeader; this.request = request; this.response = response; this.serverPath = serverPath; this.clientPath = clientPath; if (data != null) { this.data = data; } else { try { MemoryStream ms = new MemoryStream(); using (EndianBinaryWriter writer = new EndianBinaryWriter(EndianBitConverter.Big, ms, Encoding.UTF8)) { BinaryOutputArchive boa = BinaryOutputArchive.getArchive(writer); boa.WriteInt(-1, "len"); // We'll fill this in later if (header != null) { header.Serialize(boa, "header"); } if (request != null) { request.Serialize(boa, "request"); } ms.Position = 0; int len = Convert.ToInt32(ms.Length); // now we have the real length writer.Write(len - 4); // update the length info this.data = ms.ToArray(); } } #if !NET_CORE catch (IOException e) { LOG.Warn("Ignoring unexpected exception", e); } #endif #if NET_CORE catch (Exception e) { } #endif } this.watchRegistration = watchRegistration; }