Exemplo n.º 1
0
 // TODO: option to use byte array as a segment itself (add either a dispose callback or wrapper type)
 // TODO: overloads for ArraySegment, other memory types?
 public Data(Message msg, byte[] data)
 {
     _bytes = new FlatArray <byte>(msg, data.Length, out _);
     Unsafe.CopyBlockUnaligned(
         ref Unsafe.As <ulong, byte>(ref _bytes.Pointer.Data),
         ref data[0],
         (uint)data.Length);
 }
Exemplo n.º 2
0
        public static bool Is(this FlatArray <byte> flatArray, out ArraySegment <byte> arraySegment)
        {
            if (flatArray.Segment.Is(out arraySegment))
            {
                arraySegment = new ArraySegment <byte>(
                    arraySegment.Array,
                    arraySegment.Offset + flatArray.Pointer.DataOffset * sizeof(ulong),
                    flatArray.Count);
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        public Text(Message msg, string str)
        {
            var byteCount = Encoding.UTF8.GetByteCount(str) + 1;

            _bytes = new FlatArray <byte>(msg, byteCount, out AllocationContext allocContext);

            var absPointer = _bytes.Pointer;
            var segment    = absPointer.Segment;

            if (segment.Is(out ArraySegment <byte> arrSeg))
            {
                var writeOffset = arrSeg.Offset + absPointer.DataOffset * sizeof(ulong);
                Encoding.UTF8.GetBytes(str, 0, str.Length, arrSeg.Array, writeOffset);
                arrSeg.Array[writeOffset + byteCount - 1] = 0; // null terminator
            }
#if UNSAFE
            else if (segment.IsFixedMemory)
            {
                unsafe
                {
                    fixed(char *chars = str)
                    {
                        var ptr = (byte *)Unsafe.AsPointer(ref absPointer.Data);

                        Encoding.UTF8.GetBytes(chars, str.Length, ptr, byteCount - 1);
                        ptr[byteCount - 1] = 0;
                    }
                }
            }
#endif
            else
            {
                // TODO: ask for pin
                throw new NotImplementedException();
            }
        }
Exemplo n.º 4
0
 public Text(Segment segment, int baseWordOffset, ListPointer listPointer)
 {
     TypeHelpers.AssertSize <byte>(listPointer.ElementSize);
     _bytes = new FlatArray <byte>(new AbsPointer(segment, baseWordOffset, listPointer));
 }
Exemplo n.º 5
0
 public Text(Message msg, int bytesWithNulTerminator, out AllocationContext allocContext)
 {
     _bytes = new FlatArray <byte>(msg, bytesWithNulTerminator, out allocContext);
 }
Exemplo n.º 6
0
 public Data(Message msg, Stream stream)
 {
     _bytes = new FlatArray <byte>(msg, (int)stream.Length, out _);
     stream.CopyTo(this.GetStream());
 }
Exemplo n.º 7
0
 public Data(Message msg, int length, out AllocationContext allocContext)
 {
     _bytes = new FlatArray <byte>(msg, length, out allocContext);
 }
Exemplo n.º 8
0
 public Data(AbsPointer pointer)
 {
     _bytes = new FlatArray <byte>(pointer);
 }