GithubHelp home page GithubHelp logo

ulid's Introduction

Ulid

GitHub Actions Releases

Fast C# Implementation of ULID for .NET Core and Unity. Ulid is sortable, random id generator. This project aims performance by fastest binary serializer(MessagePack-CSharp) technology. It achives faster generate than Guid.NewGuid.

image

NuGet: Ulid or download .unitypackage from Ulid/Releases page.

Install-Package Ulid

Table of Contents

How to use

Similar api to Guid.

  • Ulid.NewUlid()
  • Ulid.Parse()
  • Ulid.TryParse()
  • new Ulid()
  • .ToString()
  • .ToByteArray()
  • .TryWriteBytes()
  • .TryWriteStringify()
  • .ToBase64()
  • .Time
  • .Random

Allow to convert Guid.

  • .ToGuid()
  • (Guid)ulid

Performance

Guid is standard corelib guid. Ulid is this library. NUlid is competitor RobThree/NUlid.

  • New
Method Mean Error Ratio Gen 0/1k Op Gen 1/1k Op Gen 2/1k Op Allocated Memory/Op
Guid_ 73.13 ns NA 1.00 - - - -
Ulid_ 65.41 ns NA 0.89 - - - -
NUlid_ 209.89 ns NA 2.87 0.0162 - - 104 B

Ulid.NewUlid() is faster than Guid.NewGuid() and zero allocation.

  • Parse
Method Mean Error Ratio Gen 0/1k Op Gen 1/1k Op Gen 2/1k Op Allocated Memory/Op
Guid_ 197.98 ns NA 1.00 - - - -
Ulid_ 28.67 ns NA 0.14 - - - -
NUlid_ 161.03 ns NA 0.81 0.0441 - - 280 B

from string(Base32) to ulid, Ulid.Parse(string) is fastest and zero allocation.

  • ToString
Method Mean Error Ratio Gen 0/1k Op Gen 1/1k Op Gen 2/1k Op Allocated Memory/Op
Guid_ 57.73 ns NA 1.00 0.0163 - - 104 B
Ulid_ 38.77 ns NA 0.67 0.0126 - - 80 B
NUlid_ 96.76 ns NA 1.68 0.0583 - - 368 B

to string representation(Base32), Ulid.ToString() is fastest and less allocation.

  • NewId().ToString()
Method Mean Error Ratio Gen 0/1k Op Gen 1/1k Op Gen 2/1k Op Allocated Memory/Op
Guid_ 205.7 ns NA 1.00 0.0162 - - 104 B
Ulid_ 110.2 ns NA 0.54 0.0125 - - 80 B
NUlid_ 301.7 ns NA 1.47 0.0744 - - 472 B

case of get the string representation immediately, Ulid is twice faster than Guid.

  • GetHashCode
Method Mean Error Ratio Gen 0/1k Op Gen 1/1k Op Gen 2/1k Op Allocated Memory/Op
Guid_ 0.9706 ns NA 1.00 - - - -
Ulid_ 1.0329 ns NA 1.06 - - - -
NUlid_ 20.6175 ns NA 21.24 0.0063 - - 40 B

GetHashCode is called when use dictionary's key. Ulid is fast and zero allocation.

  • Equals
Method Mean Error Ratio Gen 0/1k Op Gen 1/1k Op Gen 2/1k Op Allocated Memory/Op
Guid_ 1.819 ns NA 1.00 - - - -
Ulid_ 2.023 ns NA 1.11 - - - -
NUlid_ 29.875 ns NA 16.43 0.0126 - - 80 B

Equals is called when use dictionary's key. Ulid is fast and zero allocation.

  • CompareTo
Method Mean Error Ratio Gen 0/1k Op Gen 1/1k Op Gen 2/1k Op Allocated Memory/Op
Guid_ 5.409 ns NA 1.00 - - - -
Ulid_ 3.838 ns NA 0.71 - - - -
NUlid_ 17.126 ns NA 3.17 0.0063 - - 40 B

