public void CompressData(string p_pathTxt, string p_pathBin, out int p_totalBits) { var textWriter = new StreamWriter(p_pathTxt, false); textWriter.WriteLine(BinaryCode); textWriter.Close(); var binary = new BinaryOutputStream(p_pathBin); binary.Write(BinaryCode, out p_totalBits); binary.Close(); }
public static byte[] Encode(object data) { BinaryOutputStream stream = new BinaryOutputStream(); switch (data) { case LowLevelConnectMessage lowLevelConnectMessage: // no length prefix stream.WriteByte(42); stream.WriteByte(1); break; case APlayStringMessage aPlayStringMessage: stream.WriteByte(APlayCodec.MSGTYPE_PAYLOAD_BINARY_JSON); BinaryOutputStream content = new BinaryOutputStream(); content.WriteJsonEncoded(aPlayStringMessage.GetDataAsDecodedJson()); stream.WriteBytes(content.GetData()); break; case LowLevelIntroductionMessage lowLevelIntroductionMessage: // no length prefix stream.WriteByte(APlayCodec.MSGTYPE_LOWLEVEL_INTRODUCTION); stream.WriteString(lowLevelIntroductionMessage.AddressString); break; case LowLevelPingMessage lowLevelPingMessage: stream.WriteByte(APlayCodec.MSGTYPE_LOWLEVEL_PING); stream.WriteInt(12); // 8 + 4 stream.WriteLong(lowLevelPingMessage.PingTime); stream.WriteInt(lowLevelPingMessage.LastRTT); break; case LowLevelPongMessage lowLevelPongMessage: stream.WriteByte(APlayCodec.MSGTYPE_LOWLEVEL_PONG); stream.WriteInt(8); stream.WriteLong(lowLevelPongMessage.PingTime); break; } return(stream.GetData()); }
public void CompressData(string p_pathTxt, string p_pathBin, out int p_totalBits) { string binaryCoded = ""; for (int i = 0; i < m_charNum; i++) { TreeNode findCoded = m_coded.Find(f => f.Letter == m_code[i]); binaryCoded = binaryCoded + findCoded.Code; } var textWriter = new StreamWriter(p_pathTxt, false); textWriter.WriteLine(binaryCoded); textWriter.Close(); var binary = new BinaryOutputStream(p_pathBin); binary.Write(binaryCoded, out p_totalBits); binary.Close(); }