+ODBByteBuffer

pull/2/head
Harald Wolff 2019-10-07 08:59:05 +02:00
parent 66c996eb0c
commit 4cee7faffd
3 changed files with 63 additions and 0 deletions

View File

@ -125,6 +125,7 @@
<Compile Include="collections\WeakValueDictionary.cs" />
<Compile Include="test\WeakValueDictionaryTests.cs" />
<Compile Include="collections\WeakKeyReferenceDictionary.cs" />
<Compile Include="odb\values\ODBByteBuffer.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="odb\" />

View File

@ -0,0 +1,59 @@
// /**
// * File: ODBByteBuffer.cs
// * Author: haraldwolff
// *
// * This file and it's content is copyrighted by the Author and / or copyright holder.
// * Any use wihtout proper permission is illegal and may lead to legal actions.
// *
// *
// **/
using System;
namespace ln.types.odb.values
{
public class ODBByteBuffer : ODBValue
{
public byte[] GetBytes() => (byte[])Value;
public ODBByteBuffer(byte[] bytes)
: base(0x0800, bytes.Slice(0))
{
}
public override object As(Type targetType)
{
if (typeof(byte[]).Equals(targetType))
return GetBytes();
throw new InvalidCastException();
}
public override byte[] GetStorageBytes() => GetBytes();
protected override int compare(ODBEntity other)
{
ODBByteBuffer you = other as ODBByteBuffer;
byte[] myBytes = GetBytes();
byte[] yourBytes = you.GetBytes();
int dl = myBytes.Length - yourBytes.Length;
if (dl != 0)
return dl;
while (dl < myBytes.Length)
{
int d = myBytes[dl] - yourBytes[dl++];
if (d != 0)
return d;
}
return 0;
}
static ODBByteBuffer()
{
RegisterDeserializer(0x0800, (storageBytes, offset, length) => new ODBByteBuffer(storageBytes.Slice(offset, length)));
}
}
}

View File

@ -23,6 +23,8 @@ using System.Runtime.CompilerServices;
*
* 0x0020 ODBTypedMapping
*
* 0x0800 ODBByteBuffer
*
* 0x1000 ODBDocument
* 0x1001 Document (ln.types.odb.ng)
*
@ -208,6 +210,7 @@ namespace ln.types.odb.values
RuntimeHelpers.RunClassConstructor(typeof(ODBDouble).TypeHandle);
RuntimeHelpers.RunClassConstructor(typeof(ODBGuid).TypeHandle);
RuntimeHelpers.RunClassConstructor(typeof(ODBBool).TypeHandle);
RuntimeHelpers.RunClassConstructor(typeof(ODBByteBuffer).TypeHandle);
}
}
}