Skip to content

Commit 6b0c17b

Browse files
committed
update readme
1 parent 996d072 commit 6b0c17b

2 files changed

Lines changed: 31 additions & 11 deletions

File tree

README.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# Request Systems
1+
# Data Systems
22

3-
Implements `requests` with a system that imports data from various sources.
3+
Implements the `data` project with a system that loads data from various sources.
44

55
### Loading from an entity
66

77
```cs
8-
Datum source = new(world, "fileA");
8+
DataSource source = new(world, "fileA");
99
source.WriteUTF8("Some data here!");
1010

11-
Request request = new(world, "fileA");
11+
DataRequest request = new(world, "fileA");
1212

1313
simulator.Update();
1414

15-
using BinaryReader reader = new(request.GetBinaryData());
15+
using ByteReader reader = new(request.CreateByteReader());
1616
Span<char> dataBuffer = stackalloc char[32];
1717
uint textLength = reader.ReadUTF8Span(dataBuffer);
1818
string loadedData = dataBuffer.Slice(0, textLength).ToString();
@@ -22,11 +22,11 @@ Console.WriteLine($"Loaded data from an entity {loadedData}");
2222
### Loading from file on disk
2323

2424
```cs
25-
Request request = new(world, "C:/fileB.txt");
25+
DataRequest request = new(world, "C:/fileB.txt");
2626

2727
simulator.Update();
2828

29-
using BinaryReader reader = new(request.GetBinaryData());
29+
using ByteReader reader = new(request.CreateByteReader());
3030
Span<char> dataBuffer = stackalloc char[32];
3131
uint textLength = reader.ReadUTF8Span(dataBuffer);
3232
string loadedData = dataBuffer.Slice(0, textLength).ToString();
@@ -46,13 +46,33 @@ public readonly struct MyEmbeddedResources : IEmbeddedResourceBank
4646
}
4747

4848
EmbeddedResourceRegistry.Load<MyEmbeddedResources>();
49-
Request request = new(world, "Assets/test.txt");
49+
DataRequest request = new(world, "Assets/test.txt");
5050

5151
simulator.Update();
5252

53-
using BinaryReader reader = new(request.GetBinaryData());
53+
using ByteReader reader = new(request.CreateByteReader());
5454
Span<char> dataBuffer = stackalloc char[32];
5555
uint textLength = reader.ReadUTF8Span(dataBuffer);
5656
string loadedData = dataBuffer.Slice(0, textLength).ToString();
5757
Console.WriteLine($"Loaded data from an embedded resource {loadedData}");
58+
```
59+
60+
### Loading through a message
61+
62+
Data can be loaded by another system through the `LoadData` message:
63+
```cs
64+
LoadData message = new("Assets/test.txt");
65+
simulator.Broadcast(ref message);
66+
if (message.TryConsume(out ByteReader data))
67+
{
68+
Span<char> dataBuffer = stackalloc char[32];
69+
uint textLength = data.ReadUTF8Span(dataBuffer);
70+
string loadedData = dataBuffer.Slice(0, textLength).ToString();
71+
Console.WriteLine($"Loaded data through a message {loadedData}");
72+
data.Dispose();
73+
}
74+
else
75+
{
76+
Console.WriteLine("Failed to load data through a message");
77+
}
5878
```

source/Data.Systems.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net9.0</TargetFramework>
@@ -10,7 +10,7 @@
1010
<Company>simulation-tree</Company>
1111
<RepositoryUrl>https://github.com/simulation-tree/data-systems</RepositoryUrl>
1212
<PackageReadmeFile>README.md</PackageReadmeFile>
13-
<Description>Loads requests</Description>
13+
<Description>Handles loading data</Description>
1414
<GenerateDocumentationFile>True</GenerateDocumentationFile>
1515
<IsAotCompatible>True</IsAotCompatible>
1616
<IsTrimmable>True</IsTrimmable>

0 commit comments

Comments
 (0)