当前位置: 首页>>代码示例>>C#>>正文


C# ByteString类代码示例

本文整理汇总了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;
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:7,代码来源:PopFollowingResponse.cs

示例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;
        }
开发者ID:ezetap,项目名称:client-sdk-win-dotnet,代码行数:30,代码来源:EzeAPI.cs

示例3: ToDropListing

        public static PopDropListing ToDropListing(ByteString[] texts)
        {
            ThrowIfTooFewTexts(texts, 2);

              return new PopDropListing(ToNumber(texts[0]),
                                ToNumber(texts[1]));
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:7,代码来源:PopTextConverter.cs

示例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;
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:29,代码来源:LoginMechanism.cs

示例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;
                }
            }
        }
开发者ID:packetlost,项目名称:openchain,代码行数:28,代码来源:LedgerQueriesExtensions.cs

示例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);
            }
        }
开发者ID:juanfranblanco,项目名称:openchain,代码行数:35,代码来源:Mutation.cs

示例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());
        }
开发者ID:hellwolf,项目名称:openchain,代码行数:7,代码来源:ByteStringTests.cs

示例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;
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:27,代码来源:AnonymousMechanism.cs

示例9: OutboundTransaction

 public OutboundTransaction(ByteString recordKey, long amount, ByteString version, string target)
 {
     this.RecordKey = recordKey;
     this.Amount = amount;
     this.Version = version;
     this.Target = target;
 }
开发者ID:openchain,项目名称:sidechain,代码行数:7,代码来源:OutboundTransaction.cs

示例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));
        }
开发者ID:packetlost,项目名称:openchain,代码行数:60,代码来源:TransactionValidator.cs

示例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;
 }
开发者ID:JeckyOH,项目名称:protobuf,代码行数:12,代码来源:MessageParser.cs

示例12: UnknownFieldSetTest

 public UnknownFieldSetTest()
 {
     descriptor = TestAllTypes.Descriptor;
     allFields = TestUtil.GetAllSet();
     allFieldsData = allFields.ToByteString();
     emptyMessage = TestEmptyMessage.ParseFrom(allFieldsData);
     unknownFields = emptyMessage.UnknownFields;
 }
开发者ID:JuWell,项目名称:SmallNetGame,代码行数:8,代码来源:UnknownFieldSetTest.cs

示例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();
 }
开发者ID:2php,项目名称:protobuf,代码行数:13,代码来源:MessageExtensions.cs

示例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")));
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:8,代码来源:ByteString.cs

示例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);
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:8,代码来源:ByteString.cs


注:本文中的ByteString类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。