本文整理汇总了C#中ByteString类的典型用法代码示例。如果您正苦于以下问题:C# ByteString类的具体用法?C# ByteString怎么用?C# ByteString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ByteString类属于命名空间,在下文中一共展示了ByteString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PopFollowingResponse
internal PopFollowingResponse(ByteString text)
{
if (text == null)
throw new ArgumentNullException("text");
this.Text = text;
}
示例2: attachSignature
/**
* Method attaches a signature (captured) from the UI to a successfully executed transaction
*/
public EzeResult attachSignature(string txnId, ImageType imageType, ByteString imageData, int height, int width, double tipAmount)
{
Console.Error.WriteLine("...attachSignature <" + txnId + ">");
SignatureInput signatureInput = SignatureInput.CreateBuilder()
.SetTxnId(txnId)
.SetImageType(MapImageType(imageType))
.SetImageBytes(imageData)
.SetHeight(height)
.SetWidth(width)
.SetTipAmount(tipAmount)
.Build();
ApiInput apiInput = ApiInput.CreateBuilder()
.SetMsgType(ApiInput.Types.MessageType.ATTACH_SIGNATURE)
.SetMsgData(signatureInput.ToByteString()).Build();
this.send(apiInput);
EzeResult result = null;
while (true)
{
result = this.getResult(this.receive());
if (result.getEventName() == EventName.ATTACH_SIGNATURE) break;
}
return result;
}
示例3: ToDropListing
public static PopDropListing ToDropListing(ByteString[] texts)
{
ThrowIfTooFewTexts(texts, 2);
return new PopDropListing(ToNumber(texts[0]),
ToNumber(texts[1]));
}
示例4: Exchange
protected override SaslExchangeStatus Exchange(ByteString serverChallenge, out ByteString clientResponse)
{
if (Credential == null)
throw new SaslException("Credential property must be set");
clientResponse = null;
switch (step /* challenge */) {
case 0: /* case "Username:": */
if (string.IsNullOrEmpty(Credential.UserName))
return SaslExchangeStatus.Failed;
step++;
clientResponse = new ByteString(Credential.UserName);
return SaslExchangeStatus.Continuing;
case 1: /* case "Password:": */
if (string.IsNullOrEmpty(Credential.Password))
return SaslExchangeStatus.Failed;
step++;
clientResponse = new ByteString(Credential.Password);
return SaslExchangeStatus.Succeeded;
default: // unexpected server challenge
clientResponse = null;
return SaslExchangeStatus.Failed;
}
}
示例5: GetRecordVersion
public static async Task<Record> GetRecordVersion(this ILedgerQueries queries, ByteString key, ByteString version)
{
if (version.Value.Count == 0)
{
return new Record(key, ByteString.Empty, ByteString.Empty);
}
else
{
ByteString rawTransaction = await queries.GetTransaction(version);
if (rawTransaction == null)
{
return null;
}
else
{
Transaction transaction = MessageSerializer.DeserializeTransaction(rawTransaction);
Mutation mutation = MessageSerializer.DeserializeMutation(transaction.Mutation);
Record result = mutation.Records.FirstOrDefault(record => record.Key.Equals(key) && record.Value != null);
if (result == null)
return null;
else
return result;
}
}
}
示例6: Mutation
/// <summary>
/// Initializes a new instance of the <see cref="Mutation"/> class.
/// </summary>
/// <param name="@namespace">The namespace in which the mutation operates.</param>
/// <param name="records">A collection of all the records affected by the mutation.</param>
/// <param name="metadata">The metadata associated with the mutation.</param>
public Mutation(ByteString @namespace, IEnumerable<Record> records, ByteString metadata)
{
if (@namespace == null)
throw new ArgumentNullException(nameof(@namespace));
if (records == null)
throw new ArgumentNullException(nameof(records));
if (metadata == null)
throw new ArgumentNullException(nameof(metadata));
this.Namespace = @namespace;
this.Records = records.ToList().AsReadOnly();
this.Metadata = metadata;
// Records must not be null
if (this.Records.Any(entry => entry == null))
throw new ArgumentNullException(nameof(records));
// There must not be any duplicate keys
HashSet<ByteString> keys = new HashSet<ByteString>();
foreach (Record record in this.Records)
{
if (keys.Contains(record.Key))
throw new ArgumentNullException(nameof(records));
keys.Add(record.Key);
}
}
示例7: ToArray_Success
public void ToArray_Success()
{
byte[] sourceArray = new byte[] { 18, 178, 255, 70, 0 };
ByteString result = new ByteString(sourceArray);
Assert.Equal<byte>(new byte[] { 18, 178, 255, 70, 0 }, result.ToByteArray());
}
示例8: Exchange
protected override SaslExchangeStatus Exchange(ByteString serverChallenge, out ByteString clientResponse)
{
// 2. The Anonymous Mechanism
// The mechanism consists of a single message from the client to the
// server. The client may include in this message trace information in
// the form of a string of [UTF-8]-encoded [Unicode] characters prepared
// in accordance with [StringPrep] and the "trace" stringprep profile
// defined in Section 3 of this document. The trace information, which
// has no semantical value, should take one of two forms: an Internet
// email address, or an opaque string that does not contain the '@'
// (U+0040) character and that can be interpreted by the system
// administrator of the client's domain. For privacy reasons, an
// Internet email address or other information identifying the user
// should only be used with permission from the user.
if (Credential == null)
throw new SaslException("Credential property must be set");
clientResponse = null;
if (string.IsNullOrEmpty(Credential.UserName))
return SaslExchangeStatus.Failed;
// XXX
clientResponse = new ByteString(Encoding.UTF8.GetBytes(Credential.UserName));
return SaslExchangeStatus.Succeeded;
}
示例9: OutboundTransaction
public OutboundTransaction(ByteString recordKey, long amount, ByteString version, string target)
{
this.RecordKey = recordKey;
this.Amount = amount;
this.Version = version;
this.Target = target;
}
示例10: PostTransaction
public async Task<ByteString> PostTransaction(ByteString rawMutation, IReadOnlyList<SignatureEvidence> authentication)
{
Mutation mutation;
try
{
// Verify that the mutation can be deserialized
mutation = MessageSerializer.DeserializeMutation(rawMutation);
}
catch (InvalidProtocolBufferException)
{
throw new TransactionInvalidException("InvalidMutation");
}
if (!mutation.Namespace.Equals(this.ledgerId))
throw new TransactionInvalidException("InvalidNamespace");
if (mutation.Records.Count == 0)
throw new TransactionInvalidException("InvalidMutation");
if (mutation.Records.Any(record => record.Key.Value.Count > MaxKeySize))
throw new TransactionInvalidException("InvalidMutation");
ValidateAuthentication(authentication, MessageSerializer.ComputeHash(rawMutation.ToByteArray()));
ParsedMutation parsedMutation = ParsedMutation.Parse(mutation);
// All assets must have an overall zero balance
IReadOnlyDictionary<AccountKey, AccountStatus> accounts =
await this.store.GetAccounts(parsedMutation.AccountMutations.Select(entry => entry.AccountKey));
var groups = parsedMutation.AccountMutations
.GroupBy(account => account.AccountKey.Asset.FullPath)
.Select(group => group.Sum(entry => entry.Balance - accounts[entry.AccountKey].Balance));
if (groups.Any(group => group != 0))
throw new TransactionInvalidException("UnbalancedTransaction");
DateTime date = DateTime.UtcNow;
await this.validator.Validate(parsedMutation, authentication, accounts);
TransactionMetadata metadata = new TransactionMetadata(authentication);
byte[] rawMetadata = SerializeMetadata(metadata);
Transaction transaction = new Transaction(rawMutation, date, new ByteString(rawMetadata));
byte[] serializedTransaction = MessageSerializer.SerializeTransaction(transaction);
try
{
await this.store.AddTransactions(new[] { new ByteString(serializedTransaction) });
}
catch (ConcurrentMutationException)
{
throw new TransactionInvalidException("OptimisticConcurrency");
}
return new ByteString(MessageSerializer.ComputeHash(serializedTransaction));
}
示例11: ParseFrom
/// <summary>
/// Parses a message from the given byte string.
/// </summary>
/// <param name="data">The data to parse.</param>
/// <returns>The parsed message.</returns>
public IMessage ParseFrom(ByteString data)
{
Preconditions.CheckNotNull(data, "data");
IMessage message = factory();
message.MergeFrom(data);
return message;
}
示例12: UnknownFieldSetTest
public UnknownFieldSetTest()
{
descriptor = TestAllTypes.Descriptor;
allFields = TestUtil.GetAllSet();
allFieldsData = allFields.ToByteString();
emptyMessage = TestEmptyMessage.ParseFrom(allFieldsData);
unknownFields = emptyMessage.UnknownFields;
}
示例13: MergeFrom
/// <summary>
/// Merges data from the given byte string into an existing message.
/// </summary>
/// <param name="message">The message to merge the data into.</param>
/// <param name="data">The data to merge, which must be protobuf-encoded binary data.</param>
public static void MergeFrom(this IMessage message, ByteString data)
{
ProtoPreconditions.CheckNotNull(message, "message");
ProtoPreconditions.CheckNotNull(data, "data");
CodedInputStream input = data.CreateCodedInput();
message.MergeFrom(input);
input.CheckReadEndOfStreamTag();
}
示例14: TestContains
public void TestContains()
{
var str = new ByteString("ababdabdbdabcab");
Assert.IsTrue(str.Contains(new ByteString("abc")));
Assert.IsTrue(str.Contains(new ByteString("abd")));
Assert.IsFalse(str.Contains(new ByteString("abe")));
}
示例15: TestConstructFromString
public void TestConstructFromString()
{
var s = new ByteString("abc");
Assert.IsFalse(s.IsEmpty);
Assert.AreEqual(3, s.Length);
Assert.AreEqual(new byte[] {0x61, 0x62, 0x63}, s.ByteArray);
}