직렬화, 바이트 순서

main
syneffort 2 years ago
parent e983d0223d
commit 6000d5a4e7
  1. 10
      Socket/ByteOrder/ByteOrder.csproj
  2. 30
      Socket/ByteOrder/Program.cs
  3. 27
      Socket/Serialize/Program.cs
  4. 10
      Socket/Serialize/Serialize.csproj
  5. 12
      Socket/Socket.sln

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -0,0 +1,30 @@
using System.Net;
namespace ByteOrder;
internal class Program
{
static void Main(string[] args)
{
/*
* :
* /AMD : -
* ARM : -
*/
byte[] buffer = BitConverter.GetBytes(12345678);
Console.WriteLine(BitConverter.ToString(buffer));
// ★★★ 네트워크 레벨에서는 반드시 빅엔디언 쓰기로 약속함
// 호스트 바이트 순서에서 네트워크 바이트 순서로 변경
int num2 = IPAddress.HostToNetworkOrder(12345678);
byte[] buffer2 = BitConverter.GetBytes(num2);
Console.WriteLine(BitConverter.ToString(buffer2));
// 네트워크 바이트 순서에서 호스트 바이트 순서로 변경
int num3 = BitConverter.ToInt32(buffer2);
int num4 = IPAddress.NetworkToHostOrder(num3);
Console.WriteLine(num4);
}
}

@ -0,0 +1,27 @@
using System.Text;
namespace Serialize;
internal class Program
{
static void Main(string[] args)
{
//int num = 1234;
//byte[] buffer = BitConverter.GetBytes(num);
//Console.WriteLine($"int byte length: {buffer.Length}"); // 8bit * 4 = 4byte
//int num2 = BitConverter.ToInt32(buffer, 0);
//Console.WriteLine($"deserialized: {num2}");
//long num = 1234;
//byte[] buffer = BitConverter.GetBytes(num);
//Console.WriteLine($"long byte length: {buffer.Length}"); // 8bit * 8 = 8byte
//long num2 = BitConverter.ToInt32(buffer, 0);
//Console.WriteLine($"deserialized: {num2}");
string str = "Hello world";
byte[] buffer = Encoding.UTF8.GetBytes(str);
Console.WriteLine($"str byte length: {buffer.Length}"); // 8bit * 8 = 8byte
string str2 = Encoding.UTF8.GetString(buffer);
Console.WriteLine($"deserialized: {str2}");
}
}

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -7,6 +7,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{5EEB261C-98C2-4467-9CC3-2129F0031114}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serialize", "Serialize\Serialize.csproj", "{E2C0CA13-3138-4CB3-9B41-2C97BA520309}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ByteOrder", "ByteOrder\ByteOrder.csproj", "{34446D97-4EA2-4FEA-8366-B730469A7A87}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -21,6 +25,14 @@ Global
{5EEB261C-98C2-4467-9CC3-2129F0031114}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5EEB261C-98C2-4467-9CC3-2129F0031114}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5EEB261C-98C2-4467-9CC3-2129F0031114}.Release|Any CPU.Build.0 = Release|Any CPU
{E2C0CA13-3138-4CB3-9B41-2C97BA520309}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E2C0CA13-3138-4CB3-9B41-2C97BA520309}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2C0CA13-3138-4CB3-9B41-2C97BA520309}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2C0CA13-3138-4CB3-9B41-2C97BA520309}.Release|Any CPU.Build.0 = Release|Any CPU
{34446D97-4EA2-4FEA-8366-B730469A7A87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{34446D97-4EA2-4FEA-8366-B730469A7A87}.Debug|Any CPU.Build.0 = Debug|Any CPU
{34446D97-4EA2-4FEA-8366-B730469A7A87}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34446D97-4EA2-4FEA-8366-B730469A7A87}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Loading…
Cancel
Save