本文整理汇总了C#中Parameters.SetBoolean方法的典型用法代码示例。如果您正苦于以下问题:C# Parameters.SetBoolean方法的具体用法?C# Parameters.SetBoolean怎么用?C# Parameters.SetBoolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parameters
的用法示例。
在下文中一共展示了Parameters.SetBoolean方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: deserializeFromBytes
private static void deserializeFromBytes(Parameters parameters,
ByteIterator bytes)
{
int numOfEntries = consumeInt(bytes);
for(int i = 0; i != numOfEntries; ++i)
{
string entryName = consumeString(bytes);
int typeCode = consumeInt(bytes);
Parameters.EntryType type = codeToType(typeCode);
switch(type)
{
case Parameters.EntryType.BOOLEAN:
{
int value = consumeInt(bytes);
parameters.SetBoolean(entryName, value != 0);
}
break;
case Parameters.EntryType.INTEGER:
{
int value = consumeInt(bytes);
parameters.SetInteger(entryName, value);
}
break;
case Parameters.EntryType.LONG:
{
long value = consumeLong(bytes);
parameters.SetLong(entryName, value);
}
break;
case Parameters.EntryType.DOUBLE:
{
double value = consumeDouble(bytes);
parameters.SetDouble(entryName, value);
}
break;
case Parameters.EntryType.STRING:
{
string value = consumeString(bytes);
parameters.SetString(entryName, value);
}
break;
case Parameters.EntryType.BINARY:
{
byte[] value = consumeBinary(bytes);
parameters.SetBinary(entryName, value);
}
break;
case Parameters.EntryType.BOOLEAN_ARRAY:
{
int arrayLength = consumeInt(bytes);
int bytesNeeded =
(arrayLength + BITS_IN_BYTE - 1)
/ BITS_IN_BYTE;
byte[] packedArray =
consumeBytes(bytes, bytesNeeded);
bool[] array = new bool[arrayLength];
for(int j = 0; j != arrayLength; ++j)
{
int bytePosition = j / BITS_IN_BYTE;
int bitPosition = j % BITS_IN_BYTE;
int mask = 1 << bitPosition;
if((packedArray[bytePosition] & mask) != 0)
{
array[j] = true;
}
}
parameters.SetBooleanArray(entryName, array);
}
break;
case Parameters.EntryType.INTEGER_ARRAY:
{
int arrayLength = consumeInt(bytes);
int[] array = new int[arrayLength];
for(int j = 0; j != arrayLength; ++j)
{
array[j] = consumeInt(bytes);
}
parameters.SetIntegerArray(entryName, array);
}
break;
case Parameters.EntryType.LONG_ARRAY:
{
int arrayLength = consumeInt(bytes);
long[] array = new long[arrayLength];
for(int j = 0; j != arrayLength; ++j)
{
array[j] = consumeLong(bytes);
}
parameters.SetLongArray(entryName, array);
}
break;
case Parameters.EntryType.DOUBLE_ARRAY:
{
int arrayLength = consumeInt(bytes);
double[] array = new double[arrayLength];
for(int j = 0; j != arrayLength; ++j)
//.........这里部分代码省略.........
示例2: testRawBinary
public void testRawBinary()
{
bool gotMessage = false;
Encoding encoding = Encoding.UTF8;
byte[] messageContent =
encoding.GetBytes("Hello this is raw binary message");
byte[] replyContent =
encoding.GetBytes("Hi and this is raw binary response !");
Parameters options = new Parameters();
options.SetBoolean(OptionNames.DELIVER_AS_RAW_BINARY, true);
Agent rawServerAgent = new Agent(options);
string rawServerAddress =
rawServerAgent.AddListener("tcp://*:*");
Agent rawClientAgent = new Agent(options);
rawServerAgent.RegisterObject(objectName,
delegate(object sender, IncomingMessageArgs args)
{
gotMessage = true;
byte[] content = args.Message.RawContent;
Assert.AreEqual(messageContent, content);
args.Message.Reply(
new RawBinaryDataSource(replyContent));
});
OutgoingMessage message = rawClientAgent.Send(
rawServerAddress, objectName, messageName,
new RawBinaryDataSource(messageContent));
message.WaitForCompletion();
Assert.IsTrue(gotMessage);
Assert.AreEqual(
OutgoingMessage.MessageState.REPLIED, message.State);
byte[] reply = message.RawReply;
Assert.AreEqual(replyContent, reply);
message.Close();
rawClientAgent.Close();
rawServerAgent.Close();
}