■ AvroConvert 클래스의 Serialize/Deserialize 정적 메소드를 사용해 데이터를 직렬화/역직렬화하는 방법을 보여준다.
▶ Employee.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
namespace TestProject; /// <summary> /// 직원 /// </summary> public class Employee { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region ID - ID /// <summary> /// ID /// </summary> public int ID { get; set; } #endregion #region 성명 - Name /// <summary> /// 성명 /// </summary> public string Name { get; set; } #endregion } |
▶ Program.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
using SolTechnology.Avro; namespace TestProject; /// <summary> /// 프로그램 /// </summary> class Program { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 프로그램 시작하기 - Main() /// <summary> /// 프로그램 시작하기 /// </summary> private static void Main() { List<Employee> sourceList = new List<Employee>(); for(int i = 0; i < 100; i++) { sourceList.Add(new Employee { ID= i + 1, Name = $"직원{i + 1:d3}" }); } byte[] sourceByteArray = AvroConvert.Serialize(sourceList); Console.WriteLine("직렬화 데이터"); Console.WriteLine("--------------------------------------------------"); Console.WriteLine(Convert.ToBase64String(sourceByteArray)); Console.WriteLine("--------------------------------------------------"); Console.WriteLine(); List<Employee> targetList = AvroConvert.Deserialize<List<Employee>>(sourceByteArray); Console.WriteLine("역직렬화 데이터"); Console.WriteLine("--------------------------------------------------"); for(int i = 0; i < 100; i++) { Employee employee = targetList[i]; Console.WriteLine($"{employee.ID}, {employee.Name}"); } Console.WriteLine("--------------------------------------------------"); } #endregion } |