CompareTo is called when use sort. Ulid is fastest and zero allocation.

Cli

You can install command-line to generate ulid string by .NET Core Global Tool.

dotnet tool install --global ulid-cli

after installed, you can call like here.

$ dotnet ulid
01D7CB31YQKCJPY9FDTN2WTAFF

$ dotnet ulid -t "2019/03/25" -min
01D6R3EBC00000000000000000

$ dotnet ulid -t "2019/03/25" -max
01D6R3EBC0ZZZZZZZZZZZZZZZZ

$ dotnet ulid -t "2019/03/25" -max -base64
AWmwNy2A/////////////w==
argument list:
-t, -timestamp: [default=null]timestamp(converted to UTC, ISO8601 format recommended)
-r, -randomness: [default=null]randomness bytes(formatted as Base32, must be 16 characters, case insensitive)
-b, -base64: [default=False]output as base64 format, or output base32 if false
-min, -minRandomness: [default=False]min-randomness(use 000...)
-max, -maxRandomness: [default=False]max-randomness(use ZZZ...)

This CLI tool is powered by ConsoleAppFramework.

Integrate

System.Text.Json

NuGet: Ulid.SystemTextJson

You can use custom Ulid converter - Cysharp.Serialization.Json.UlidJsonConverter.

var options = new JsonSerializerOptions()
{
    Converters =
    {
        new Cysharp.Serialization.Json.UlidJsonConverter()
    }
};

JsonSerializer.Serialize(Ulid.NewUlid(), options);

If application targetframework is netcoreapp3.0, converter is builtin, does not require to add Ulid.SystemTextJson package, and does not require use custom options.

MessagePack-CSharp

NuGet: Ulid.MessagePack

You can use custom Ulid formatter - Cysharp.Serialization.MessagePack.UlidMessagePackFormatter and resolver - Cysharp.Serialization.MessagePack.UlidMessagePackResolver.

var resolver = MessagePack.Resolvers.CompositeResolver.Create(
    Cysharp.Serialization.MessagePack.UlidMessagePackResolver.Instance,
    MessagePack.Resolvers.StandardResolver.Instance);
var options = MessagePackSerializerOptions.Standard.WithResolver(resolver);

MessagePackSerializer.Serialize(Ulid.NewUlid(), options);

If you want to use this custom formatter on Unity, download UlidMessagePackFormatter.cs.

Dapper

For Dapper or other ADO.NET database mapper, register custom converter from Ulid to binary or Ulid to string.

public class BinaryUlidHandler : TypeHandler<Ulid>
{
    public override Ulid Parse(object value)
    {
        return new Ulid((byte[])value);
    }

    public override void SetValue(IDbDataParameter parameter, Ulid value)
    {
        parameter.DbType = DbType.Binary;
        parameter.Size = 16;
        parameter.Value = value.ToByteArray();
    }
}

public class StringUlidHandler : TypeHandler<Ulid>
{
    public override Ulid Parse(object value)
    {
        return Ulid.Parse((string)value);
    }

    public override void SetValue(IDbDataParameter parameter, Ulid value)
    {
        parameter.DbType = DbType.StringFixedLength;
        parameter.Size = 26;
        parameter.Value = value.ToString();
    }
}

// setup handler
Dapper.SqlMapper.AddTypeHandler(new BinaryUlidHandler());

Entity Framework Core

to use in EF, create ValueConverter and bind it.

public class UlidToBytesConverter : ValueConverter<Ulid, byte[]>
{
    private static readonly ConverterMappingHints defaultHints = new ConverterMappingHints(size: 16);

    public UlidToBytesConverter() : this(null)
    {
    }

    public UlidToBytesConverter(ConverterMappingHints mappingHints = null)
        : base(
                convertToProviderExpression: x => x.ToByteArray(),
                convertFromProviderExpression: x => new Ulid(x),
                mappingHints: defaultHints.With(mappingHints))
    {
    }
}

public class UlidToStringConverter : ValueConverter<Ulid, string>
{
    private static readonly ConverterMappingHints defaultHints = new ConverterMappingHints(size: 26);

