Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public static partial class Services
public const string PATH_CALLABLE_METHOD_NAME_KEY = "x-beamable-callable-method-name";
public const string PATH_CALLABLE_METHOD_CLIENT_PREFIX_KEY = "x-beamable-route-source-client-prefix";

/// <summary>
/// OpenAPI extension that describes the semantic type of a primitive field.
/// </summary>
public const string SCHEMA_SEMANTIC_TYPE_NAME_KEY = "x-beamable-semantic-type";

public const string MICROSERVICE_FEDERATED_COMPONENTS_V2_INTERFACE_KEY = "interface";
public const string MICROSERVICE_FEDERATED_COMPONENTS_V2_FEDERATION_ID_KEY = "federationId";
public const string MICROSERVICE_FEDERATED_COMPONENTS_V2_FEDERATION_CLASS_NAME_KEY = "federationClassName";
Expand Down
88 changes: 88 additions & 0 deletions cli/beamable.common/Runtime/Semantics/BeamAccountId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using Beamable.Common.BeamCli;
using System;

namespace Beamable.Common.Semantics
{
[CliContractType, Serializable]
public struct BeamAccountId : IBeamSemanticType<long>, IEquatable<string>, IEquatable<long>, IEquatable<BeamAccountId>
{
private long _longValue;
private string _stringValue;

public string SemanticName => "AccountId";

public long AsLong
{
get => _longValue;
set
{
_longValue = value;
_stringValue = value.ToString();
}
}

public string AsString
{
get => string.IsNullOrEmpty(_stringValue) ? _longValue.ToString() : _stringValue;
set
{
if (string.IsNullOrEmpty(value))
{
throw new ArgumentNullException($"Parameter {nameof(value)} cannot be null or empty.");
}
_stringValue = value;
_longValue = long.TryParse(value, out var longValue)
? longValue
: throw new ArgumentException($"Parameter {nameof(value)} is invalid. Must be a numeric value.");
}
}

public BeamAccountId(long value)
{
_longValue = value;
_stringValue = value.ToString();
}

public BeamAccountId(string value)
{
if (string.IsNullOrEmpty(value))
{
throw new ArgumentNullException($"Parameter {nameof(value)} cannot be null or empty.");
}
_stringValue = value;
_longValue = long.TryParse(value, out var longValue)
? longValue
: throw new ArgumentException($"Parameter {nameof(value)} is invalid. Must be a numeric value.");
}

public static implicit operator string(BeamAccountId id) => id.AsString;
public static implicit operator long(BeamAccountId id) => id.AsLong;

public static implicit operator BeamAccountId(string value) => new BeamAccountId(value);
public static implicit operator BeamAccountId(long value) => new BeamAccountId(value);
public string ToJson()
{
return AsString;
}

public bool Equals(string other)
{
return other == AsString;
}

public bool Equals(long other)
{
return other == AsLong;
}

public bool Equals(BeamAccountId other)
{
return other.AsLong == AsLong;
}

public override string ToString()
{
return AsString;
}
}
}
86 changes: 86 additions & 0 deletions cli/beamable.common/Runtime/Semantics/BeamCid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using Beamable.Common.BeamCli;

namespace Beamable.Common.Semantics
{
[CliContractType, Serializable]
public struct BeamCid : IBeamSemanticType<long>, IEquatable<string>, IEquatable<long>, IEquatable<BeamCid>
{
private long _longValue;
private string _stringValue;

public string SemanticName => "Cid";

public long AsLong {
get => _longValue;
set {
_longValue = value;
_stringValue = value.ToString();
}
}

public string AsString
{
get => string.IsNullOrEmpty(_stringValue) ? _longValue.ToString() : _stringValue;
set
{
if (string.IsNullOrEmpty(value))
{
throw new ArgumentNullException($"Parameter {nameof(value)} cannot be null or empty.");
}
_stringValue = value;
_longValue = long.TryParse(value, out var longValue)
? longValue
: throw new ArgumentException($"Parameter {nameof(value)} is invalid. Must be a numeric value.");
}
}

public BeamCid(long value)
{
_longValue = value;
_stringValue = value.ToString();
}

public BeamCid(string value)
{
if (string.IsNullOrEmpty(value))
{
throw new ArgumentNullException($"Parameter {nameof(value)} cannot be null or empty.");
}
_stringValue = value;
_longValue = long.TryParse(value, out var longValue)
? longValue
: throw new ArgumentException($"Parameter {nameof(value)} is invalid. Must be a numeric value.");
}

public static implicit operator string(BeamCid cid) => cid.AsString;
public static implicit operator long(BeamCid cid) => cid.AsLong;

public static implicit operator BeamCid(string value) => new BeamCid(value);
public static implicit operator BeamCid(long value) => new BeamCid(value);
public string ToJson()
{
return AsString;
}

public bool Equals(string other)
{
return other == AsString;
}

public bool Equals(long other)
{
return other == AsLong;
}

public bool Equals(BeamCid other)
{
return other.AsLong == AsLong;
}

public override string ToString()
{
return AsString;
}
}
}
52 changes: 52 additions & 0 deletions cli/beamable.common/Runtime/Semantics/BeamContentId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using Beamable.Common.BeamCli;
using Beamable.Common.Content;

namespace Beamable.Common.Semantics
{
[CliContractType, Serializable]
public struct BeamContentId : IBeamSemanticType<string>, IEquatable<string>, IEquatable<BeamContentId>
{
private string _value;

public string SemanticName => "ContentId";

public string AsString
{
get => _value ?? string.Empty;
set => _value = value;
}

public BeamContentId(string value)
{
_value = value;
}

public BeamContentId(ContentRef contentRef) : this(contentRef.GetId()) { }
public BeamContentId(ContentObject contentObject) : this(contentObject.Id) { }

public static implicit operator string(BeamContentId contentId) => contentId.AsString;
public static implicit operator BeamContentId(ContentRef contentRef) => new BeamContentId(contentRef);
public static implicit operator BeamContentId(ContentObject contentObject) => new BeamContentId(contentObject);
public static implicit operator BeamContentId(string contentId) => new BeamContentId(contentId);
public string ToJson()
{
return $"\"{AsString}\"";
}

public bool Equals(string other)
{
return other == AsString;
}

public bool Equals(BeamContentId other)
{
return other.AsString == AsString;
}

public override string ToString()
{
return AsString;
}
}
}
46 changes: 46 additions & 0 deletions cli/beamable.common/Runtime/Semantics/BeamContentManifestId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using Beamable.Common.BeamCli;

namespace Beamable.Common.Semantics
{
[CliContractType, Serializable]
public struct BeamContentManifestId : IBeamSemanticType<string>, IEquatable<string>, IEquatable<BeamContentManifestId>
{
private string _value;

public string SemanticName => "ContentManifestId";

public string AsString
{
get => _value ?? string.Empty;
set => _value = value;
}

public BeamContentManifestId(string value)
{
_value = value;
}

public static implicit operator string(BeamContentManifestId id) => id.AsString;
public static implicit operator BeamContentManifestId(string value) => new BeamContentManifestId(value);
public string ToJson()
{
return $"\"{AsString}\"";
}

public bool Equals(string other)
{
return other == AsString;
}

public bool Equals(BeamContentManifestId other)
{
return other.AsString == AsString;
}

public override string ToString()
{
return AsString;
}
}
}
87 changes: 87 additions & 0 deletions cli/beamable.common/Runtime/Semantics/BeamGamerTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;
using Beamable.Common.BeamCli;

namespace Beamable.Common.Semantics
{
[CliContractType, Serializable]
public struct BeamGamerTag : IBeamSemanticType<long>, IEquatable<string>, IEquatable<long>, IEquatable<BeamGamerTag>
{
private long _longValue;
private string _stringValue;

public string SemanticName => "GamerTag";

public long AsLong
{
get => _longValue;
set {
_longValue = value;
_stringValue = value.ToString();
}
}

public string AsString
{
get => string.IsNullOrEmpty(_stringValue) ? _longValue.ToString() : _stringValue;
set
{
if (string.IsNullOrEmpty(value))
{
throw new ArgumentNullException($"Parameter {nameof(value)} cannot be null or empty.");
}
_stringValue = value;
_longValue = long.TryParse(value, out var longValue)
? longValue
: throw new ArgumentException($"Parameter {nameof(value)} is invalid. Must be a numeric value.");
}
}

public BeamGamerTag(long value)
{
_longValue = value;
_stringValue = value.ToString();
}

public BeamGamerTag(string value)
{
if (string.IsNullOrEmpty(value))
{
throw new ArgumentNullException($"Parameter {nameof(value)} cannot be null or empty.");
}
_stringValue = value;
_longValue = long.TryParse(value, out var longValue)
? longValue
: throw new ArgumentException($"Parameter {nameof(value)} is invalid. Must be a numeric value.");
}

public static implicit operator string(BeamGamerTag tag) => tag.AsString;
public static implicit operator long(BeamGamerTag tag) => tag.AsLong;

public static implicit operator BeamGamerTag(string value) => new BeamGamerTag(value);
public static implicit operator BeamGamerTag(long value) => new BeamGamerTag(value);
public string ToJson()
{
return AsString;
}

public bool Equals(string other)
{
return other == AsString;
}

public bool Equals(long other)
{
return other == AsLong;
}

public bool Equals(BeamGamerTag other)
{
return other.AsLong == AsLong;
}

public override string ToString()
{
return AsString;
}
}
}
Loading
Loading