Skip to content

Commit

Permalink
feat(typegen): implement Requests.cs and enable C Style Enums for uni…
Browse files Browse the repository at this point in the history
…t enum variants

Implements a class otherwise, always for enums. Which isn't ideal, however
passing the option to the user might be wiser.
  • Loading branch information
huwaireb committed Jul 6, 2024
1 parent 2ee30b8 commit 6e4cf4d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
20 changes: 8 additions & 12 deletions crux_core/src/typegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,13 +552,13 @@ The 2 common cases are:
let path = path.as_ref().join(package_name);

fs::create_dir_all(&path)?;

let installer = csharp::Installer::new(path.clone());

installer
.install_serde_runtime()
.map_err(|e| TypeGenError::Generation(e.to_string()))?;

installer
.install_bincode_runtime()
.map_err(|e| TypeGenError::Generation(e.to_string()))?;
Expand All @@ -568,19 +568,15 @@ The 2 common cases are:
_ => panic!("registry creation failed"),
};


let config = serde_generate::CodeGeneratorConfig::new(
package_name.to_string())
.with_encodings(vec![Encoding::Bincode]);

let config = serde_generate::CodeGeneratorConfig::new(package_name.to_string())
.with_encodings(vec![Encoding::Bincode])
.with_c_style_enums(true);

installer
.install_module(&config, registry)
.map_err(|e| TypeGenError::Generation(e.to_string()))?;

let mut output = File::create(
path.join(package_name)
.join("Requests.cs")
)?;
let mut output = File::create(path.join(package_name).join("Requests.cs"))?;

let requests_path = self.extensions_path("csharp/Requests.cs");
let requests_data = fs::read_to_string(requests_path)?;
Expand Down
29 changes: 28 additions & 1 deletion crux_core/typegen_extensions/csharp/Requests.cs
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
// hi
using System;
using System.Collections.Generic;

namespace SharedTypes
{
public static class Requests
{
public static List<Request> BincodeDeserialize(ArraySegment<byte> input)
{
Serde.IDeserializer deserializer = new Bincode.BincodeDeserializer(input);
deserializer.increase_container_depth();

var length = deserializer.deserialize_len();
var requests = new List<Request>();
for (var i = 0; i < length; ++i)
{
while (deserializer.get_buffer_offset() < input.Count)
{
var req = Request.Deserialize(deserializer);
requests.Add(req);
}
}

deserializer.decrease_container_depth();
return requests;
}
}
}

0 comments on commit 6e4cf4d

Please sign in to comment.