    public UlidToStringConverter() : this(null)
    {
    }

    public UlidToStringConverter(ConverterMappingHints mappingHints = null)
        : base(
                convertToProviderExpression: x => x.ToString(),
                convertFromProviderExpression: x => Ulid.Parse(x),
                mappingHints: defaultHints.With(mappingHints))
    {
    }
}

To use those converters, you can either specify individual properties of entities in OnModelCreating method of your context:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<MyEntity>()
        .Property(e => e.MyProperty)
        .HasConversion<UlidToStringConverter>()
        .HasConversion<UlidToBytesConverter>();
}

or use model bulk configuration for all properties of type Ulid. To do this, overload ConfigureConventions method of your context:

protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
    configurationBuilder
        .Properties<Ulid>()
        .HaveConversion<UlidToStringConverter>()
        .HaveConversion<UlidToBytesConverter>();
}

License

This library is under the MIT License.

ulid's People

Contributors

akrock avatar dependabot[bot] avatar fdipuma avatar github-actions[bot] avatar guitarrapc avatar hadashia avatar hanachiru avatar hexagonite avatar itn3000 avatar lynzrand avatar mayuki avatar neuecc avatar timothymakkison avatar yoshifumikawai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ulid's Issues

Campos tempid criado nas migrations

Estou implementando a lib e percebi esta sendo gerado um campo tempid nas migrations sendo este um campo unique alguem saberia me informar o porque da criação deste campo?

different ulid was generated even if randomness parameter was set

Overview

Different ULID was generated even if using Ulid.NewUlid(DateTimeOffset d, ReadOnlySpan<byte> r).

Environment

  • dotnet-sdk-3.0pre3
  • Ulid-0.1.0

Steps to reproduce

  1. run following procedure
            var d = DateTime.Parse("1970/1/1 00:00:00Z");
            var r = new byte[10];
            var first = Ulid.NewUlid(d, r);
            var second = Ulid.NewUlid(d, r);
            Console.WriteLine($"first={first.ToString()}, second={second.ToString()}");

Expected

first and second is same value

Actual

first and second are different

Notes

Ulid.NewUlid(DateTimeOffset t, ReadOnlySpan<byte> r) seems to ignore r parameter

Ulid/src/Ulid/Ulid.cs

Lines 160 to 164 in e33f674

public static Ulid NewUlid(DateTimeOffset timestamp, ReadOnlySpan<byte> randomness)
{
if (randomness.Length != 10) throw new ArgumentException("invalid randomness length, length:" + randomness.Length);
return new Ulid(timestamp.ToUnixTimeMilliseconds(), RandomProvider.GetXorShift64());
}

Ulid.Parse cannot round trip with the guid string representation.

Currently the implementation of Ulid.Parse will not parse a Ulid that is in GUID format back into the correct Ulid.

Example:

var ulidX = Ulid.NewUlid();
var guidX = ulidX.ToGuid();
var ulidXrt = Ulid.Parse(guidX.ToString());

var xeq = ulidX == ulidXrt;

var guidY = Guid.NewGuid();
var ulidY = Ulid.Parse(guidY.ToString());
var guidYrt = ulidY.ToGuid();

var yeq = guidY == guidYrt;

With this code in both cases the equality checks on the round-tripped from GUID string versions will fail to be the same as the original Ulid (or GUID). I would consider this unexpected and potentially dangerous behavior for data integrity purposes.

I would suggest that the implementation of Ulid.Parse should detect that a GUID format (not ULID) has been passed and either:

  • Parse it as a GUID and return the equivalent of: new Uild(Guid.Parse(input))
  • Throw an exception explaining that the input was in GUID format which is not supported.

Coupling of Ulid and System.Text.Json

Even though there is a separate Ulid.SystemTextJson project, containing the JsonConverter for Ulid.
However the converter is already in the Ulid project which now has a hard-coded reference on System.Text.Json

I know it is convenient to have this attribute, but it is coupling.

