Example #1
0
        public static ImmutableBytes WriteByte(
            ImmutableBytes bytes,
            ByteAddress address,
            byte value)
        {
            if (address.IsOutOfRange(bytes.Size))
            {
                throw new InvalidOperationException("out of range");
            }

            return(new ImmutableBytes(bytes.OriginalBytes, bytes.Edits.Add(address.Value, value)));
        }
Example #2
0
        public byte ReadByte(ByteAddress address)
        {
            var dynamicSize = DynamicMemory.Size;

            if (address.IsInRange(dynamicSize))
            {
                return(ImmutableBytes.ReadByte(DynamicMemory, address));
            }

            var staticAddress = address.DecrementBy(dynamicSize);

            return(staticAddress.DereferenceBytes(StaticMemory));
        }
Example #3
0
        public static byte ReadByte(ImmutableBytes bytes, ByteAddress address)
        {
            if (address.IsOutOfRange(bytes.Size))
            {
                throw new InvalidOperationException("out of range");
            }

            if (bytes.Edits.TryGetValue(address.Value, out var recordedEdit))
            {
                return(recordedEdit);
            }

            return(bytes.OriginalBytes[address.Value]);
        }
Example #4
0
        public Story WriteByte(ByteAddress address, byte value)
        {
            var dynamicMemory = ImmutableBytes.WriteByte(DynamicMemory, address, value);

            return(new Story(dynamicMemory, StaticMemory));
        }
Example #5
0
 private Story(ImmutableBytes dynamicMemory, ImmutableArray <byte> staticMemory)
 {
     DynamicMemory = dynamicMemory;
     StaticMemory  = staticMemory;
 }
Example #6
0
 private Story(byte[] dynamicBytes, byte[] staticBytes)
 {
     DynamicMemory = ImmutableBytes.Create(dynamicBytes);
     StaticMemory  = ImmutableArray.Create(staticBytes);
 }