Skip to content

Commit ed0ce30

Browse files
committed
[All] Add README.md
1 parent fa11039 commit ed0ce30

File tree

6 files changed

+64
-109
lines changed

6 files changed

+64
-109
lines changed

Lagrange.Core.sln

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{798B7680-2
2020
EndProject
2121
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lagrange.Proto.Runner", "Lagrange.Proto.Runner\Lagrange.Proto.Runner.csproj", "{D8B893D8-44B1-47E8-8513-9E3E1F9FD391}"
2222
EndProject
23+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3C682B4B-3C8D-4D4A-AF0D-8E188D421605}"
24+
ProjectSection(SolutionItems) = preProject
25+
README.md = README.md
26+
Proto.md = Proto.md
27+
OneBot.md = OneBot.md
28+
EndProjectSection
29+
EndProject
2330
Global
2431
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2532
Debug|Any CPU = Debug|Any CPU

Lagrange.Proto.Runner/Program.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Runtime.CompilerServices;
1+
using System.Buffers;
22
using Lagrange.Proto.Primitives;
33
using Lagrange.Proto.Serialization;
44

@@ -8,7 +8,7 @@ internal static class Program
88
{
99
private static void Main(string[] args)
1010
{
11-
var bufferWriter = new SegmentBufferWriter();
11+
var bufferWriter = new ArrayBufferWriter<byte>();
1212

1313
var writer = new ProtoWriter(bufferWriter);
1414
var test = new Test
@@ -35,7 +35,8 @@ private static void Main(string[] args)
3535
Test.SerializeHandler(test, writer);
3636
writer.Flush();
3737

38-
Console.WriteLine(Convert.ToHexString(bufferWriter.CreateReadOnlyMemory().Span));
38+
Console.WriteLine(Convert.ToHexString(bufferWriter.WrittenSpan));
39+
bufferWriter.Clear();
3940
}
4041
}
4142

Lagrange.Proto.Runner/SegmentBufferWriter.cs

-106
This file was deleted.

OneBot.md

Whitespace-only changes.

Proto.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
## Lagrange.Proto
2+
3+
### The Blazing-fast Code-first C# Google Protocol Buffer Serializer
4+
5+
### Overview
6+
7+
+ Low memory allocation
8+
+ AOT Friendly using Roslyn's Source Generators
9+
+ Extreme-fast Serialization
10+
+ x86-64 SIMD Support for the VarInt Encoding
11+
+ Supported C# Type
12+
+ string, byte[], ReadOnlyMemory<byte> (Length-Delimited)
13+
+ bool, sbyte, byte, short, ushort, int, uint, long, ulong (VarInt)
14+
+ float, double (Fixed32, Fixed64)
15+
+ ProtoPackable (nested object for Length-Delimited)
16+
+ List\<T>, T[], ReadOnlyCollection\<T> (repeated field)
17+
+ IDictionary\<TKey, TValue> (map field)
18+
+ Nullable\<T> (optional field)
19+
+ Enum with valid underlying type (VarInt)
20+
21+
### Usage
22+
```csharp
23+
using System;
24+
using System.Collections.Generic;
25+
using System.IO;
26+
using System.Linq;
27+
28+
[ProtoPackable]
29+
public class Person
30+
{
31+
[ProtoMember(1)] public string Name { get; set; }
32+
33+
[ProtoMember(2)] public int Age { get; set; }
34+
35+
[ProtoMember(3)] public List<string> Hobbies { get; set; }
36+
}
37+
```
38+
39+
After defining the class, you can serialize and deserialize it using the `ProtoSerializer` class.
40+
41+
```csharp
42+
var result = ProtoSerializer.Serialize(new Person
43+
{
44+
Name = "John Doe",
45+
Age = 30,
46+
Hobbies = new List<string> { "Reading", "Traveling" }
47+
});
48+
Console.WriteLine($"Serialized: {BitConverter.ToString(resutl)}");
49+
var person = ProtoSerializer.Deserialize<Person>(result.AsSpan());
50+
Console.WriteLine($"Name: {person.Name}, Age: {person.Age}");
51+
Console.WriteLine($"Hobbies: {string.Join(", ", person.Hobbies)}");
52+
```
53+

README.md

Whitespace-only changes.

0 commit comments

Comments
 (0)