Can this be decoupled?
We have users on both NewtonSoft.Json and System.Text.Json and don't want to pull in the 2nd when using the 1st.
We also have code using protobuf which should not pull in any Json package.

Unable to create new Ulid from Guid

Hi,

here's my code :
Guid id = new Guid("018ced5c-1f3d-da5f-8349-8acba12a5e3f");
Ulid idUlid = new Ulid(id);

And here's the result :
image

The Ulid.Guid is incorrect.

I don't really understand why and how to fix this, thank you for your time.

Sincerely,

Nicolas

Tasks

  • library impl
    • NewUlid
    • tostring
    • parse
    • other Guid compatibility
    • other Ulid utility
  • dotnet tool(encode/decode Ulid)
  • Setup CI
  • Unit tests
  • Documentation
  • Benchmark(compare with NUlid, Guid)
  • more Guid compatibility(operator overload, etc)
  • extensions
    • JSON.NET
    • Utf8Json
    • MessaegePack-CSharp
    • Dapper
  • Serialization Compatibility
    • BinaryFormatter
    • DataContractSerializer

Code modernisation

Optimize and modernise code to be in parity with System.Guid

Modernisation

  • Implement ISpanFormattable, IComparable, ISpanParsable<Ulid>, see #35
  • Remove unsafe/pinning code in favor of ref Unsafe see Guid.GetHashCode
  • Add if BigEndian logic (Does this library supports big endian?)

