本文整理汇总了C#中MessagePackObject类的典型用法代码示例。如果您正苦于以下问题:C# MessagePackObject类的具体用法?C# MessagePackObject怎么用?C# MessagePackObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessagePackObject类属于命名空间,在下文中一共展示了MessagePackObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakePacket
public byte[] MakePacket(string label, DateTime timestamp, params object[] records)
{
string tag;
if (!string.IsNullOrEmpty(label))
{
tag = _tag + "." + label;
}
else
{
tag = _tag;
}
var xs = new List<MessagePackObject>();
xs.Add(tag);
var children = new List<MessagePackObject>();
foreach (var record in records)
{
var child = new List<MessagePackObject>();
child.Add(timestamp.ToUniversalTime().Subtract(_epoc).TotalSeconds);
child.Add(CreateTypedMessagePackObject(record.GetType(), record, first:true));
children.Add(new MessagePackObject(child));
}
xs.Add(new MessagePackObject(children));
var x = new MessagePackObject(xs);
var ms = new MemoryStream();
var packer = Packer.Create(ms);
packer.Pack(x);
return ms.ToArray();
}
示例2: RpcException
/// <summary>
/// Initialize new instance with unpacked data.
/// </summary>
/// <param name="rpcError">
/// Metadata of error. If you specify null, <see cref="MsgPack.Rpc.RpcError.RemoteRuntimeError"/> is used.
/// </param>
/// <param name="unpackedException">
/// Exception data from remote MessagePack-RPC server.
/// </param>
/// <exception cref="SerializationException">
/// Cannot deserialize instance from <paramref name="unpackedException"/>.
/// </exception>
protected internal RpcException( RpcError rpcError, MessagePackObject unpackedException )
: this( rpcError, unpackedException.GetString( MessageKeyUtf8 ), unpackedException.GetString( DebugInformationKeyUtf8 ) )
{
if ( unpackedException.IsDictionary )
{
MessagePackObject mayBeArray;
if ( unpackedException.AsDictionary().TryGetValue( _remoteExceptionsUtf8, out mayBeArray ) && mayBeArray.IsArray )
{
var array = mayBeArray.AsList();
this._remoteExceptions = new RemoteExceptionInformation[ array.Count ];
for ( int i = 0; i < this._remoteExceptions.Length; i++ )
{
if ( array[ i ].IsList )
{
this._remoteExceptions[ i ] = new RemoteExceptionInformation( array[ i ].AsList() );
}
else
{
// Unexpected type.
Debug.WriteLine( "Unexepcted ExceptionInformation at {0}, type: {1}, value: \"{2}\".", i, array[ i ].UnderlyingType, array[ i ] );
this._remoteExceptions[ i ] = new RemoteExceptionInformation( new MessagePackObject[] { array[ i ] } );
}
}
}
}
#if !SILVERLIGHT && !MONO
this.RegisterSerializeObjectStateEventHandler();
#endif
}
示例3: MsgUnPackTable
public static bool MsgUnPackTable(out LuaTable luatable, ref MessagePackObject pObj)
{
LuaTable result = new LuaTable();
luatable = result;
var mPk = pObj.AsDictionary();
bool isString = false;
string key;
object value;
foreach (var item in mPk)
{
//parse for key
MessagePackObject mKey = item.Key;
if (mKey.IsRaw)
{
key = mKey.AsString();
isString = true;
}
else if (true == mKey.IsTypeOf<double>())
{
key = mKey.AsDouble().ToString();
}
else
{
LoggerHelper.Error("key type error");
return false;
}
//parse for value
MessagePackObject mValue = item.Value;
if (mValue.IsRaw)
{
value = mValue.AsString();
}
else if (mValue.IsDictionary)
{
LuaTable luatbl;
MsgUnPackTable(out luatbl, ref mValue);
value = luatbl;
}
else if (true == mValue.IsTypeOf<bool>())
{
value = mValue.AsBoolean();
}
else if (true == mValue.IsTypeOf<double>())
{
value = mValue.AsDouble();
}
else
{
LoggerHelper.Error("value type error");
return false;
}
result.Add(key, isString, value);
isString = false;
}
return true;
}
示例4: TestAsByteOverflow
public void TestAsByteOverflow()
{
var target = new MessagePackObject( Byte.MaxValue + 1 );
Assert.Throws<InvalidOperationException>(
() =>
{
var result = ( Byte )target;
Console.WriteLine( "TestAsByteOverflow:0x{0:x}({0:#,0})[{1}]", result, result.GetType() );
}
);
}
示例5: RpcErrorMessage
/// <summary>
/// Initialize new instance.
/// </summary>
/// <param name="error">Error information of the error.</param>
/// <param name="detail">Unpacked detailed information of the error which was occurred in remote endpoint.</param>
/// <exception cref="ArgumentNullException">
/// <paramref name="error"/> is null.
/// </exception>
public RpcErrorMessage( RpcError error, MessagePackObject detail )
{
if ( error == null )
{
throw new ArgumentNullException( "error" );
}
Contract.EndContractBlock();
this._error = error;
this._detail = detail;
}
示例6: List
/// <summary>
/// </summary>
/// <param name="objects">
/// </param>
/// <returns>
/// </returns>
public static string List(MessagePackObject[] objects)
{
string output = string.Empty;
foreach (MessagePackObject mpo in objects)
{
// Using \r\n here with purpose, dont change to Environment.NewLine
output += mpo.UnderlyingType.ToString() + ": " + mpo.ToString() + "\r\n";
}
return output;
}
示例7: GetTimeSpan
public static TimeSpan? GetTimeSpan( this MessagePackObject source, MessagePackObject key )
{
if ( source.IsDictionary )
{
MessagePackObject value;
if ( source.AsDictionary().TryGetValue( key, out value ) && value.IsTypeOf<Int64>().GetValueOrDefault() )
{
return new TimeSpan( value.AsInt64() );
}
}
return null;
}
示例8: GetString
public static string GetString( this MessagePackObject source, MessagePackObject key )
{
if ( source.IsDictionary )
{
MessagePackObject value;
if ( source.AsDictionary().TryGetValue( key, out value ) && value.IsTypeOf<string>().GetValueOrDefault() )
{
return value.AsString();
}
}
return null;
}
示例9: Execute
public override bool Execute(
INamedEntity self,
IEntity caller,
IInstancedEntity target,
MessagePackObject[] arguments)
{
ICharacter character = (ICharacter)self;
int statelId = (int)((uint)0xC0000000 | arguments[1].AsInt32() | (arguments[2].AsInt32() << 16));
character.Stats[StatIds.externaldoorinstance].BaseValue = 0;
character.Stats[StatIds.externalplayfieldinstance].BaseValue = 0;
if (arguments[1].AsInt32() > 0)
{
StatelData sd = PlayfieldLoader.PFData[arguments[1].AsInt32()].GetDoor(statelId);
if (sd == null)
{
throw new Exception(
"Statel " + arguments[3].AsInt32().ToString("X") + " not found? Check the rdb dammit");
}
Vector3 v = new Vector3(sd.X, sd.Y, sd.Z);
Quaternion q = new Quaternion(sd.HeadingX, sd.HeadingY, sd.HeadingZ, sd.HeadingW);
Quaternion.Normalize(q);
Vector3 n = (Vector3)q.RotateVector3(Vector3.AxisZ);
v.x += n.x * 2.5;
v.z += n.z * 2.5;
character.Playfield.Teleport(
(Dynel)character,
new Coordinate(v),
q,
new Identity() { Type = (IdentityType)arguments[0].AsInt32(), Instance = arguments[1].AsInt32() });
}
return true;
self.Stats[StatIds.externalplayfieldinstance].Value = 0;
self.Stats[StatIds.externaldoorinstance].Value = 0;
self.Playfield.Teleport(
(Dynel)self,
new Coordinate(100, 10, 100),
((ICharacter)self).Heading,
new Identity() { Type = (IdentityType)arguments[0].AsInt32(), Instance = arguments[1].AsInt32() });
return true;
}
示例10: PackValuesAsArray
private static void PackValuesAsArray(
Packer packer,
MessagePackObject memberDefault,
MessagePackObject nullButValueType,
MessagePackObject nullAndNullableValueType,
MessagePackObject nullAndReferenceType,
MessagePackObject prohibitReferenceType
)
{
packer.PackArrayHeader( 5 );
packer.Pack( memberDefault );
packer.Pack( nullButValueType );
packer.Pack( nullAndNullableValueType );
packer.Pack( nullAndReferenceType );
packer.Pack( prohibitReferenceType );
}
示例11: Execute
/// <summary>
/// </summary>
/// <param name="self">
/// </param>
/// <param name="caller">
/// </param>
/// <param name="target">
/// </param>
/// <param name="arguments">
/// </param>
/// <returns>
/// </returns>
public override bool Execute(
INamedEntity self,
IEntity caller,
IInstancedEntity target,
MessagePackObject[] arguments)
{
string text = arguments[0].AsString();
var message = new FormatFeedbackMessage()
{
Identity = self.Identity,
FormattedMessage = "~&!!!\":!!!)<s" + (char)(text.Length + 1),
Unknown1 = 0,
Unknown2 = 0,
};
((ICharacter)self).Send(message);
return true;
}
示例12: RpcException
/// <summary>
/// Initialize new sintance with unpacked data.
/// </summary>
/// <param name="rpcError">
/// Metadata of error. If you specify null, <see cref="MsgPack.Rpc.RpcError.RemoteRuntimeError"/> is used.
/// </param>
/// <param name="unpackedException">
/// Exception data from remote MessagePack-RPC server.
/// </param>
/// <exception cref="SerializationException">
/// Cannot deserialize instance from <paramref name="unpackedException"/>.
/// </exception>
protected internal RpcException( RpcError rpcError, MessagePackObject unpackedException )
: this(rpcError, GetString( unpackedException, MessageKeyUtf8, true ), GetString( unpackedException, DebugInformationKeyUtf8, false ))
{
IList<MessagePackObject> array;
if ( MessagePackObjectDictionary.TryGetArray( unpackedException, _remoteExceptionsUtf8, null, out array ) )
{
try
{
this._remoteExceptions = new RemoteExceptionInformation[ array.Count ];
for ( int i = 0; i < this._remoteExceptions.Length; i++ )
{
this._remoteExceptions[ i ] = new RemoteExceptionInformation( array[ i ].AsList() );
}
}
catch ( InvalidOperationException ex )
{
throw new SerializationException( "Failed to deserialize remote exception information", ex );
}
}
}
示例13: UnpackFromMessage
public void UnpackFromMessage( MessagePackObject messagePackObject )
{
if (! messagePackObject.IsTypeOf<IList<MessagePackObject>>().GetValueOrDefault() )
{
throw new ArgumentException(messagePackObject.UnderlyingType.ToString());
}
var asList = messagePackObject.AsList();
if ( asList.Count != 5 )
{
throw new ArgumentException();
}
uri = asList[ 0 ].AsString();
title = asList[ 1].AsString();
width = asList[ 2 ].AsInt32();
height = asList[ 3 ].AsInt32();
size = asList[ 4 ].AsInt32();
}
示例14: PackValuesAsMap
private static void PackValuesAsMap(
Packer packer,
MessagePackObject memberDefault,
MessagePackObject nullButValueType,
MessagePackObject nullAndNullableValueType,
MessagePackObject nullAndReferenceType,
MessagePackObject prohibitReferenceType
)
{
packer.PackMapHeader( 5 );
packer.PackString( "MemberDefault" );
packer.Pack( memberDefault );
packer.PackString( "NullButValueType" );
packer.Pack( nullButValueType );
packer.PackString( "NullAndNullableValueType" );
packer.Pack( nullAndNullableValueType );
packer.PackString( "NullAndReferenceType" );
packer.Pack( nullAndReferenceType );
packer.PackString( "ProhibitReferenceType" );
packer.Pack( prohibitReferenceType );
}
示例15: TestKnownErrors_Properties_ToException_ToString_GetHashCode_Success
public void TestKnownErrors_Properties_ToException_ToString_GetHashCode_Success()
{
foreach ( var prop in typeof( RpcError ).GetProperties( BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic ).Where( item => item.PropertyType == typeof( RpcError ) ) )
{
var target = prop.GetValue( null, null ) as RpcError;
Assert.That( target, Is.Not.Null, prop.Name );
Assert.That( target.DefaultMessage, Is.Not.Null.And.Not.Empty, prop.Name );
Assert.That( target.DefaultMessageInvariant, Is.Not.Null.And.Not.Empty, prop.Name );
Assert.That( target.Identifier, Is.Not.Null.And.Not.Empty, prop.Name );
Assert.That( target.GetHashCode(), Is.EqualTo( target.ErrorCode ), prop.Name );
Assert.That(
target.ToString(),
Is.Not.Null
.And.StringContaining( target.Identifier )
.And.StringContaining( target.ErrorCode.ToString( CultureInfo.CurrentCulture ) )
.And.StringContaining( target.DefaultMessage ),
prop.Name
);
var message = Guid.NewGuid().ToString();
var debugInformation = Guid.NewGuid().ToString();
var detail =
new MessagePackObject(
new MessagePackObjectDictionary()
{
{ RpcException.MessageKeyUtf8, message },
{ RpcException.DebugInformationKeyUtf8, debugInformation },
{ RpcArgumentException.ParameterNameKeyUtf8, "test" },
{ RpcMethodInvocationException.MethodNameKeyUtf8, "Test" },
{ RpcTimeoutException.ClientTimeoutKeyUtf8, TimeSpan.FromSeconds( 15 ).Ticks }
}
);
var exception = target.ToException( detail );
Assert.That( exception, Is.Not.Null, prop.Name );
Assert.That( exception.DebugInformation, Is.StringContaining( debugInformation ), prop.Name );
Assert.That( exception.Message, Is.StringContaining( message ), prop.Name );
Assert.That( exception.RpcError, Is.EqualTo( target ), prop.Name );
}
}