• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ByteString类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ByteString的典型用法代码示例。如果您正苦于以下问题:C# ByteString类的具体用法?C# ByteString怎么用?C# ByteString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ByteString类属于命名空间,在下文中一共展示了ByteString类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: DecodeEscapedString

 public string DecodeEscapedString(int end, int skip, Encoding encoding)
 {
     if(CheckValue('\"'))
     {
         var sb = new StringBuilder(end - Position);
         ByteString bs = null;
         var bytes = new byte[end - Position + 1];
         Skip();
         while(Position < end)
         {
             var c = ReadChar();
             if(c == '\\')
             {
                 var nc = CurrentChar;
                 if(nc.IsOctDigit())
                 {
                     if(bs == null)
                     {
                         var bufferSize = end - Position;
                         if(bufferSize < 1) bufferSize = 1;
                         bs = new ByteString(end - Position);
                     }
                     int len = 1;
                     int start = Position;
                     Skip();
                     while(CurrentChar.IsOctDigit())
                     {
                         Skip();
                         ++len;
                     }
                     bs.AppendByte(ByteFromOctString(String, start, len));
                 }
                 else
                 {
                     ByteString.Dump(bs, sb, encoding);
                     HandleEscapeCode(sb, nc);
                     Skip();
                 }
             }
             else if(c == '\"')
             {
                 ByteString.Dump(bs, sb, encoding);
                 break;
             }
             else
             {
                 ByteString.Dump(bs, sb, encoding);
                 sb.Append(c);
             }
         }
         Position = end + skip;
         return sb.ToString();
     }
     else
     {
         return ReadStringUpTo(end, skip);
     }
 }
开发者ID:Kuzq,项目名称:gitter,代码行数:58,代码来源:GitParser.cs


示例17: Parse_Data

        public void Parse_Data()
        {
            ByteString data = new ByteString(Encoding.UTF8.GetBytes("/aka/name/:DATA:record:name"));
            RecordKey key = RecordKey.Parse(data);

            Assert.Equal(RecordType.Data, key.RecordType);
            Assert.Equal("/aka/name/", key.Path.FullPath);
            Assert.Equal("record:name", key.Name);
        }
开发者ID:hellwolf,项目名称:openchain,代码行数:9,代码来源:RecordKeyTests.cs


示例18: GetRecordMutations

 public async Task<IReadOnlyList<ByteString>> GetRecordMutations(ByteString recordKey)
 {
     var key = recordKey.ToByteArray();
     var res = await TransactionCollection.Find(Builders<MongoDbTransaction>.Filter.AnyEq(x=>x.Records, key))
         .Project(x=>x.MutationHash)
         .SortBy(x=>x.Timestamp)
         .ToListAsync();
     return res.Select(x=>new ByteString(x)).ToList().AsReadOnly();
 }
开发者ID:Flavien,项目名称:mongodb-storage,代码行数:9,代码来源:MongoDbLedger.cs


示例19: ToMessageNumber

        public static long ToMessageNumber(ByteString text)
        {
            var val = ToNumber(text);

              if (val == 0L)
            throw new PopMalformedTextException(string.Format("must be non-zero positive number, but was {0}", val));

              return val;
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:9,代码来源:PopTextConverter.cs


示例20: Parse_Account

        public void Parse_Account()
        {
            ByteString data = new ByteString(Encoding.UTF8.GetBytes("/account/name/:ACC:/asset/name/"));
            RecordKey key = RecordKey.Parse(data);

            Assert.Equal(RecordType.Account, key.RecordType);
            Assert.Equal("/account/name/", key.Path.FullPath);
            Assert.Equal("/asset/name/", key.Name);
        }
开发者ID:hellwolf,项目名称:openchain,代码行数:9,代码来源:RecordKeyTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ByteVector类代码示例发布时间:2022-05-24
下一篇:
C# ByteReader类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap