本文整理汇总了C#中MessagePackObject类的典型用法代码示例。如果您正苦于以下问题:C# MessagePackObject类的具体用法?C# MessagePackObject怎么用?C# MessagePackObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessagePackObject类属于命名空间,在下文中一共展示了MessagePackObject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:joonseok,项目名称:fluent-logger-csharp,代码行数:31,代码来源:MessagePacker.cs
示例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
}
开发者ID:Indifer,项目名称:Test,代码行数:42,代码来源:RpcException.Propagation.cs
示例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;
}
开发者ID:lbddk,项目名称:ahzs-client,代码行数:56,代码来源:Utils.cs
示例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() );
}
);
}
开发者ID:gezidan,项目名称:ZYSOCKET,代码行数:11,代码来源:MessagePackObjectTest.Conversion.cs
示例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;
}
开发者ID:yfakariya,项目名称:msgpack-rpc,代码行数:20,代码来源:RpcErrorMessage.cs
示例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;
}
开发者ID:kittin,项目名称:CellAO-NightPredator,代码行数:18,代码来源:FunctionArgumentList.cs
示例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;
}
开发者ID:Indifer,项目名称:Test,代码行数:13,代码来源:MessagePackObjectExtension.cs
示例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;
}
开发者ID:Indifer,项目名称:Test,代码行数:13,代码来源:MessagePackObjectExtension.cs
示例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;
}
开发者ID:gordonc64,项目名称:CellAO-NightPredator,代码行数:48,代码来源:teleportproxy2.cs
示例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 );
}
开发者ID:purplecow,项目名称:msgpack-cli,代码行数:16,代码来源:NilImplicationTest.cs
示例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;
}
开发者ID:gordonc64,项目名称:CellAO-NightPredator,代码行数:29,代码来源:systemtext.cs
示例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 );
}
}
}
开发者ID:yfakariya,项目名称:msgpack-rpc,代码行数:32,代码来源:RpcException.Propagation.cs
示例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();
}
开发者ID:davemkirk,项目名称:msgpack-cli,代码行数:20,代码来源:Image.cs
示例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 );
}
开发者ID:davemkirk,项目名称:msgpack-cli,代码行数:21,代码来源:NilImplicationTest.cs
示例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 );
}
}
开发者ID:Indifer,项目名称:Test,代码行数:40,代码来源:RpcErrorTest.cs
示例16: 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)
{
if (arguments.Count() != 3)
{
return false;
}
uint arg1 = arguments[1].AsUInt32();
int toPlayfield = arguments[2].AsInt32();
byte destinationIndex = (byte)(arg1 >> 16);
PlayfieldData pfd = PlayfieldLoader.PFData[toPlayfield];
PlayfieldDestination pfDestination = pfd.Destinations[destinationIndex];
float newX = (pfDestination.EndX - pfDestination.StartX) * 0.5f + pfDestination.StartX;
float newZ = (pfDestination.EndZ - pfDestination.StartZ) * 0.5f + pfDestination.StartZ;
float dist = WallCollision.Distance(
pfDestination.StartX,
pfDestination.StartZ,
pfDestination.EndX,
pfDestination.EndZ);
float headDistX = (pfDestination.EndX - pfDestination.StartX) / dist;
float headDistZ = (pfDestination.EndZ - pfDestination.StartZ) / dist;
newX -= headDistZ * 4;
newZ += headDistX * 4;
Coordinate destCoordinate = new Coordinate(newX, pfDestination.EndY, newZ);
((ICharacter)self).Teleport(
destCoordinate,
((ICharacter)self).Heading,
new Identity() { Type = IdentityType.Playfield, Instance = toPlayfield });
return true;
}
开发者ID:gordonc64,项目名称:CellAO-NightPredator,代码行数:50,代码来源:lineteleport.cs
示例17: 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,
INamedEntity caller,
IInstancedEntity target,
MessagePackObject[] arguments)
{
var temp = new UploadedNano() { NanoId = arguments[0].AsInt32() };
((Character)self).UploadedNanos.Add(temp);
UploadedNanosDao.WriteNano(((Character)self).Identity.Instance, temp);
var message = new CharacterActionMessage()
{
Identity = self.Identity,
Action = CharacterActionType.UploadNano,
Target = self.Identity,
Parameter1 = (int)IdentityType.NanoProgram,
Parameter2 = temp.NanoId,
Unknown = 0
};
((Character)self).Client.SendCompressed(message);
return true;
}
开发者ID:kittin,项目名称:CellAO-NightPredator,代码行数:35,代码来源:uploadnano.cs
示例18: 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,
INamedEntity caller,
IInstancedEntity target,
MessagePackObject[] arguments)
{
string text = arguments[0].AsString();
byte b = 0;
var message = new FormatFeedbackMessage()
{
Identity = self.Identity,
Message = text + (char)b,
Unknown1 = 0,
DataLength = (short)(text.Length + 0xf),
Unknown2 = 0x7e26,
Unknown3 = 0x21212122,
Unknown4 = 0x3a212121,
Unknown5 = 0x293C,
Unknown6 = 0x73,
Unknown7 = 0
};
((ICharacter)self).Send(message);
return true;
}
开发者ID:kittin,项目名称:CellAO-NightPredator,代码行数:36,代码来源:systemtext.cs
示例19: AssertNotEquals
private static void AssertNotEquals( MessagePackObject left, MessagePackObject right )
{
TestEqualsCore( left, right, false );
}
开发者ID:msgpack,项目名称:msgpack-cli,代码行数:4,代码来源:MessagePackObjectTest.Equals.cs
示例20: Reply
public void Reply( int? id, MessagePackObject message )
{
if ( id == null )
{
throw new ArgumentException( "id must be set.", "id" );
}
if ( this._context.AcceptSocket == null )
{
throw new InvalidOperationException();
}
using ( var buffer = GCChunkBuffer.CreateDefault() )
{
using ( RpcOutputBuffer rpcBuffer = SerializationUtility.SerializeResponse( id.Value, message ) )
{
var bytesToSend = rpcBuffer.ReadBytes().ToArray();
this._context.AcceptSocket.Send( bytesToSend );
}
}
}
开发者ID:yfakariya,项目名称:msgpack-rpc,代码行数:21,代码来源:ServerMockReceivedEventArgs.cs
注:本文中的MessagePackObject类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论