/// <summary> /// Creates a new <see cref="SystemTargetGrainId"/> instance. /// </summary> public static SystemTargetGrainId Create(GrainType kind, SiloAddress address, string extraIdentifier) { var addr = address.ToUtf8String(); if (extraIdentifier is string) { var extraLen = Encoding.UTF8.GetByteCount(extraIdentifier); var buf = new byte[addr.Length + 1 + extraLen]; addr.CopyTo(buf.AsSpan()); buf[addr.Length] = (byte)SegmentSeparator; Encoding.UTF8.GetBytes(extraIdentifier, 0, extraIdentifier.Length, buf, addr.Length + 1); addr = buf; } return(new SystemTargetGrainId(new GrainId(kind, new IdSpan(addr)))); }
/// <summary> /// Returns a new <see cref="SystemTargetGrainId"/> targeting the provided address. /// </summary> public SystemTargetGrainId WithSiloAddress(SiloAddress siloAddress) { var addr = siloAddress.ToUtf8String(); var key = this.GrainId.Key.AsSpan(); if (key.IndexOf((byte)SegmentSeparator) is int index && index >= 0) { var extraIdentifier = key.Slice(index + 1); var buf = new byte[addr.Length + 1 + extraIdentifier.Length]; addr.CopyTo(buf.AsSpan()); buf[addr.Length] = (byte)SegmentSeparator; extraIdentifier.CopyTo(buf.AsSpan(addr.Length + 1)); addr = buf; } return(new SystemTargetGrainId(new GrainId(GrainId.Type, new IdSpan(addr)))); }
/// <summary> /// Creates a new <see cref="SystemTargetGrainId"/> instance. /// </summary> public static SystemTargetGrainId Create(GrainType kind, SiloAddress address) => new SystemTargetGrainId(new GrainId(kind, new IdSpan(address.ToUtf8String())));
internal static GrainId CreateGrainServiceGrainId(GrainType grainType, SiloAddress address) => new GrainId(grainType, new IdSpan(address.ToUtf8String()));