-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUcmSerializer.cs
More file actions
70 lines (58 loc) · 1.86 KB
/
UcmSerializer.cs
File metadata and controls
70 lines (58 loc) · 1.86 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// Copyright (c) 2018, Intel Corporation. All rights reserved.
//
// Author: Cezary Rojewski <cezary.rojewski@intel.com>
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
//
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace NUcmSerializer
{
public class UcmSerializer
{
public UcmSerializer()
{
// TODO: check semantics of type to be serialized/ deserialized
}
public void Serialize(Stream stream, IEnumerable<Section> sections, Encoding encoding)
{
if (stream == null)
throw new ArgumentNullException(nameof(stream));
if (sections == null)
throw new ArgumentNullException("sections");
var writer = new UcmWriter(stream, encoding);
foreach (var section in sections)
{
if (section == null)
throw new ArgumentNullException("section");
writer.WriteToken(section, null);
}
writer.Flush();
writer.Dispose();
}
public void Serialize(Stream stream, IEnumerable<Section> topology)
{
Serialize(stream, topology, null);
}
public IEnumerable<Section> Deserialize(Stream stream, Encoding encoding)
{
if (stream == null)
throw new ArgumentNullException(nameof(stream));
List<Section> result = new List<Section>();
Section section;
using (var reader = new UcmReader(stream, encoding))
{
while ((section = reader.ReadToken()) != null)
result.Add(section);
}
return result;
}
public IEnumerable<Section> Deserialize(Stream stream)
{
return Deserialize(stream, null);
}
}
}