Exemple #1
0
    public void Setup()
    {
        const int ItemCount = 16;

        using var message = new SecsMessage(s: 1, f: 2, replyExpected: false)
              {
                  SecsItem = L(
                      L(),
                      U1(MemoryOwner <byte> .Allocate(ItemCount)),
                      U2(MemoryOwner <ushort> .Allocate(ItemCount)),
                      U4(MemoryOwner <uint> .Allocate(ItemCount)),
                      F4(MemoryOwner <float> .Allocate(ItemCount)),
                      A(CreateString(ItemCount, Encoding.ASCII)),
                      J(CreateString(ItemCount, Item.Jis8Encoding)),
                      F8(MemoryOwner <double> .Allocate(ItemCount)),
                      L(
                          I1(MemoryOwner <sbyte> .Allocate(ItemCount)),
                          I2(MemoryOwner <short> .Allocate(ItemCount)),
                          I4(MemoryOwner <int> .Allocate(ItemCount)),
                          F4(MemoryOwner <float> .Allocate(ItemCount)),
                          L(
                              I1(MemoryOwner <sbyte> .Allocate(ItemCount)),
                              I2(MemoryOwner <short> .Allocate(ItemCount)),
                              I4(MemoryOwner <int> .Allocate(ItemCount)),
                              F4(MemoryOwner <float> .Allocate(ItemCount)),
                              Boolean(MemoryOwner <bool> .Allocate(ItemCount)),
                              B(MemoryOwner <byte> .Allocate(ItemCount)),
                              L(
                                  A(CreateString(ItemCount, Encoding.ASCII)),
                                  J(CreateString(ItemCount, Item.Jis8Encoding)),
                                  Boolean(MemoryOwner <bool> .Allocate(ItemCount)),
                                  B(MemoryOwner <byte> .Allocate(ItemCount))),
                              F8(MemoryOwner <double> .Allocate(ItemCount))),
                          Boolean(MemoryOwner <bool> .Allocate(ItemCount)),
                          B(MemoryOwner <byte> .Allocate(ItemCount)),
                          L(
                              A(CreateString(ItemCount, Encoding.ASCII)),
                              J(CreateString(ItemCount, Item.Jis8Encoding)),
                              Boolean(MemoryOwner <bool> .Allocate(ItemCount)),
                              B(MemoryOwner <byte> .Allocate(ItemCount))),
                          F8(MemoryOwner <double> .Allocate(ItemCount))),
                      U1(MemoryOwner <byte> .Allocate(ItemCount)),
                      U2(MemoryOwner <ushort> .Allocate(ItemCount)),
                      U4(MemoryOwner <uint> .Allocate(ItemCount)),
                      F4(MemoryOwner <float> .Allocate(ItemCount))),
              };

        using var buffer = new ArrayPoolBufferWriter <byte>();

        for (var i = 0; i < MessageCount; i++)
        {
            SecsGem.EncodeMessage(message, 1000 + i, deviceId: 0, buffer);
        }

        _encodedBytes = buffer.WrittenSpan.ToArray().Chunk(InputChunkSize).ToArray();