Class AbstractMapper<TModel>
Provides all abstract implementation shared by all just-in-time compiled individual mapper
for the IGeneratedEntityLogger mapper interface.
Inheritance
System.Object
AbstractMapper<TModel>
Inherited Members
Namespace: Mars.Core.Data.Compiler
Assembly: Mars.Core.dll
Syntax
public abstract class AbstractMapper<TModel> : AbstractJitMapper, IGeneratedLogger<TModel>, IOutputLogger
Type Parameters
Name | Description |
---|---|
TModel |
Remarks
Beside preventing duplicate code, the idea is to reduce to overhead coming from the JIT
compilation step by reducing the amount of generated (potential duplicate) code.
Fields
BsonDocument
Declaration
protected BsonDocument BsonDocument
Field Value
Type | Description |
---|---|
BsonDocument |
CompressionOptions
The compression options when the SerializeCompressed()
or SerializeToJsonCompressed() is used.
Declaration
protected static readonly MessagePackSerializerOptions CompressionOptions
Field Value
Type | Description |
---|---|
MessagePackSerializerOptions |
Remarks
Do not make this option object private, since it is used by the JIT generated sub types.
Frame
Declaration
protected DataFrame Frame
Field Value
Type | Description |
---|---|
DataFrame |
Properties
DateTime
Specifies the current realtime reference
Declaration
public virtual DateTime? DateTime { get; set; }
Property Value
Type | Description |
---|---|
System.Nullable<DateTime> |
Entity
The associated entity model object (either an agent or a layer)
Is refined implemented in IGeneratedEntityLogger.
Declaration
public virtual TModel Entity { get; set; }
Property Value
Type | Description |
---|---|
TModel |
Id
Gets the Id of the entity which is cared by this mapping proxy
Declaration
public Guid Id { get; set; }
Property Value
Type | Description |
---|---|
Guid |
IdString
Gets the id as a string of this entity
Declaration
public virtual string IdString { get; set; }
Property Value
Type | Description |
---|---|
System.String |
RId
Represents the identity column for relational mapping
Declaration
public virtual long RId { get; set; }
Property Value
Type | Description |
---|---|
System.Int64 |
Remarks
This property is not intended to be used from outside.
Step
Specifies the current step of this mapper
Declaration
public virtual long Step { get; set; }
Property Value
Type | Description |
---|---|
System.Int64 |
Tick
Specifies the current tick of this mapper
Declaration
public virtual long Tick { get; set; }
Property Value
Type | Description |
---|---|
System.Int64 |
Methods
Initialize()
Performs a deferred initialization of this entity-specific mapper.
This makes it possible to assign properties with values before
(e.g., the concrete entity ).
Declaration
public override void Initialize()
Overrides
Remarks
This method should always be used when something have to be implemented within the constructor scope.
IsSerializable()
Checks for the current instance, based on precondition whether this instance shall be persisted or not.
Declaration
public virtual bool IsSerializable()
Returns
Type | Description |
---|---|
System.Boolean | Returns true when the instance can be serialized otherwise false |
Serialize()
Serialize the snapshot of an agent with output properties as a
formatted byte field, encoded in hex. Instead of creating a new DataFrame struct
the primitive output properties will be serialized directly. This format
is much more smaller and faster than just to use the SerializeToFrame()
method, but for the client within the database or in the client programme (with another language)
there an explicit deserialization step necessary.
MessagePack specification
https://msgpack.org
.Net binding of MessagePack with all options described
https://github.com/neuecc/MessagePack-CSharp#performance
Declaration
public abstract byte[] Serialize()
Returns
Type | Description |
---|---|
System.Byte[] | A |
Serialize(Stream)
Serialize the output properties of the associated entity instance into format
similar to and pass it directly into a stream (e.g. Kafka, or
WebSocket)
with no intermediate overhead. Consumer of this stream the shall be aware
that they need to deserialize it explicitly according to the specification.
Declaration
public abstract void Serialize(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The stream to pass the packed frame of the output properties. |
SerializeCompressed()
Serialize the snapshot of an agent with output properties as a
formatted byte field, encoded in hex and compressed by the LZ4 compression algorithm.
Instead of creating a new DataFrame struct
the primitive output properties will be serialized directly. This format
is much more smaller and faster than just to use the SerializeToFrame()
method, but for the client within the database or in the client programme (with another language)
there an explicit deserialization step necessary.
MessagePack specification
https://msgpack.org
LZ4 compression algorithm
https://en.wikipedia.org/wiki/LZ4_(compression_algorithm)
.Net binding of MessagePack with all options described
https://github.com/neuecc/MessagePack-CSharp#performance
Declaration
public abstract byte[] SerializeCompressed()
Returns
Type | Description |
---|---|
System.Byte[] | A |
SerializeCompressed(Stream)
Serialize the output properties of the associated entity instance into a
similar to and pass it directly into a stream (e.g. Kafka, or
WebSocket)
with no intermediate overhead. Consumer of this stream the shall be aware
that they need to deserialize it explicitly according to the specification.
LZ4
compression
Declaration
public abstract void SerializeCompressed(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The stream to pass the compressed frame of the output properties. |
Remarks
When the JSON output shall used, an extra LZ4 decompression step have first to be applied.
SerializeProperties()
Serialize the values of all output properties by returning the actual value as an iterator.
Declaration
public abstract IEnumerable<> SerializeProperties()
Returns
Type | Description |
---|---|
IEnumerable<System.> | Returns an iterator containing each output property value with the associated name, and the corresponding data type of this property. When no output properties are registered, then the iterator returns nothing. |
Remarks
This method can be used to get the concrete values of an entity or layer or to generate the schema by using
the returned property names.
SerializePropertyValues()
Serialize the values of all output properties by returning the actual value as an iterator.
Declaration
public abstract IEnumerable<object> SerializePropertyValues()
Returns
Type | Description |
---|---|
IEnumerable<System.Object> | Returns an iterator containing each output property value. |
SerializeToDocument()
Serialize this instance of the proxy with the corresponding output
properties described in into a MongoDb
conforming which is reused for each tick.
Declaration
public virtual BsonDocument SerializeToDocument()
Returns
Type | Description |
---|---|
BsonDocument |
SerializeToFrame()
Generates a full-state message of this simulation object in form of new created DataFrame object.
This contains the spatial and temporal reference as well as all active output properties of this agent type.
Declaration
public virtual DataFrame SerializeToFrame()
Returns
Type | Description |
---|---|
DataFrame | A JSON-compliant output for all agent states. |
SerializeToJson()
Serialize the output properties directly as a JSON suited document.
Based on the output configuration , in default case,
this DOES NOT include the property names as keys.
Declaration
public abstract string SerializeToJson()
Returns
Type | Description |
---|---|
System.String | A JSON formatted string of all output properties for the associated agent. |
SerializeToJsonCompressed()
Serialize the output properties to , in default case,
this DOES NOT include the property names as keys.
L4Z
compressed JSON document.
Based on the output configuration Declaration
public abstract string SerializeToJsonCompressed()
Returns
Type | Description |
---|---|
System.String | A JSON formatted string of all output properties for the associated agent. |
Remarks
When the JSON output shall used, an extra LZ4 decompression step have first to be applied.
SerializeValueFor(String)
Serializes the value for the given
propertyName
or returns null otherwise.
Declaration
public abstract object SerializeValueFor(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | The property to access. |
Returns
Type | Description |
---|---|
System.Object | Returns the value or null when the property is not available. |