Optimisation

  • Use string.Create where possible
  • Vectorize the ToGuid, public Ulid(Guid guid) shuffle.
  • Vectorize equality #37
  • Vectorize Comparison see Guid.FastCompareTo
  • Consider vectorizing TryWriteStringify
  • Vectorize internal Ulid(long timestampMilliseconds timestamp shuffling
  • Vectorize internal Ulid(ReadOnlySpan<char> base32)
  • Vectorize public DateTimeOffset Time

Ulid.NewUlid() crashes on Galaxy A13 and IL2CPP

Unity3D 2022.3.13f1
When I make an apk build and run it on Galaxy A13 it crashes on Ulid.NewUlid()
It crashes every time

Stacktrace

Crashed: Thread: SIGBUS  0x00000000ac9fbcea
#00 pc 0x48dd824 libil2cpp.so (Ulid._ctor) (BuildId: cf773a2dd8bd74ee)
#01 pc 0x5429ca2 libil2cpp.so (__Il2CppComDelegate_Finalize_mC9F8EA94444C3AF0A43CC723A23EE4D8B7984F8C) (BuildId: cf773a2dd8bd74ee)
#02 pc 0x542dbbe libil2cpp.so (__Il2CppComDelegate_Finalize_mC9F8EA94444C3AF0A43CC723A23EE4D8B7984F8C) (BuildId: cf773a2dd8bd74ee)
#03 pc 0xbc272 libc.so (BuildId: f1f4a4b2b76c986f7bd6e840119e41e2)
#04 pc 0xbc272 libc.so (BuildId: f1f4a4b2b76c986f7bd6e840119e41e2)
#05 pc 0x48e2186 libil2cpp.so (Ulid._cctor) (BuildId: cf773a2dd8bd74ee)
#06 pc 0x1347ce2 libil2cpp.so (RuntimeInvoker_FalseVector4(void (*)(), MethodInfo const*, void*, void**, void*)) (BuildId: cf773a2dd8bd74ee)
#07 pc 0x14a9b76 libil2cpp.so (il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const*, void*, void**)) (BuildId: cf773a2dd8bd74ee)
#08 pc 0x9a205c libil2cpp.so (BuildId: cf773a2dd8bd74ee)
#09 pc 0xbc272 libc.so (BuildId: f1f4a4b2b76c986f7bd6e840119e41e2)
#10 pc 0x14a9ab6 libil2cpp.so (il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**)) (BuildId: cf773a2dd8bd74ee)
#11 pc 0x56021fa libil2cpp.so (__Il2CppComDelegate_Finalize_mC9F8EA94444C3AF0A43CC723A23EE4D8B7984F8C) (BuildId: cf773a2dd8bd74ee)
#12 pc 0x14a791e libil2cpp.so (il2cpp::vm::Runtime::ClassInit(Il2CppClass*)) (BuildId: cf773a2dd8bd74ee)
#13 pc 0x55756bd libil2cpp.so (__Il2CppComDelegate_Finalize_mC9F8EA94444C3AF0A43CC723A23EE4D8B7984F8C) (BuildId: cf773a2dd8bd74ee)
#14 pc 0x54383c6 libil2cpp.so (__Il2CppComDelegate_Finalize_mC9F8EA94444C3AF0A43CC723A23EE4D8B7984F8C) (BuildId: cf773a2dd8bd74ee)
...

SystemInfo CPU = ARMv7 VFPv3 NEON, Cores = 8, Memory = 3707mb
SystemInfo ARM big.LITTLE configuration: 8 big (mask: 0xff), 0 little (mask: 0x0)
Version '2022.3.13f1 (5f90a5ebde0f)', Build type 'Development', Scripting Backend 'il2cpp', CPU 'armeabi-v7a', Stripping 'Enabled'

Discussion: Why not use integers?

Pardon me for the appearance that I might be trolling, but I promise I'm not. I'm legitimately interested in answers to this.

I've been using integer primary keys for decades, and in all these years I haven't run into a single problem. I'm not sure what the fuss is all about. Enlighten me.

I'm a staunch adherent to the rule that primary/foreign keys are to be used for internal database referential integrity only. They should never be exposed outside the database—not in source code, heaven forbid in a URL or some such other place in the UI/UX.

So if that's the only reason to not use integers—obfuscation in the UI—I'm at a loss to see why I should switch.

Change My Mind™

Cannot install ulid-cli

Hi, probably noob issue here but posting because I don't know how to proceed... Thing is I'm trying to install the ulid-cli as indicated in the readme.md with dotnet tool install --global ulid-cli but it fails throwing an HttpRequestException: 401 Unauthorized:

image

What am I doing wrong? Thanks!

Ordering of Ulids produced at the same time

Hello,
First, I’d like to thank you for your valuable open source contributions to the .NET community.

From a cursory code analysis there seem to be no guarantees regarding ordering when the timestamp component is the same - I am however unsure about this assessment, and I could use some help.

If that’s the case, are there any plans to include additional out of the box guarantees ordering-wise?

TryParse/Parse does not detect invalid string content

According to the "canonical spec":

Technically, a 26-character Base32 encoded string can contain 130 bits of information, whereas a ULID must only contain 128 bits. Therefore, the largest valid ULID encoded in Base32 is 7ZZZZZZZZZZZZZZZZZZZZZZZZZ, which corresponds to an epoch time of 281474976710655 or 2 ^ 48 - 1.

Any attempt to decode or encode a ULID larger than this should be rejected by all implementations, to prevent overflow bugs.

However, parsing 26 Z's succeeds, even though it clamps the value to the maximum possible value.

Furthermore, parsing any string consisting of 26 characters succeeds, regardless of the characters, whereas only a subset of all possible 26-character strings are valid Ulids.

Example:

Console.WriteLine(Ulid.TryParse(",,,,,,,,,,,,,,,,,,,,,,,,,,", out Ulid u));

outputs:

True

Unable to use ULID in ModelBinding for Asp.net (core)

Attempting to use a ULID as a route parameter in a Asp.net core application will currently fail due to the following exception.

System.InvalidOperationException: Could not create an instance of type 'System.Ulid'. Model bound complex types must not be abstract or value types and must have a parameterless constructor. Alternatively, give the 'input' parameter a non-null default value.

Example code:

using System;
using Microsoft.AspNetCore.Mvc;

namespace WebAppBinding
{
    [Route("test")]
    [ApiController]
    public class TestController : ControllerBase
    {

        [Route("{input}")]
        [HttpGet]
        public Ulid Echo([FromRoute] Ulid input)
        {
            return input;
        }
    }
}

Expected Result:
Much like a GUID a ULID is a valid route parameter.

Current Result:
The documented exception above.

This issue can be prevented by adding a TypeConverter for ULID that is able to convert from a string value. I will open a PR with working changes shortly.

Serialization Object must mark MessagePackObjectAttribute. type: global::System.Ulid

What happened

  • Add Ulid to project
  • Add UlidMessagePackResolver and UlidMessagePackFormatter from Cysharp.Serialization.MessagePack
  • Use Ulid in a [MessagePackObject]
  • dotnet mpc -i . -o "Visionary\Assets\Scripts\Frameworks\MessagePack"
    => Exception

Exception

dotnet mpc -i . -o "Visionary\Assets\Scripts\Frameworks\MessagePack"
Project Compilation Start:.
Project Compilation Complete:00:00:28.3916847
Method Collect Start
Fail in console app running on MessagepackCompiler.RunAsync
MessagePackCompiler.CodeAnalysis.MessagePackGeneratorResolveFailedException: Serialization Object must mark MessagePackObjectAttribute. type: global::System.Ulid
   at MessagePackCompiler.CodeAnalysis.TypeCollector.GetObjectInfo(INamedTypeSymbol type) in D:\a\1\s\src\MessagePack.GeneratorCore\CodeAnalysis\TypeCollector.cs:line 610
   at MessagePackCompiler.CodeAnalysis.TypeCollector.CollectObject(INamedTypeSymbol type) in D:\a\1\s\src\MessagePack.GeneratorCore\CodeAnalysis\TypeCollector.cs:line 604
   at MessagePackCompiler.CodeAnalysis.TypeCollector.CollectCore(ITypeSymbol typeSymbol) in D:\a\1\s\src\MessagePack.GeneratorCore\CodeAnalysis\TypeCollector.cs:line 392
   at MessagePackCompiler.CodeAnalysis.TypeCollector.CollectGeneric(INamedTypeSymbol type) in D:\a\1\s\src\MessagePack.GeneratorCore\CodeAnalysis\TypeCollector.cs:line 522
   at MessagePackCompiler.CodeAnalysis.TypeCollector.CollectCore(ITypeSymbol typeSymbol) in D:\a\1\s\src\MessagePack.GeneratorCore\CodeAnalysis\TypeCollector.cs:line 371
   at MessagePackCompiler.CodeAnalysis.TypeCollector.GetObjectInfo(INamedTypeSymbol type) in D:\a\1\s\src\MessagePack.GeneratorCore\CodeAnalysis\TypeCollector.cs:line 784
   at MessagePackCompiler.CodeAnalysis.TypeCollector.CollectObject(INamedTypeSymbol type) in D:\a\1\s\src\MessagePack.GeneratorCore\CodeAnalysis\TypeCollector.cs:line 604
   at MessagePackCompiler.CodeAnalysis.TypeCollector.CollectCore(ITypeSymbol typeSymbol) in D:\a\1\s\src\MessagePack.GeneratorCore\CodeAnalysis\TypeCollector.cs:line 392
   at MessagePackCompiler.CodeAnalysis.TypeCollector.Collect() in D:\a\1\s\src\MessagePack.GeneratorCore\CodeAnalysis\TypeCollector.cs:line 323
   at MessagePackCompiler.CodeGenerator.GenerateFileAsync(String input, String output, String conditionalSymbol, String resolverName, String namespace, Boolean useMapMode, String multipleIfDirectiveOutputSymbols) in D:\a\1\s\src\MessagePack.GeneratorCore\CodeGenerator.cs:line 58
   at MessagePack.Generator.MessagepackCompiler.RunAsync(String input, String output, String conditionalSymbol, String resolverName, String namespace, Boolean useMapMode, String multipleIfDirectiveOutputSymbols) in D:\a\1\s\src\MessagePack.Generator\MessagepackCompiler.cs:line 30
   at ConsoleAppFramework.ConsoleAppEngine.RunCore(ConsoleAppContext ctx, Type type, MethodInfo methodInfo, String[] args, Int32 argsOffset)

Expected
Regenerate the generated formatters and resolvers for classes flagged as [MessagePackObject] in all *.csproj files in .\**

Additional information
The same error occurs when running on a single csproj dotnet mpc -i "Application.csproj" -o "Visionary\Assets\Scripts\Frameworks\MessagePack" with the following [MessagePackObject] classes

using System;
using MessagePack;

namespace Application.Project.Files.Mpk
{
	[MessagePackObject]
	public class UlidFileMpk
	{		
		[IgnoreMember]
		public string OpenedDirectory;

		[Key(0)]
		public Ulid Ulid = Ulid.NewUlid();
	}
}
using System;
using System.Collections.Generic;
using MessagePack;

namespace Application.Project.Files.Mpk
{
	[MessagePackObject]
	public class ProjectCacheRegistryMpk
	{
		[Key(0)]
		public Dictionary<Ulid, string> UlidToRelativePath = new Dictionary<Ulid, string>();

		[IgnoreMember]
		public string OpenedDirectory;

		public bool TryGetRelativePath(Ulid ulid, out string relativePath) => UlidToRelativePath.TryGetValue(ulid, out relativePath);

		public void Add(Ulid ulid, string relativePath) => UlidToRelativePath.Add(ulid, relativePath);
	}
}

Platform & Version

  • Unity 2020.1.2f1
  • Ulid 1.0.0
  • dotnet --version 3.1.401
  • mpc installed locally dotnet tool install MessagePack.Generator

Nuget dependencies for netcoreapp

Hi!

Awesome project and great performance 👍

Is there any reason why you are taking a dependency on both:

System.Memory (>= 4.5.2)
System.Runtime.CompilerServices.Unsafe (>= 4.5.2)

when targeting netcoreapp3.0?

I understand is necessary for netstandard2.0, but it could be very useful to drop those dependencies for netcoreapp, so we do not have to import nuget packages in apps that already have the APIs inside their SDK.

Entity Framework Core more detailed usage guide

The doc provides two classes UlidToBytesConverter and UlidToStringConverter. But which one to use when? For the class BaseModel, I am using the UlidToStringConverter for storing the ULID as string in the DB. But when to use the UlidToBytesConverter? Can you give any example? Also, is my approach of saving ULID as string in the DB any good?

public abstract class BaseModel
{
    public Ulid Id { get; set; }
    public DateTime CreatedAt { get; } = DateTime.UtcNow;
    public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
}

public class BaseModelConfig : IEntityTypeConfiguration<BaseModel>
{
    public void Configure(EntityTypeBuilder<BaseModel> builder)
    {
        builder.Property(e => e.Id).HasConversion(new UlidToStringConverter());

        builder.UseTpcMappingStrategy();
        builder.Property(x => x.CreatedAt);

    }
}

Create Guids directly using the Ulid algorithm

I would like to use Ulids to allow for the geo-distributed insertion of lexographically sortable entities.

However, I am using PostgreSQL as the data store and, in practice, it is easier to use the UUID SQL data type and the Guid CLR type rather than Ulids and SQL byte arrays directly. I note that this library includes the Ulid.ToGuid method for converting Ulids to Guids and I have confirmed through tests that sorting on the Guid produced in this way works correctly.

Is it possible to create a Ulid in Guid form directly, to avoid the extra conversion, e.g.:

Guid myGuid1 = Ulid.NewGuid();

// Or as a Guid  extension method
Guid myGuid2 = Guid.NewGuidUsingUlidAlg();

ID Collisions When Generated from Strings

We're using Ulid to generate unique IDs based on names.
For the most part it works, but we're seeing a lot of ID collisions in certain circumstances...

For instance, these two collide:
image
image

I'm sorry if I'm misunderstanding how this works, but I was under the impression that Ulids generated should be more unique than this?

This is the implementation: (Sorry, code tags butchered everything..)
image

.ToUlid:
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.