本文整理汇总了C#中Message.SetString方法的典型用法代码示例。如果您正苦于以下问题:C# Message.SetString方法的具体用法?C# Message.SetString怎么用?C# Message.SetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message.SetString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestEncodeMessageWithAllFieldTypes
public void TestEncodeMessageWithAllFieldTypes()
{
var template = new MessageTemplate(
"",
new Field[]
{
new Scalar("1", FastType.String, Operator.Copy, ScalarValue.Undefined, false),
new Scalar("2", FastType.ByteVector, Operator.Copy, ScalarValue.Undefined, false),
new Scalar("3", FastType.Decimal, Operator.Copy, ScalarValue.Undefined, false),
new Scalar("4", FastType.I32, Operator.Copy, ScalarValue.Undefined, false),
new Scalar("5", FastType.String, Operator.Copy, ScalarValue.Undefined, false),
new Scalar("6", FastType.U32, Operator.Copy, ScalarValue.Undefined, false),
});
var context = new Context();
context.RegisterTemplate(113, template);
var message = new Message(template);
message.SetString(1, "H");
message.SetByteVector(2, new[] {(byte) 0xFF});
message.SetDecimal(3, 1.201);
message.SetInteger(4, -1);
message.SetString(5, "abc");
message.SetInteger(6, 2);
// --PMAP-- --TID--- ---#1--- -------#2-------- ------------#3------------ ---#4--- ------------#5------------ ---#6---
const string msgstr =
"11111111 11110001 11001000 10000001 11111111 11111101 00001001 10110001 11111111 01100001 01100010 11100011 10000010";
AssertEquals(msgstr, new FastEncoder(context).Encode(message));
}
示例2: TestDecodeMessageWithAllFieldTypes
public void TestDecodeMessageWithAllFieldTypes()
{
// --PMAP-- --TID--- ---#1--- -------#2-------- ------------#3------------ ---#4--- ------------#5------------ ---#6---
const string msgstr =
"11111111 11110001 11001000 10000001 11111111 11111101 00001001 10110001 11111111 01100001 01100010 11100011 10000010";
Stream input = ByteUtil.CreateByteStream(msgstr);
var template = new MessageTemplate(
"",
new Field[]
{
new Scalar("1", FastType.Ascii, Operator.Copy, ScalarValue.Undefined, false),
new Scalar("2", FastType.ByteVector, Operator.Copy, ScalarValue.Undefined, false),
new Scalar("3", FastType.Decimal, Operator.Copy, ScalarValue.Undefined, false),
new Scalar("4", FastType.I32, Operator.Copy, ScalarValue.Undefined, false),
new Scalar("5", FastType.Ascii, Operator.Copy, ScalarValue.Undefined, false),
new Scalar("6", FastType.U32, Operator.Copy, ScalarValue.Undefined, false),
});
var context = new Context();
context.RegisterTemplate(113, template);
GroupValue message = new Message(template);
message.SetString(1, "H");
message.SetByteVector(2, new[] {(byte) 0xFF});
message.SetDecimal(3, 1.201);
message.SetInteger(4, -1);
message.SetString(5, "abc");
message.SetInteger(6, 2);
Assert.AreEqual(message, new FastDecoder(context, input).ReadMessage());
}
示例3: TestConversions
public void TestConversions()
{
MessageTemplate template = Template(
"<template>" +
" <string name='string'/>" +
" <uInt32 name='uint'/>" +
" <int8 name='byte'/>" +
" <int16 name='short'/>" +
" <int64 name='long'/>" +
" <byteVector name='bytevector'/>" +
" <decimal name='decimal'/>" +
"</template>");
var message = new Message(template);
message.SetByteVector("string", Byte("7f001a"));
message.SetDecimal("uint", 150.0);
message.SetString("byte", "4");
message.SetString("short", "-5");
message.SetString("long", "1000000000000000000");
message.SetString("bytevector", "abcd");
message.SetString("decimal", "2.3");
FastEncoder encoder = Encoder(template);
byte[] encoding = encoder.Encode(message);
FastDecoder decoder = Decoder(template, encoding);
Message decodedMessage = decoder.ReadMessage();
Assert.AreEqual(150, decodedMessage.GetInt("uint"));
Assert.AreEqual(150, decodedMessage.GetShort("uint"));
Assert.AreEqual(4, decodedMessage.GetByte("byte"));
Assert.AreEqual(-5, decodedMessage.GetShort("short"));
Assert.AreEqual(1000000000000000000L, decodedMessage.GetLong("long"));
}
示例4: TestDictionaryNotInherited
public void TestDictionaryNotInherited()
{
const string templateDef = "<template name='OptDeltaDec' id='58' dictionary='template'>" +
" <string name='desc'/>" +
" <decimal id='1' presence='optional' name='Line1'>" +
" <exponent><copy/></exponent>" +
" <mantissa><copy/></mantissa>" +
" </decimal>" +
" <decimal id='1' presence='optional' name='Line2'>" +
" <exponent><copy/></exponent>" +
" <mantissa><copy/></mantissa>" +
" </decimal> " +
" <decimal id='1' presence='optional' name='Line3'>" +
" <exponent><copy/></exponent> " +
" <mantissa><copy/></mantissa>" +
" </decimal>" +
"</template>";
MessageTemplate template = Template(templateDef);
var m = new Message(template);
m.SetString("desc", "prev");
m.SetDecimal("Line2", 9427.61);
m.SetDecimal("Line3", 9427.6);
byte[] bytes = Encoder(template).Encode(m);
Message m2 = Decoder(template, bytes).ReadMessage();
Assert.AreEqual(m, m2);
}
示例5: CreateOperator
public static GroupValue CreateOperator(Scalar scalar)
{
MessageTemplate operatorTemplate;
if (!OperatorTemplateMap.TryGetValue(scalar.Operator, out operatorTemplate))
return null;
GroupValue operatorMessage = new Message(operatorTemplate);
if (!scalar.Dictionary.Equals(DictionaryFields.Global))
operatorMessage.SetString("Dictionary", scalar.Dictionary);
if (!scalar.Key.Equals(scalar.QName))
{
Group key = operatorTemplate.GetGroup("Key");
var keyValue = new GroupValue(key);
keyValue.SetString("Name", scalar.Key.Name);
keyValue.SetString("Ns", scalar.Key.Namespace);
operatorMessage.SetFieldValue(key, keyValue);
}
return operatorMessage;
}
示例6: CreateHelloMessage
public static Message CreateHelloMessage(string name)
{
var message = new Message(HelloTemplate);
message.SetString(1, name);
return message;
}
示例7: CreateFastAlertMessage
public static Message CreateFastAlertMessage(DynError code)
{
ErrorInfoAttribute attr = code.GetErrorInfo();
var alert = new Message(AlertTemplate);
alert.SetInteger(1, (int) attr.Severity);
alert.SetInteger(2, (int) code);
alert.SetString(4, attr.Description);
return alert;
}
示例8: TestEncodeMessageWithStringFieldTypesAndAllOperators
public void TestEncodeMessageWithStringFieldTypesAndAllOperators()
{
var template = new MessageTemplate(
"",
new Field[]
{
new Scalar("1", FastType.String, Operator.Copy, ScalarValue.Undefined, false),
new Scalar("2", FastType.String, Operator.Delta, ScalarValue.Undefined, false),
new Scalar("3", FastType.String, Operator.Constant, new StringValue("e"), false),
/* NON-TRANSFERRABLE */
new Scalar("4", FastType.String, Operator.Default, new StringValue("long"), false)
});
var context = new Context();
context.RegisterTemplate(113, template);
var message = new Message(template);
message.SetString(1, "on");
message.SetString(2, "DCB32");
message.SetString(3, "e");
message.SetString(4, "long");
// --PMAP-- --TID--- --------#1------- ---------------------#2------------------------------
const string msg1 =
"11100000 11110001 01101111 11101110 10000000 01000100 01000011 01000010 00110011 10110010";
// --PMAP-- --------#2---------------- ---------------------#4---------------------
const string msg2 = "10010000 10000010 00110001 10110110 01110011 01101000 01101111 01110010 11110100";
var encoder = new FastEncoder(context);
AssertEquals(msg1, encoder.Encode(message));
message.SetString(2, "DCB16");
message.SetString(4, "short");
AssertEquals(msg2, encoder.Encode(message));
}
示例9: TestTailOperatorWithOptionalField
public void TestTailOperatorWithOptionalField()
{
var field = new Scalar("", FastType.String, Operator.Tail,
new StringValue("abc"), true);
MessageTemplate template = RegisterTemplate(field);
var msg1 = new Message(template);
msg1.SetString(1, "abc");
var msg2 = new Message(template);
msg2.SetString(1, "abd");
var msg3 = new Message(template);
var msg4 = new Message(template);
msg4.SetString(1, "dbef");
// --PMAP-- --TID---
EncodeAndAssertEquals("11000000 11110001", msg1);
// --PMAP-- ---#1---
EncodeAndAssertEquals("10100000 11100100", msg2);
// --PMAP-- ---#1---
EncodeAndAssertEquals("10100000 10000000", msg3);
// --PMAP-- -----------------#1----------------
EncodeAndAssertEquals("10100000 01100100 01100010 01100101 11100110",
msg4);
ReadMessageAndAssertEquals(msg1);
ReadMessageAndAssertEquals(msg2);
ReadMessageAndAssertEquals(msg3);
ReadMessageAndAssertEquals(msg4);
}
示例10: SetUp
protected void SetUp()
{
_nameTemplate = Template("<template>" +
" <string name='name'/>" +
"</template>");
_template = Template("<template>" +
" <uInt32 name='quantity'/>" +
" <templateRef/>" +
" <decimal name='price'/>" +
"</template>");
_message = new Message(_template);
_message.SetInteger(1, 15);
_message.SetDecimal(3, 102.0);
_name = new Message(_nameTemplate);
_name.SetString(1, "IBM");
_message.SetFieldValue(2, _name);
_context = new Context();
_context.RegisterTemplate(1, _template);
_context.RegisterTemplate(2, _nameTemplate);
}
示例11: TestDecodeMessageWithStringFieldTypesAndAllOperators
public void TestDecodeMessageWithStringFieldTypesAndAllOperators()
{
var template = new MessageTemplate(
"",
new Field[]
{
new Scalar("1", FastType.Ascii, Operator.Copy, ScalarValue.Undefined, false),
new Scalar("2", FastType.Ascii, Operator.Delta, ScalarValue.Undefined, false),
new Scalar("3", FastType.Ascii, Operator.Constant, new StringValue("e"), false),
/* NON-TRANSFERRABLE */
new Scalar("4", FastType.Ascii, Operator.Default, new StringValue("long"), false)
});
var message = new Message(template);
message.SetString(1, "on");
message.SetString(2, "DCB32");
message.SetString(3, "e");
message.SetString(4, "long");
// --PMAP-- --TID--- --------#1------- ---------------------#2---------------------
const string msg1 =
"11100000 11110001 01101111 11101110 10000000 01000100 01000011 01000010 00110011 10110010";
// --PMAP-- ------------#2------------ ---------------------#4---------------------
const string msg2 = "10010000 10000010 00110001 10110110 01110011 01101000 01101111 01110010 11110100";
Stream input = ByteUtil.CreateByteStream(msg1 + ' ' + msg2);
var context = new Context();
context.RegisterTemplate(113, template);
var decoder = new FastDecoder(context, input);
Message readMessage = decoder.ReadMessage();
Assert.AreEqual(message, readMessage);
message.SetString(2, "DCB16");
message.SetString(4, "short");
readMessage = decoder.ReadMessage();
Assert.AreEqual(message, readMessage);
}
示例12: CreateHelloMessage
public static Message CreateHelloMessage(string name)
{
var message = new Message(FAST_HELLO_TEMPLATE);
message.SetString(1, name);
return message;
}
示例13: CreateFastAlertMessage
public static Message CreateFastAlertMessage(ErrorCode code)
{
var alert = new Message(FAST_ALERT_TEMPLATE);
alert.SetInteger(1, code.Severity.Code);
alert.SetInteger(2, code.Code);
alert.SetString(4, code.Description);
return alert;
}
示例14: CreateOperator
public static GroupValue CreateOperator(Scalar scalar)
{
if (!OPERATOR_TEMPLATE_MAP.Contains(scalar.Operator))
return null;
var operatorTemplate = (MessageTemplate) OPERATOR_TEMPLATE_MAP[scalar.Operator];
GroupValue operatorMessage = new Message(operatorTemplate);
if (!scalar.Dictionary.Equals(Dictionary_Fields.GLOBAL))
operatorMessage.SetString("Dictionary", scalar.Dictionary);
if (!scalar.Key.Equals(scalar.QName))
{
var key = operatorTemplate.GetGroup("Key");
var keyValue = new GroupValue(key);
keyValue.SetString("Name", scalar.Key.Name);
keyValue.SetString("Ns", scalar.Key.Namespace);
operatorMessage.SetFieldValue(key, keyValue);
}
return operatorMessage;
}
示例15: CreateHelloMessage
public virtual Message CreateHelloMessage(string senderName)
{
var message = new Message(FAST_HELLO_TEMPLATE);
message.SetString(1, senderName);
message.SetString(2, SessionConstants.VENDOR_ID);
return message;
}