Initial Commit (broken due to version update)
This commit is contained in:
parent
74003df84b
commit
3f7b3b7440
3132 changed files with 1103305 additions and 0 deletions
277
Assets/Scripts/MessagePack/Internal/AsymmetricKeyHashTable.cs
Normal file
277
Assets/Scripts/MessagePack/Internal/AsymmetricKeyHashTable.cs
Normal file
|
|
@ -0,0 +1,277 @@
|
|||
#if NETSTANDARD
|
||||
|
||||
using System;
|
||||
|
||||
namespace MessagePack.Internal
|
||||
{
|
||||
// Safe for multiple-read, single-write.
|
||||
|
||||
// Add and Get Key is asymmetric.
|
||||
|
||||
internal interface IAsymmetricEqualityComparer<TKey1, TKey2>
|
||||
{
|
||||
int GetHashCode(TKey1 key1);
|
||||
int GetHashCode(TKey2 key2);
|
||||
bool Equals(TKey1 x, TKey1 y); // when used rehash
|
||||
bool Equals(TKey1 x, TKey2 y); // when used get
|
||||
}
|
||||
|
||||
internal class StringArraySegmentByteAscymmetricEqualityComparer : IAsymmetricEqualityComparer<byte[], ArraySegment<byte>>
|
||||
{
|
||||
static readonly bool Is32Bit = (IntPtr.Size == 4);
|
||||
|
||||
public bool Equals(byte[] x, byte[] y)
|
||||
{
|
||||
if (x.Length != y.Length) return false;
|
||||
|
||||
for (int i = 0; i < x.Length; i++)
|
||||
{
|
||||
if (x[i] != y[i]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Equals(byte[] x, ArraySegment<byte> y)
|
||||
{
|
||||
return ByteArrayComparer.Equals(y.Array, y.Offset, y.Count, x);
|
||||
}
|
||||
|
||||
public int GetHashCode(byte[] key1)
|
||||
{
|
||||
return GetHashCode(new ArraySegment<byte>(key1, 0, key1.Length));
|
||||
}
|
||||
|
||||
public int GetHashCode(ArraySegment<byte> key2)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
if (Is32Bit)
|
||||
{
|
||||
return (int)FarmHash.Hash32(key2.Array, key2.Offset, key2.Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (int)FarmHash.Hash64(key2.Array, key2.Offset, key2.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class AsymmetricKeyHashTable<TKey1, TKey2, TValue>
|
||||
{
|
||||
Entry[] buckets;
|
||||
int size; // only use in writer lock
|
||||
|
||||
readonly object writerLock = new object();
|
||||
readonly float loadFactor;
|
||||
readonly IAsymmetricEqualityComparer<TKey1, TKey2> comparer;
|
||||
|
||||
public AsymmetricKeyHashTable(IAsymmetricEqualityComparer<TKey1, TKey2> comparer)
|
||||
: this(4, 0.72f, comparer)
|
||||
{
|
||||
}
|
||||
|
||||
public AsymmetricKeyHashTable(int capacity, float loadFactor, IAsymmetricEqualityComparer<TKey1, TKey2> comparer)
|
||||
{
|
||||
var tableSize = CalculateCapacity(capacity, loadFactor);
|
||||
this.buckets = new Entry[tableSize];
|
||||
this.loadFactor = loadFactor;
|
||||
this.comparer = comparer;
|
||||
}
|
||||
|
||||
public TValue AddOrGet(TKey1 key1, Func<TKey1, TValue> valueFactory)
|
||||
{
|
||||
TValue v;
|
||||
TryAddInternal(key1, valueFactory, out v);
|
||||
return v;
|
||||
}
|
||||
|
||||
public bool TryAdd(TKey1 key, TValue value)
|
||||
{
|
||||
return TryAdd(key, _ => value); // closure capture
|
||||
}
|
||||
|
||||
public bool TryAdd(TKey1 key, Func<TKey1, TValue> valueFactory)
|
||||
{
|
||||
TValue _;
|
||||
return TryAddInternal(key, valueFactory, out _);
|
||||
}
|
||||
|
||||
bool TryAddInternal(TKey1 key, Func<TKey1, TValue> valueFactory, out TValue resultingValue)
|
||||
{
|
||||
lock (writerLock)
|
||||
{
|
||||
var nextCapacity = CalculateCapacity(size + 1, loadFactor);
|
||||
|
||||
if (buckets.Length < nextCapacity)
|
||||
{
|
||||
// rehash
|
||||
var nextBucket = new Entry[nextCapacity];
|
||||
for (int i = 0; i < buckets.Length; i++)
|
||||
{
|
||||
var e = buckets[i];
|
||||
while (e != null)
|
||||
{
|
||||
var newEntry = new Entry { Key = e.Key, Value = e.Value, Hash = e.Hash };
|
||||
AddToBuckets(nextBucket, key, newEntry, null, out resultingValue);
|
||||
e = e.Next;
|
||||
}
|
||||
}
|
||||
|
||||
// add entry(if failed to add, only do resize)
|
||||
var successAdd = AddToBuckets(nextBucket, key, null, valueFactory, out resultingValue);
|
||||
|
||||
// replace field(threadsafe for read)
|
||||
VolatileWrite(ref buckets, nextBucket);
|
||||
|
||||
if (successAdd) size++;
|
||||
return successAdd;
|
||||
}
|
||||
else
|
||||
{
|
||||
// add entry(insert last is thread safe for read)
|
||||
var successAdd = AddToBuckets(buckets, key, null, valueFactory, out resultingValue);
|
||||
if (successAdd) size++;
|
||||
return successAdd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool AddToBuckets(Entry[] buckets, TKey1 newKey, Entry newEntryOrNull, Func<TKey1, TValue> valueFactory, out TValue resultingValue)
|
||||
{
|
||||
var h = (newEntryOrNull != null) ? newEntryOrNull.Hash : comparer.GetHashCode(newKey);
|
||||
if (buckets[h & (buckets.Length - 1)] == null)
|
||||
{
|
||||
if (newEntryOrNull != null)
|
||||
{
|
||||
resultingValue = newEntryOrNull.Value;
|
||||
VolatileWrite(ref buckets[h & (buckets.Length - 1)], newEntryOrNull);
|
||||
}
|
||||
else
|
||||
{
|
||||
resultingValue = valueFactory(newKey);
|
||||
VolatileWrite(ref buckets[h & (buckets.Length - 1)], new Entry { Key = newKey, Value = resultingValue, Hash = h });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var searchLastEntry = buckets[h & (buckets.Length - 1)];
|
||||
while (true)
|
||||
{
|
||||
if (comparer.Equals(searchLastEntry.Key, newKey))
|
||||
{
|
||||
resultingValue = searchLastEntry.Value;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (searchLastEntry.Next == null)
|
||||
{
|
||||
if (newEntryOrNull != null)
|
||||
{
|
||||
resultingValue = newEntryOrNull.Value;
|
||||
VolatileWrite(ref searchLastEntry.Next, newEntryOrNull);
|
||||
}
|
||||
else
|
||||
{
|
||||
resultingValue = valueFactory(newKey);
|
||||
VolatileWrite(ref searchLastEntry.Next, new Entry { Key = newKey, Value = resultingValue, Hash = h });
|
||||
}
|
||||
break;
|
||||
}
|
||||
searchLastEntry = searchLastEntry.Next;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryGetValue(TKey2 key, out TValue value)
|
||||
{
|
||||
var table = buckets;
|
||||
var hash = comparer.GetHashCode(key);
|
||||
var entry = table[hash & table.Length - 1];
|
||||
|
||||
if (entry == null) goto NOT_FOUND;
|
||||
|
||||
if (comparer.Equals(entry.Key, key))
|
||||
{
|
||||
value = entry.Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
var next = entry.Next;
|
||||
while (next != null)
|
||||
{
|
||||
if (comparer.Equals(next.Key, key))
|
||||
{
|
||||
value = next.Value;
|
||||
return true;
|
||||
}
|
||||
next = next.Next;
|
||||
}
|
||||
|
||||
NOT_FOUND:
|
||||
value = default(TValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
static int CalculateCapacity(int collectionSize, float loadFactor)
|
||||
{
|
||||
var initialCapacity = (int)(((float)collectionSize) / loadFactor);
|
||||
var capacity = 1;
|
||||
while (capacity < initialCapacity)
|
||||
{
|
||||
capacity <<= 1;
|
||||
}
|
||||
|
||||
if (capacity < 8)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
return capacity;
|
||||
}
|
||||
|
||||
static void VolatileWrite(ref Entry location, Entry value)
|
||||
{
|
||||
System.Threading.Volatile.Write(ref location, value);
|
||||
}
|
||||
|
||||
static void VolatileWrite(ref Entry[] location, Entry[] value)
|
||||
{
|
||||
System.Threading.Volatile.Write(ref location, value);
|
||||
}
|
||||
|
||||
class Entry
|
||||
{
|
||||
public TKey1 Key;
|
||||
public TValue Value;
|
||||
public int Hash;
|
||||
public Entry Next;
|
||||
|
||||
// from debugger only
|
||||
public override string ToString()
|
||||
{
|
||||
return "Count:" + Count;
|
||||
}
|
||||
|
||||
internal int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
var count = 1;
|
||||
var n = this;
|
||||
while (n.Next != null)
|
||||
{
|
||||
count++;
|
||||
n = n.Next;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0cb7ee211ccebcd408e2e3f53d8b9f8a
|
||||
timeCreated: 1503499035
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
679
Assets/Scripts/MessagePack/Internal/AutomataDictionary.cs
Normal file
679
Assets/Scripts/MessagePack/Internal/AutomataDictionary.cs
Normal file
|
|
@ -0,0 +1,679 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using System.Reflection.Emit;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MessagePack.Internal
|
||||
{
|
||||
// Key = long, Value = int for UTF8String Dictionary
|
||||
|
||||
public class AutomataDictionary : IEnumerable<KeyValuePair<string, int>>
|
||||
{
|
||||
readonly AutomataNode root;
|
||||
|
||||
public AutomataDictionary()
|
||||
{
|
||||
root = new AutomataNode(0);
|
||||
}
|
||||
|
||||
#if NETSTANDARD
|
||||
public unsafe void Add(string str, int value)
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(str);
|
||||
fixed (byte* buffer = &bytes[0])
|
||||
{
|
||||
var node = root;
|
||||
|
||||
var p = buffer;
|
||||
var rest = bytes.Length;
|
||||
while (rest != 0)
|
||||
{
|
||||
var key = AutomataKeyGen.GetKey(ref p, ref rest);
|
||||
|
||||
if (rest == 0)
|
||||
{
|
||||
node = node.Add(key, value, str);
|
||||
}
|
||||
else
|
||||
{
|
||||
node = node.Add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe bool TryGetValue(byte[] bytes, int offset, int count, out int value)
|
||||
{
|
||||
fixed (byte* p = &bytes[0])
|
||||
{
|
||||
var p1 = p;
|
||||
var node = root;
|
||||
var rest = count;
|
||||
|
||||
while (rest != 0 && node != null)
|
||||
{
|
||||
node = node.SearchNext(ref p1, ref rest);
|
||||
}
|
||||
|
||||
if (node == null)
|
||||
{
|
||||
value = -1;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = node.Value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
// for Unity, use safe only.
|
||||
|
||||
public void Add(string str, int value)
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(str);
|
||||
var offset = 0;
|
||||
|
||||
var node = root;
|
||||
|
||||
var rest = bytes.Length;
|
||||
while (rest != 0)
|
||||
{
|
||||
var key = AutomataKeyGen.GetKeySafe(bytes, ref offset, ref rest);
|
||||
|
||||
if (rest == 0)
|
||||
{
|
||||
node = node.Add(key, value, str);
|
||||
}
|
||||
else
|
||||
{
|
||||
node = node.Add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
public bool TryGetValueSafe(ArraySegment<byte> key, out int value)
|
||||
{
|
||||
var node = root;
|
||||
var bytes = key.Array;
|
||||
var offset = key.Offset;
|
||||
var rest = key.Count;
|
||||
|
||||
while (rest != 0 && node != null)
|
||||
{
|
||||
node = node.SearchNextSafe(bytes, ref offset, ref rest);
|
||||
}
|
||||
|
||||
if (node == null)
|
||||
{
|
||||
value = -1;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = node.Value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// for debugging
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
ToStringCore(root.YieldChildren(), sb, 0);
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
static void ToStringCore(IEnumerable<AutomataNode> nexts, StringBuilder sb, int depth)
|
||||
{
|
||||
foreach (var item in nexts)
|
||||
{
|
||||
if (depth != 0)
|
||||
{
|
||||
sb.Append(' ', depth * 2);
|
||||
}
|
||||
sb.Append("[" + item.Key + "]");
|
||||
if (item.Value != -1)
|
||||
{
|
||||
sb.Append("(" + item.originalKey + ")");
|
||||
sb.Append(" = ");
|
||||
sb.Append(item.Value);
|
||||
}
|
||||
sb.AppendLine();
|
||||
ToStringCore(item.YieldChildren(), sb, depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<string, int>> GetEnumerator()
|
||||
{
|
||||
return YieldCore(this.root.YieldChildren()).GetEnumerator();
|
||||
}
|
||||
|
||||
static IEnumerable<KeyValuePair<string, int>> YieldCore(IEnumerable<AutomataNode> nexts)
|
||||
{
|
||||
foreach (var item in nexts)
|
||||
{
|
||||
if (item.Value != -1) yield return new KeyValuePair<string, int>(item.originalKey, item.Value);
|
||||
foreach (var x in YieldCore(item.YieldChildren())) yield return x;
|
||||
}
|
||||
}
|
||||
|
||||
// IL Emit
|
||||
|
||||
public void EmitMatch(ILGenerator il, LocalBuilder p, LocalBuilder rest, LocalBuilder key, Action<KeyValuePair<string, int>> onFound, Action onNotFound)
|
||||
{
|
||||
root.EmitSearchNext(il, p, rest, key, onFound, onNotFound);
|
||||
}
|
||||
|
||||
class AutomataNode : IComparable<AutomataNode>
|
||||
{
|
||||
static readonly AutomataNode[] emptyNodes = new AutomataNode[0];
|
||||
static readonly ulong[] emptyKeys = new ulong[0];
|
||||
|
||||
public ulong Key;
|
||||
public int Value;
|
||||
public string originalKey;
|
||||
|
||||
AutomataNode[] nexts;
|
||||
ulong[] nextKeys;
|
||||
int count;
|
||||
|
||||
public bool HasChildren { get { return count != 0; } }
|
||||
|
||||
public AutomataNode(ulong key)
|
||||
{
|
||||
this.Key = key;
|
||||
this.Value = -1;
|
||||
this.nexts = emptyNodes;
|
||||
this.nextKeys = emptyKeys;
|
||||
this.count = 0;
|
||||
this.originalKey = null;
|
||||
}
|
||||
|
||||
public AutomataNode Add(ulong key)
|
||||
{
|
||||
var index = Array.BinarySearch(nextKeys, 0, count, key);
|
||||
if (index < 0)
|
||||
{
|
||||
if (nexts.Length == count)
|
||||
{
|
||||
Array.Resize<AutomataNode>(ref nexts, (count == 0) ? 4 : (count * 2));
|
||||
Array.Resize<ulong>(ref nextKeys, (count == 0) ? 4 : (count * 2));
|
||||
}
|
||||
count++;
|
||||
|
||||
var nextNode = new AutomataNode(key);
|
||||
nexts[count - 1] = nextNode;
|
||||
nextKeys[count - 1] = key;
|
||||
Array.Sort(nexts, 0, count);
|
||||
Array.Sort(nextKeys, 0, count);
|
||||
return nextNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nexts[index];
|
||||
}
|
||||
}
|
||||
|
||||
public AutomataNode Add(ulong key, int value, string originalKey)
|
||||
{
|
||||
var v = Add(key);
|
||||
v.Value = value;
|
||||
v.originalKey = originalKey;
|
||||
return v;
|
||||
}
|
||||
|
||||
public unsafe AutomataNode SearchNext(ref byte* p, ref int rest)
|
||||
{
|
||||
var key = AutomataKeyGen.GetKey(ref p, ref rest);
|
||||
if (count < 4)
|
||||
{
|
||||
// linear search
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (nextKeys[i] == key)
|
||||
{
|
||||
return nexts[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// binary search
|
||||
var index = BinarySearch(nextKeys, 0, count, key);
|
||||
if (index >= 0)
|
||||
{
|
||||
return nexts[index];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public unsafe AutomataNode SearchNextSafe(byte[] p, ref int offset, ref int rest)
|
||||
{
|
||||
var key = AutomataKeyGen.GetKeySafe(p, ref offset, ref rest);
|
||||
if (count < 4)
|
||||
{
|
||||
// linear search
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (nextKeys[i] == key)
|
||||
{
|
||||
return nexts[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// binary search
|
||||
var index = BinarySearch(nextKeys, 0, count, key);
|
||||
if (index >= 0)
|
||||
{
|
||||
return nexts[index];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
internal static int BinarySearch(ulong[] array, int index, int length, ulong value)
|
||||
{
|
||||
int lo = index;
|
||||
int hi = index + length - 1;
|
||||
while (lo <= hi)
|
||||
{
|
||||
int i = lo + ((hi - lo) >> 1);
|
||||
|
||||
var arrayValue = array[i];
|
||||
int order;
|
||||
if (arrayValue < value) order = -1;
|
||||
else if (arrayValue > value) order = 1;
|
||||
else order = 0;
|
||||
|
||||
if (order == 0) return i;
|
||||
if (order < 0)
|
||||
{
|
||||
lo = i + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hi = i - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ~lo;
|
||||
}
|
||||
|
||||
public int CompareTo(AutomataNode other)
|
||||
{
|
||||
return this.Key.CompareTo(other.Key);
|
||||
}
|
||||
|
||||
public IEnumerable<AutomataNode> YieldChildren()
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
yield return nexts[i];
|
||||
}
|
||||
}
|
||||
|
||||
// SearchNext(ref byte* p, ref int rest, ref ulong key)
|
||||
public void EmitSearchNext(ILGenerator il, LocalBuilder p, LocalBuilder rest, LocalBuilder key, Action<KeyValuePair<string, int>> onFound, Action onNotFound)
|
||||
{
|
||||
// key = AutomataKeyGen.GetKey(ref p, ref rest);
|
||||
il.EmitLdloca(p);
|
||||
il.EmitLdloca(rest);
|
||||
il.EmitCall(AutomataKeyGen.GetKeyMethod);
|
||||
il.EmitStloc(key);
|
||||
|
||||
// match children.
|
||||
EmitSearchNextCore(il, p, rest, key, onFound, onNotFound, nexts, count);
|
||||
}
|
||||
|
||||
static void EmitSearchNextCore(ILGenerator il, LocalBuilder p, LocalBuilder rest, LocalBuilder key, Action<KeyValuePair<string, int>> onFound, Action onNotFound, AutomataNode[] nexts, int count)
|
||||
{
|
||||
if (count < 4)
|
||||
{
|
||||
// linear-search
|
||||
var valueExists = nexts.Take(count).Where(x => x.Value != -1).ToArray();
|
||||
var childrenExists = nexts.Take(count).Where(x => x.HasChildren).ToArray();
|
||||
var gotoSearchNext = il.DefineLabel();
|
||||
var gotoNotFound = il.DefineLabel();
|
||||
|
||||
{
|
||||
il.EmitLdloc(rest);
|
||||
if (childrenExists.Length != 0 && valueExists.Length == 0)
|
||||
{
|
||||
|
||||
il.Emit(OpCodes.Brfalse, gotoNotFound); // if(rest == 0)
|
||||
}
|
||||
else
|
||||
{
|
||||
il.Emit(OpCodes.Brtrue, gotoSearchNext); // if(rest != 0)
|
||||
}
|
||||
}
|
||||
{
|
||||
var ifValueNexts = Enumerable.Range(0, Math.Max(valueExists.Length - 1, 0)).Select(_ => il.DefineLabel()).ToArray();
|
||||
for (int i = 0; i < valueExists.Length; i++)
|
||||
{
|
||||
var notFoundLabel = il.DefineLabel();
|
||||
if (i != 0)
|
||||
{
|
||||
il.MarkLabel(ifValueNexts[i - 1]);
|
||||
}
|
||||
|
||||
il.EmitLdloc(key);
|
||||
il.EmitULong(valueExists[i].Key);
|
||||
il.Emit(OpCodes.Bne_Un, notFoundLabel);
|
||||
// found
|
||||
onFound(new KeyValuePair<string, int>(valueExists[i].originalKey, valueExists[i].Value));
|
||||
|
||||
// notfound
|
||||
il.MarkLabel(notFoundLabel);
|
||||
if (i != valueExists.Length - 1)
|
||||
{
|
||||
il.Emit(OpCodes.Br, ifValueNexts[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
onNotFound();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
il.MarkLabel(gotoSearchNext);
|
||||
var ifRecNext = Enumerable.Range(0, Math.Max(childrenExists.Length - 1, 0)).Select(_ => il.DefineLabel()).ToArray();
|
||||
for (int i = 0; i < childrenExists.Length; i++)
|
||||
{
|
||||
var notFoundLabel = il.DefineLabel();
|
||||
if (i != 0)
|
||||
{
|
||||
il.MarkLabel(ifRecNext[i - 1]);
|
||||
}
|
||||
|
||||
il.EmitLdloc(key);
|
||||
il.EmitULong(childrenExists[i].Key);
|
||||
il.Emit(OpCodes.Bne_Un, notFoundLabel);
|
||||
// found
|
||||
childrenExists[i].EmitSearchNext(il, p, rest, key, onFound, onNotFound);
|
||||
// notfound
|
||||
il.MarkLabel(notFoundLabel);
|
||||
if (i != childrenExists.Length - 1)
|
||||
{
|
||||
il.Emit(OpCodes.Br, ifRecNext[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
onNotFound();
|
||||
}
|
||||
}
|
||||
|
||||
il.MarkLabel(gotoNotFound);
|
||||
onNotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
// binary-search
|
||||
var midline = count / 2;
|
||||
var mid = nexts[midline].Key;
|
||||
var l = nexts.Take(count).Take(midline).ToArray();
|
||||
var r = nexts.Take(count).Skip(midline).ToArray();
|
||||
|
||||
var gotoRight = il.DefineLabel();
|
||||
|
||||
// if(key < mid)
|
||||
il.EmitLdloc(key);
|
||||
il.EmitULong(mid);
|
||||
il.Emit(OpCodes.Bge, gotoRight);
|
||||
EmitSearchNextCore(il, p, rest, key, onFound, onNotFound, l, l.Length);
|
||||
|
||||
// else
|
||||
il.MarkLabel(gotoRight);
|
||||
EmitSearchNextCore(il, p, rest, key, onFound, onNotFound, r, r.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class AutomataKeyGen
|
||||
{
|
||||
public static readonly MethodInfo GetKeyMethod = typeof(AutomataKeyGen).GetRuntimeMethod("GetKey", new[] { typeof(byte*).MakeByRefType(), typeof(int).MakeByRefType() });
|
||||
// public static readonly MethodInfo GetKeySafeMethod = typeof(AutomataKeyGen).GetRuntimeMethod("GetKeySafe", new[] { typeof(byte[]), typeof(int).MakeByRefType(), typeof(int).MakeByRefType() });
|
||||
|
||||
public static unsafe ulong GetKey(ref byte* p, ref int rest)
|
||||
{
|
||||
int readSize;
|
||||
ulong key;
|
||||
|
||||
unchecked
|
||||
{
|
||||
if (rest >= 8)
|
||||
{
|
||||
key = *(ulong*)p;
|
||||
readSize = 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (rest)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
key = *(byte*)p;
|
||||
readSize = 1;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
key = *(ushort*)p;
|
||||
readSize = 2;
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
var a = *p;
|
||||
var b = *(ushort*)(p + 1);
|
||||
key = ((ulong)a | (ulong)b << 8);
|
||||
readSize = 3;
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
key = *(uint*)p;
|
||||
readSize = 4;
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
var a = *p;
|
||||
var b = *(uint*)(p + 1);
|
||||
key = ((ulong)a | (ulong)b << 8);
|
||||
readSize = 5;
|
||||
break;
|
||||
}
|
||||
case 6:
|
||||
{
|
||||
ulong a = *(ushort*)p;
|
||||
ulong b = *(uint*)(p + 2);
|
||||
key = (a | (b << 16));
|
||||
readSize = 6;
|
||||
break;
|
||||
}
|
||||
case 7:
|
||||
{
|
||||
var a = *(byte*)p;
|
||||
var b = *(ushort*)(p + 1);
|
||||
var c = *(uint*)(p + 3);
|
||||
key = ((ulong)a | (ulong)b << 8 | (ulong)c << 24);
|
||||
readSize = 7;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new InvalidOperationException("Not Supported Length");
|
||||
}
|
||||
}
|
||||
|
||||
p += readSize;
|
||||
rest -= readSize;
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
public static ulong GetKeySafe(byte[] bytes, ref int offset, ref int rest)
|
||||
{
|
||||
int readSize;
|
||||
ulong key;
|
||||
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
if (rest >= 8)
|
||||
{
|
||||
key = (ulong)bytes[offset] << 0 | (ulong)bytes[offset + 1] << 8 | (ulong)bytes[offset + 2] << 16 | (ulong)bytes[offset + 3] << 24
|
||||
| (ulong)bytes[offset + 4] << 32 | (ulong)bytes[offset + 5] << 40 | (ulong)bytes[offset + 6] << 48 | (ulong)bytes[offset + 7] << 56;
|
||||
readSize = 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (rest)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
key = bytes[offset];
|
||||
readSize = 1;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
key = (ulong)bytes[offset] << 0 | (ulong)bytes[offset + 1] << 8;
|
||||
readSize = 2;
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
key = (ulong)bytes[offset] << 0 | (ulong)bytes[offset + 1] << 8 | (ulong)bytes[offset + 2] << 16;
|
||||
readSize = 3;
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
key = (ulong)bytes[offset] << 0 | (ulong)bytes[offset + 1] << 8 | (ulong)bytes[offset + 2] << 16 | (ulong)bytes[offset + 3] << 24;
|
||||
readSize = 4;
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
key = (ulong)bytes[offset] << 0 | (ulong)bytes[offset + 1] << 8 | (ulong)bytes[offset + 2] << 16 | (ulong)bytes[offset + 3] << 24
|
||||
| (ulong)bytes[offset + 4] << 32;
|
||||
readSize = 5;
|
||||
break;
|
||||
}
|
||||
case 6:
|
||||
{
|
||||
key = (ulong)bytes[offset] << 0 | (ulong)bytes[offset + 1] << 8 | (ulong)bytes[offset + 2] << 16 | (ulong)bytes[offset + 3] << 24
|
||||
| (ulong)bytes[offset + 4] << 32 | (ulong)bytes[offset + 5] << 40;
|
||||
readSize = 6;
|
||||
break;
|
||||
}
|
||||
case 7:
|
||||
{
|
||||
key = (ulong)bytes[offset] << 0 | (ulong)bytes[offset + 1] << 8 | (ulong)bytes[offset + 2] << 16 | (ulong)bytes[offset + 3] << 24
|
||||
| (ulong)bytes[offset + 4] << 32 | (ulong)bytes[offset + 5] << 40 | (ulong)bytes[offset + 6] << 48;
|
||||
readSize = 7;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new InvalidOperationException("Not Supported Length");
|
||||
}
|
||||
}
|
||||
|
||||
offset += readSize;
|
||||
rest -= readSize;
|
||||
return key;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
if (rest >= 8)
|
||||
{
|
||||
key = (ulong)bytes[offset] << 56 | (ulong)bytes[offset + 1] << 48 | (ulong)bytes[offset + 2] << 40 | (ulong)bytes[offset + 3] << 32
|
||||
| (ulong)bytes[offset + 4] << 24 | (ulong)bytes[offset + 5] << 16 | (ulong)bytes[offset + 6] << 8 | (ulong)bytes[offset + 7];
|
||||
readSize = 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (rest)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
key = bytes[offset];
|
||||
readSize = 1;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
key = (ulong)bytes[offset] << 8 | (ulong)bytes[offset + 1] << 0;
|
||||
readSize = 2;
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
key = (ulong)bytes[offset] << 16 | (ulong)bytes[offset + 1] << 8 | (ulong)bytes[offset + 2] << 0;
|
||||
readSize = 3;
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
key = (ulong)bytes[offset] << 24 | (ulong)bytes[offset + 1] << 16 | (ulong)bytes[offset + 2] << 8 | (ulong)bytes[offset + 3] << 0;
|
||||
readSize = 4;
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
key = (ulong)bytes[offset] << 32 | (ulong)bytes[offset + 1] << 24 | (ulong)bytes[offset + 2] << 16 | (ulong)bytes[offset + 3] << 8
|
||||
| (ulong)bytes[offset + 4] << 0;
|
||||
readSize = 5;
|
||||
break;
|
||||
}
|
||||
case 6:
|
||||
{
|
||||
key = (ulong)bytes[offset] << 40 | (ulong)bytes[offset + 1] << 32 | (ulong)bytes[offset + 2] << 24 | (ulong)bytes[offset + 3] << 16
|
||||
| (ulong)bytes[offset + 4] << 8 | (ulong)bytes[offset + 5] << 0;
|
||||
readSize = 6;
|
||||
break;
|
||||
}
|
||||
case 7:
|
||||
{
|
||||
key = (ulong)bytes[offset] << 48 | (ulong)bytes[offset + 1] << 40 | (ulong)bytes[offset + 2] << 32 | (ulong)bytes[offset + 3] << 24
|
||||
| (ulong)bytes[offset + 4] << 16 | (ulong)bytes[offset + 5] << 8 | (ulong)bytes[offset + 6] << 0;
|
||||
readSize = 7;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new InvalidOperationException("Not Supported Length");
|
||||
}
|
||||
}
|
||||
|
||||
offset += readSize;
|
||||
rest -= readSize;
|
||||
return key;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9422203c151b16c4e8bd7c4b9e96f7ab
|
||||
timeCreated: 1503901444
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
139
Assets/Scripts/MessagePack/Internal/ByteArrayComparer.cs
Normal file
139
Assets/Scripts/MessagePack/Internal/ByteArrayComparer.cs
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace MessagePack.Internal
|
||||
{
|
||||
public static class ByteArrayComparer
|
||||
{
|
||||
#if ENABLE_UNSAFE_MSGPACK
|
||||
|
||||
#if NETSTANDARD
|
||||
|
||||
static readonly bool Is32Bit = (IntPtr.Size == 4);
|
||||
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
|
||||
public static int GetHashCode(byte[] bytes, int offset, int count)
|
||||
{
|
||||
if (Is32Bit)
|
||||
{
|
||||
return unchecked((int)FarmHash.Hash32(bytes, offset, count));
|
||||
}
|
||||
else
|
||||
{
|
||||
return unchecked((int)FarmHash.Hash64(bytes, offset, count));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if NETSTANDARD
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
|
||||
#endif
|
||||
public static unsafe bool Equals(byte[] xs, int xsOffset, int xsCount, byte[] ys)
|
||||
{
|
||||
return Equals(xs, xsOffset, xsCount, ys, 0, ys.Length);
|
||||
}
|
||||
|
||||
#if NETSTANDARD
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
|
||||
#endif
|
||||
public static unsafe bool Equals(byte[] xs, int xsOffset, int xsCount, byte[] ys, int ysOffset, int ysCount)
|
||||
{
|
||||
if (xs == null || ys == null || xsCount != ysCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
fixed (byte* p1 = &xs[xsOffset])
|
||||
fixed (byte* p2 = &ys[ysOffset])
|
||||
{
|
||||
switch (xsCount)
|
||||
{
|
||||
case 0:
|
||||
return true;
|
||||
case 1:
|
||||
return *p1 == *p2;
|
||||
case 2:
|
||||
return *(short*)p1 == *(short*)p2;
|
||||
case 3:
|
||||
if (*(byte*)p1 != *(byte*)p2) return false;
|
||||
return *(short*)(p1 + 1) == *(short*)(p2 + 1);
|
||||
case 4:
|
||||
return *(int*)p1 == *(int*)p2;
|
||||
case 5:
|
||||
if (*(byte*)p1 != *(byte*)p2) return false;
|
||||
return *(int*)(p1 + 1) == *(int*)(p2 + 1);
|
||||
case 6:
|
||||
if (*(short*)p1 != *(short*)p2) return false;
|
||||
return *(int*)(p1 + 2) == *(int*)(p2 + 2);
|
||||
case 7:
|
||||
if (*(byte*)p1 != *(byte*)p2) return false;
|
||||
if (*(short*)(p1 + 1) != *(short*)(p2 + 1)) return false;
|
||||
return *(int*)(p1 + 3) == *(int*)(p2 + 3);
|
||||
default:
|
||||
{
|
||||
var x1 = p1;
|
||||
var x2 = p2;
|
||||
|
||||
byte* xEnd = p1 + xsCount - 8;
|
||||
byte* yEnd = p2 + ysCount - 8;
|
||||
|
||||
while (x1 < xEnd)
|
||||
{
|
||||
if (*(long*)x1 != *(long*)x2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
x1 += 8;
|
||||
x2 += 8;
|
||||
}
|
||||
|
||||
return *(long*)xEnd == *(long*)yEnd;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
#if NETSTANDARD
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
|
||||
#endif
|
||||
public static bool Equals(byte[] xs, int xsOffset, int xsCount, byte[] ys)
|
||||
{
|
||||
if (xs == null || ys == null || xsCount != ys.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ys.Length; i++)
|
||||
{
|
||||
if (xs[xsOffset++] != ys[i]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if NETSTANDARD
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
|
||||
#endif
|
||||
public static bool Equals(byte[] xs, int xsOffset, int xsCount, byte[] ys, int ysOffset, int ysCount)
|
||||
{
|
||||
if (xs == null || ys == null || xsCount != ysCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < xsCount; i++)
|
||||
{
|
||||
if (xs[xsOffset++] != ys[ysOffset++]) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f1ca7a6e056df3949a27f2cf69173ea6
|
||||
timeCreated: 1503499035
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
209
Assets/Scripts/MessagePack/Internal/ByteArrayStringHashTable.cs
Normal file
209
Assets/Scripts/MessagePack/Internal/ByteArrayStringHashTable.cs
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace MessagePack.Internal
|
||||
{
|
||||
// like ArraySegment<byte> hashtable.
|
||||
// Add is safe for construction phase only and requires capacity(does not do rehash)
|
||||
// and specialized for internal use(nongenerics, TValue is int)
|
||||
|
||||
// internal, but code generator requires this class
|
||||
public class ByteArrayStringHashTable : IEnumerable<KeyValuePair<string, int>>
|
||||
{
|
||||
readonly Entry[][] buckets; // immutable array(faster than linkedlist)
|
||||
readonly ulong indexFor;
|
||||
|
||||
public ByteArrayStringHashTable(int capacity)
|
||||
: this(capacity, 0.42f) // default: 0.75f -> 0.42f
|
||||
{
|
||||
}
|
||||
|
||||
public ByteArrayStringHashTable(int capacity, float loadFactor)
|
||||
{
|
||||
var tableSize = CalculateCapacity(capacity, loadFactor);
|
||||
this.buckets = new Entry[tableSize][];
|
||||
this.indexFor = (ulong)buckets.Length - 1;
|
||||
}
|
||||
|
||||
public void Add(string key, int value)
|
||||
{
|
||||
if (!TryAddInternal(Encoding.UTF8.GetBytes(key), value))
|
||||
{
|
||||
throw new ArgumentException("Key was already exists. Key:" + key);
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(byte[] key, int value)
|
||||
{
|
||||
if (!TryAddInternal(key, value))
|
||||
{
|
||||
throw new ArgumentException("Key was already exists. Key:" + key);
|
||||
}
|
||||
}
|
||||
|
||||
bool TryAddInternal(byte[] key, int value)
|
||||
{
|
||||
var h = ByteArrayGetHashCode(key, 0, key.Length);
|
||||
var entry = new Entry { Key = key, Value = value };
|
||||
|
||||
var array = buckets[h & (indexFor)];
|
||||
if (array == null)
|
||||
{
|
||||
buckets[h & (indexFor)] = new[] { entry };
|
||||
}
|
||||
else
|
||||
{
|
||||
// check duplicate
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
var e = array[i].Key;
|
||||
if (ByteArrayComparer.Equals(key, 0, key.Length, e))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var newArray = new Entry[array.Length + 1];
|
||||
Array.Copy(array, newArray, array.Length);
|
||||
array = newArray;
|
||||
array[array.Length - 1] = entry;
|
||||
buckets[h & (indexFor)] = array;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryGetValue(ArraySegment<byte> key, out int value)
|
||||
{
|
||||
var table = buckets;
|
||||
var hash = ByteArrayGetHashCode(key.Array, key.Offset, key.Count);
|
||||
var entry = table[hash & indexFor];
|
||||
|
||||
if (entry == null) goto NOT_FOUND;
|
||||
|
||||
{
|
||||
#if NETSTANDARD
|
||||
ref var v = ref entry[0];
|
||||
#else
|
||||
var v = entry[0];
|
||||
#endif
|
||||
if (ByteArrayComparer.Equals(key.Array, key.Offset, key.Count, v.Key))
|
||||
{
|
||||
value = v.Value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i < entry.Length; i++)
|
||||
{
|
||||
#if NETSTANDARD
|
||||
ref var v = ref entry[i];
|
||||
#else
|
||||
var v = entry[i];
|
||||
#endif
|
||||
if (ByteArrayComparer.Equals(key.Array, key.Offset, key.Count, v.Key))
|
||||
{
|
||||
value = v.Value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
NOT_FOUND:
|
||||
value = default(int);
|
||||
return false;
|
||||
}
|
||||
|
||||
#if NETSTANDARD
|
||||
static readonly bool Is32Bit = (IntPtr.Size == 4);
|
||||
#endif
|
||||
|
||||
#if NETSTANDARD
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
|
||||
#endif
|
||||
static ulong ByteArrayGetHashCode(byte[] x, int offset, int count)
|
||||
{
|
||||
#if NETSTANDARD
|
||||
// FarmHash https://github.com/google/farmhash
|
||||
if (x == null) return 0;
|
||||
|
||||
if (Is32Bit)
|
||||
{
|
||||
return (ulong)FarmHash.Hash32(x, offset, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FarmHash.Hash64(x, offset, count);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// FNV1-1a 32bit https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
||||
uint hash = 0;
|
||||
if (x != null)
|
||||
{
|
||||
var max = offset + count;
|
||||
|
||||
hash = 2166136261;
|
||||
for (int i = offset; i < max; i++)
|
||||
{
|
||||
hash = unchecked((x[i] ^ hash) * 16777619);
|
||||
}
|
||||
}
|
||||
|
||||
return (ulong)hash;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
static int CalculateCapacity(int collectionSize, float loadFactor)
|
||||
{
|
||||
var initialCapacity = (int)(((float)collectionSize) / loadFactor);
|
||||
var capacity = 1;
|
||||
while (capacity < initialCapacity)
|
||||
{
|
||||
capacity <<= 1;
|
||||
}
|
||||
|
||||
if (capacity < 8)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
return capacity;
|
||||
}
|
||||
|
||||
// only for Debug use
|
||||
public IEnumerator<KeyValuePair<string, int>> GetEnumerator()
|
||||
{
|
||||
var b = this.buckets;
|
||||
|
||||
foreach (var item in b)
|
||||
{
|
||||
if (item == null) continue;
|
||||
foreach (var item2 in item)
|
||||
{
|
||||
yield return new KeyValuePair<string, int>(Encoding.UTF8.GetString(item2.Key), item2.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
struct Entry
|
||||
{
|
||||
public byte[] Key;
|
||||
public int Value;
|
||||
|
||||
// for debugging
|
||||
public override string ToString()
|
||||
{
|
||||
return "(" + Encoding.UTF8.GetString(Key) + ", " + Value + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 150b5dab543f3e647922c5017293f831
|
||||
timeCreated: 1501832163
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
47
Assets/Scripts/MessagePack/Internal/DynamicAssembly.cs
Normal file
47
Assets/Scripts/MessagePack/Internal/DynamicAssembly.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#if !UNITY_WSA
|
||||
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
|
||||
namespace MessagePack.Internal
|
||||
{
|
||||
internal class DynamicAssembly
|
||||
{
|
||||
#if NET_35
|
||||
readonly string moduleName;
|
||||
#endif
|
||||
readonly AssemblyBuilder assemblyBuilder;
|
||||
readonly ModuleBuilder moduleBuilder;
|
||||
|
||||
public ModuleBuilder ModuleBuilder { get { return moduleBuilder; } }
|
||||
|
||||
public DynamicAssembly(string moduleName)
|
||||
{
|
||||
#if NET_35
|
||||
this.moduleName = moduleName;
|
||||
this.assemblyBuilder = System.AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(moduleName), AssemblyBuilderAccess.RunAndSave);
|
||||
this.moduleBuilder = assemblyBuilder.DefineDynamicModule(moduleName, moduleName + ".dll");
|
||||
#else
|
||||
#if NETSTANDARD
|
||||
this.assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(moduleName), AssemblyBuilderAccess.Run);
|
||||
#else
|
||||
this.assemblyBuilder = System.AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(moduleName), AssemblyBuilderAccess.Run);
|
||||
#endif
|
||||
|
||||
this.moduleBuilder = assemblyBuilder.DefineDynamicModule(moduleName);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if NET_35
|
||||
|
||||
public AssemblyBuilder Save()
|
||||
{
|
||||
assemblyBuilder.Save(moduleName + ".dll");
|
||||
return assemblyBuilder;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
12
Assets/Scripts/MessagePack/Internal/DynamicAssembly.cs.meta
Normal file
12
Assets/Scripts/MessagePack/Internal/DynamicAssembly.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2fd360de733c1504bb9a002668a6a73c
|
||||
timeCreated: 1488099023
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
88
Assets/Scripts/MessagePack/Internal/ExpressionUtility.cs
Normal file
88
Assets/Scripts/MessagePack/Internal/ExpressionUtility.cs
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MessagePack.Internal
|
||||
{
|
||||
public static class ExpressionUtility
|
||||
{
|
||||
// Method
|
||||
|
||||
static MethodInfo GetMethodInfoCore(LambdaExpression expression)
|
||||
{
|
||||
if (expression == null)
|
||||
{
|
||||
throw new ArgumentNullException("expression");
|
||||
}
|
||||
|
||||
return (expression.Body as MethodCallExpression).Method;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get MethodInfo from Expression for Static(with result) method.
|
||||
/// </summary>
|
||||
public static MethodInfo GetMethodInfo<T>(Expression<Func<T>> expression)
|
||||
{
|
||||
return GetMethodInfoCore(expression);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get MethodInfo from Expression for Static(void) method.
|
||||
/// </summary>
|
||||
public static MethodInfo GetMethodInfo(Expression<Action> expression)
|
||||
{
|
||||
return GetMethodInfoCore(expression);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get MethodInfo from Expression for Instance(with result) method.
|
||||
/// </summary>
|
||||
public static MethodInfo GetMethodInfo<T, TR>(Expression<Func<T, TR>> expression)
|
||||
{
|
||||
return GetMethodInfoCore(expression);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get MethodInfo from Expression for Instance(void) method.
|
||||
/// </summary>
|
||||
public static MethodInfo GetMethodInfo<T>(Expression<Action<T>> expression)
|
||||
{
|
||||
return GetMethodInfoCore(expression);
|
||||
}
|
||||
|
||||
// WithArgument(for ref, out) helper
|
||||
|
||||
/// <summary>
|
||||
/// Get MethodInfo from Expression for Instance(with result) method.
|
||||
/// </summary>
|
||||
public static MethodInfo GetMethodInfo<T, TArg1, TR>(Expression<Func<T, TArg1, TR>> expression)
|
||||
{
|
||||
return GetMethodInfoCore(expression);
|
||||
}
|
||||
|
||||
// Property
|
||||
|
||||
static MemberInfo GetMemberInfoCore<T>(Expression<T> source)
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
throw new ArgumentNullException("source");
|
||||
}
|
||||
|
||||
var memberExpression = source.Body as MemberExpression;
|
||||
return memberExpression.Member;
|
||||
}
|
||||
|
||||
public static PropertyInfo GetPropertyInfo<T, TR>(Expression<Func<T, TR>> expression)
|
||||
{
|
||||
return GetMemberInfoCore(expression) as PropertyInfo;
|
||||
}
|
||||
|
||||
// Field
|
||||
|
||||
public static FieldInfo GetFieldInfo<T, TR>(Expression<Func<T, TR>> expression)
|
||||
{
|
||||
return GetMemberInfoCore(expression) as FieldInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9ce5e75c332bb854c9bfd13f612c7ef0
|
||||
timeCreated: 1505965655
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
604
Assets/Scripts/MessagePack/Internal/FarmHash.cs
Normal file
604
Assets/Scripts/MessagePack/Internal/FarmHash.cs
Normal file
|
|
@ -0,0 +1,604 @@
|
|||
#if NETSTANDARD
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace MessagePack.Internal
|
||||
{
|
||||
public static class FarmHash
|
||||
{
|
||||
// entry point of 32bit
|
||||
|
||||
#region Hash32
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe uint Hash32(byte[] bytes, int offset, int count)
|
||||
{
|
||||
if (count <= 4)
|
||||
{
|
||||
return Hash32Len0to4(bytes, offset, (uint)count);
|
||||
}
|
||||
|
||||
fixed (byte* p = &bytes[offset])
|
||||
{
|
||||
return Hash32(p, (uint)count);
|
||||
}
|
||||
}
|
||||
|
||||
// port of farmhash.cc, 32bit only
|
||||
|
||||
// Magic numbers for 32-bit hashing. Copied from Murmur3.
|
||||
const uint c1 = 0xcc9e2d51;
|
||||
const uint c2 = 0x1b873593;
|
||||
|
||||
static unsafe uint Fetch32(byte* p)
|
||||
{
|
||||
return *(uint*)p;
|
||||
}
|
||||
|
||||
static uint Rotate32(uint val, int shift)
|
||||
{
|
||||
return shift == 0 ? val : ((val >> shift) | (val << (32 - shift)));
|
||||
}
|
||||
|
||||
// A 32-bit to 32-bit integer hash copied from Murmur3.
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static uint fmix(uint h)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
h ^= h >> 16;
|
||||
h *= 0x85ebca6b;
|
||||
h ^= h >> 13;
|
||||
h *= 0xc2b2ae35;
|
||||
h ^= h >> 16;
|
||||
return h;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static uint Mur(uint a, uint h)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
// Helper from Murmur3 for combining two 32-bit values.
|
||||
a *= c1;
|
||||
a = Rotate32(a, 17);
|
||||
a *= c2;
|
||||
h ^= a;
|
||||
h = Rotate32(h, 19);
|
||||
return h * 5 + 0xe6546b64;
|
||||
}
|
||||
}
|
||||
|
||||
// 0-4
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static unsafe uint Hash32Len0to4(byte[] s, int offset, uint len)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
uint b = 0;
|
||||
uint c = 9;
|
||||
var max = offset + len;
|
||||
for (int i = offset; i < max; i++)
|
||||
{
|
||||
b = b * c1 + s[i];
|
||||
c ^= b;
|
||||
}
|
||||
return fmix(Mur(b, Mur(len, c)));
|
||||
}
|
||||
}
|
||||
|
||||
// 5-12
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static unsafe uint Hash32Len5to12(byte* s, uint len)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
uint a = len, b = len * 5, c = 9, d = b;
|
||||
a += Fetch32(s);
|
||||
b += Fetch32(s + len - 4);
|
||||
c += Fetch32(s + ((len >> 1) & 4));
|
||||
return fmix(Mur(c, Mur(b, Mur(a, d))));
|
||||
}
|
||||
}
|
||||
|
||||
// 13-24
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static unsafe uint Hash32Len13to24(byte* s, uint len)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
uint a = Fetch32(s - 4 + (len >> 1));
|
||||
uint b = Fetch32(s + 4);
|
||||
uint c = Fetch32(s + len - 8);
|
||||
uint d = Fetch32(s + (len >> 1));
|
||||
uint e = Fetch32(s);
|
||||
uint f = Fetch32(s + len - 4);
|
||||
uint h = d * c1 + len;
|
||||
a = Rotate32(a, 12) + f;
|
||||
h = Mur(c, h) + a;
|
||||
a = Rotate32(a, 3) + c;
|
||||
h = Mur(e, h) + a;
|
||||
a = Rotate32(a + f, 12) + d;
|
||||
h = Mur(b, h) + a;
|
||||
return fmix(h);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static unsafe uint Hash32(byte* s, uint len)
|
||||
{
|
||||
if (len <= 24)
|
||||
{
|
||||
return len <= 12 ? Hash32Len5to12(s, len) : Hash32Len13to24(s, len);
|
||||
}
|
||||
|
||||
unchecked
|
||||
{
|
||||
// len > 24
|
||||
uint h = len, g = c1 * len, f = g;
|
||||
uint a0 = Rotate32(Fetch32(s + len - 4) * c1, 17) * c2;
|
||||
uint a1 = Rotate32(Fetch32(s + len - 8) * c1, 17) * c2;
|
||||
uint a2 = Rotate32(Fetch32(s + len - 16) * c1, 17) * c2;
|
||||
uint a3 = Rotate32(Fetch32(s + len - 12) * c1, 17) * c2;
|
||||
uint a4 = Rotate32(Fetch32(s + len - 20) * c1, 17) * c2;
|
||||
h ^= a0;
|
||||
h = Rotate32(h, 19);
|
||||
h = h * 5 + 0xe6546b64;
|
||||
h ^= a2;
|
||||
h = Rotate32(h, 19);
|
||||
h = h * 5 + 0xe6546b64;
|
||||
g ^= a1;
|
||||
g = Rotate32(g, 19);
|
||||
g = g * 5 + 0xe6546b64;
|
||||
g ^= a3;
|
||||
g = Rotate32(g, 19);
|
||||
g = g * 5 + 0xe6546b64;
|
||||
f += a4;
|
||||
f = Rotate32(f, 19) + 113;
|
||||
uint iters = (len - 1) / 20;
|
||||
do
|
||||
{
|
||||
uint a = Fetch32(s);
|
||||
uint b = Fetch32(s + 4);
|
||||
uint c = Fetch32(s + 8);
|
||||
uint d = Fetch32(s + 12);
|
||||
uint e = Fetch32(s + 16);
|
||||
h += a;
|
||||
g += b;
|
||||
f += c;
|
||||
h = Mur(d, h) + e;
|
||||
g = Mur(c, g) + a;
|
||||
f = Mur(b + e * c1, f) + d;
|
||||
f += g;
|
||||
g += f;
|
||||
s += 20;
|
||||
} while (--iters != 0);
|
||||
g = Rotate32(g, 11) * c1;
|
||||
g = Rotate32(g, 17) * c1;
|
||||
f = Rotate32(f, 11) * c1;
|
||||
f = Rotate32(f, 17) * c1;
|
||||
h = Rotate32(h + g, 19);
|
||||
h = h * 5 + 0xe6546b64;
|
||||
h = Rotate32(h, 17) * c1;
|
||||
h = Rotate32(h + f, 19);
|
||||
h = h * 5 + 0xe6546b64;
|
||||
h = Rotate32(h, 17) * c1;
|
||||
return h;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region hash64
|
||||
|
||||
// entry point
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong Hash64(byte[] bytes, int offset, int count)
|
||||
{
|
||||
fixed (byte* p = &bytes[offset])
|
||||
{
|
||||
return Hash64(p, (uint)count);
|
||||
}
|
||||
}
|
||||
|
||||
// port from farmhash.cc
|
||||
|
||||
struct pair
|
||||
{
|
||||
public ulong first;
|
||||
public ulong second;
|
||||
|
||||
public pair(ulong first, ulong second)
|
||||
{
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static pair make_pair(ulong first, ulong second)
|
||||
{
|
||||
return new pair(first, second);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static void swap(ref ulong x, ref ulong z)
|
||||
{
|
||||
var temp = z;
|
||||
z = x;
|
||||
x = temp;
|
||||
}
|
||||
|
||||
// Some primes between 2^63 and 2^64 for various uses.
|
||||
const ulong k0 = 0xc3a5c85c97cb3127UL;
|
||||
const ulong k1 = 0xb492b66fbe98f273UL;
|
||||
const ulong k2 = 0x9ae16a3b2f90404fUL;
|
||||
|
||||
static unsafe ulong Fetch64(byte* p)
|
||||
{
|
||||
return *(ulong*)p;
|
||||
}
|
||||
|
||||
static ulong Rotate64(ulong val, int shift)
|
||||
{
|
||||
return shift == 0 ? val : (val >> shift) | (val << (64 - shift));
|
||||
}
|
||||
|
||||
// farmhashna.cc
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static ulong ShiftMix(ulong val)
|
||||
{
|
||||
return val ^ (val >> 47);
|
||||
}
|
||||
|
||||
// farmhashna.cc
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static ulong HashLen16(ulong u, ulong v, ulong mul)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
// Murmur-inspired hashing.
|
||||
ulong a = (u ^ v) * mul;
|
||||
a ^= a >> 47;
|
||||
ulong b = (v ^ a) * mul;
|
||||
b ^= b >> 47;
|
||||
b *= mul;
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
// farmhashxo.cc
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static unsafe ulong Hash64(byte* s, uint len)
|
||||
{
|
||||
if (len <= 16)
|
||||
{
|
||||
// farmhashna::
|
||||
return HashLen0to16(s, len);
|
||||
}
|
||||
|
||||
if (len <= 32)
|
||||
{
|
||||
// farmhashna::
|
||||
return HashLen17to32(s, len);
|
||||
}
|
||||
|
||||
if (len <= 64)
|
||||
{
|
||||
return HashLen33to64(s, len);
|
||||
}
|
||||
|
||||
if (len <= 96)
|
||||
{
|
||||
return HashLen65to96(s, len);
|
||||
}
|
||||
|
||||
if (len <= 256)
|
||||
{
|
||||
// farmhashna::
|
||||
return Hash64NA(s, len);
|
||||
}
|
||||
|
||||
// farmhashuo::
|
||||
return Hash64UO(s, len);
|
||||
}
|
||||
|
||||
// 0-16 farmhashna.cc
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static unsafe ulong HashLen0to16(byte* s, uint len)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
if (len >= 8)
|
||||
{
|
||||
ulong mul = k2 + len * 2;
|
||||
ulong a = Fetch64(s) + k2;
|
||||
ulong b = Fetch64(s + len - 8);
|
||||
ulong c = Rotate64(b, 37) * mul + a;
|
||||
ulong d = (Rotate64(a, 25) + b) * mul;
|
||||
return HashLen16(c, d, mul);
|
||||
}
|
||||
if (len >= 4)
|
||||
{
|
||||
ulong mul = k2 + len * 2;
|
||||
ulong a = Fetch32(s);
|
||||
return HashLen16(len + (a << 3), Fetch32(s + len - 4), mul);
|
||||
}
|
||||
if (len > 0)
|
||||
{
|
||||
ushort a = s[0];
|
||||
ushort b = s[len >> 1];
|
||||
ushort c = s[len - 1];
|
||||
uint y = a + ((uint)b << 8);
|
||||
uint z = len + ((uint)c << 2);
|
||||
return ShiftMix(y * k2 ^ z * k0) * k2;
|
||||
}
|
||||
return k2;
|
||||
}
|
||||
}
|
||||
|
||||
// 17-32 farmhashna.cc
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static unsafe ulong HashLen17to32(byte* s, uint len)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
ulong mul = k2 + len * 2;
|
||||
ulong a = Fetch64(s) * k1;
|
||||
ulong b = Fetch64(s + 8);
|
||||
ulong c = Fetch64(s + len - 8) * mul;
|
||||
ulong d = Fetch64(s + len - 16) * k2;
|
||||
return HashLen16(Rotate64(a + b, 43) + Rotate64(c, 30) + d,
|
||||
a + Rotate64(b + k2, 18) + c, mul);
|
||||
}
|
||||
}
|
||||
|
||||
// farmhashxo.cc
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static unsafe ulong H32(byte* s, uint len, ulong mul, ulong seed0 = 0, ulong seed1 = 0)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
ulong a = Fetch64(s) * k1;
|
||||
ulong b = Fetch64(s + 8);
|
||||
ulong c = Fetch64(s + len - 8) * mul;
|
||||
ulong d = Fetch64(s + len - 16) * k2;
|
||||
ulong u = Rotate64(a + b, 43) + Rotate64(c, 30) + d + seed0;
|
||||
ulong v = a + Rotate64(b + k2, 18) + c + seed1;
|
||||
a = ShiftMix((u ^ v) * mul);
|
||||
b = ShiftMix((v ^ a) * mul);
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
// 33-64 farmhashxo.cc
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static unsafe ulong HashLen33to64(byte* s, uint len)
|
||||
{
|
||||
const ulong mul0 = k2 - 30;
|
||||
|
||||
unchecked
|
||||
{
|
||||
ulong mul1 = k2 - 30 + 2 * len;
|
||||
ulong h0 = H32(s, 32, mul0);
|
||||
ulong h1 = H32(s + len - 32, 32, mul1);
|
||||
return (h1 * mul1 + h0) * mul1;
|
||||
}
|
||||
}
|
||||
|
||||
// 65-96 farmhashxo.cc
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static unsafe ulong HashLen65to96(byte* s, uint len)
|
||||
{
|
||||
const ulong mul0 = k2 - 114;
|
||||
|
||||
unchecked
|
||||
{
|
||||
ulong mul1 = k2 - 114 + 2 * len;
|
||||
ulong h0 = H32(s, 32, mul0);
|
||||
ulong h1 = H32(s + 32, 32, mul1);
|
||||
ulong h2 = H32(s + len - 32, 32, mul1, h0, h1);
|
||||
return (h2 * 9 + (h0 >> 17) + (h1 >> 21)) * mul1;
|
||||
}
|
||||
}
|
||||
|
||||
// farmhashna.cc
|
||||
// Return a 16-byte hash for 48 bytes. Quick and dirty.
|
||||
// Callers do best to use "random-looking" values for a and b.
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static unsafe pair WeakHashLen32WithSeeds(ulong w, ulong x, ulong y, ulong z, ulong a, ulong b)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
a += w;
|
||||
b = Rotate64(b + a + z, 21);
|
||||
ulong c = a;
|
||||
a += x;
|
||||
a += y;
|
||||
b += Rotate64(a, 44);
|
||||
return make_pair(a + z, b + c);
|
||||
}
|
||||
}
|
||||
|
||||
// farmhashna.cc
|
||||
// Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static unsafe pair WeakHashLen32WithSeeds(byte* s, ulong a, ulong b)
|
||||
{
|
||||
return WeakHashLen32WithSeeds(Fetch64(s),
|
||||
Fetch64(s + 8),
|
||||
Fetch64(s + 16),
|
||||
Fetch64(s + 24),
|
||||
a,
|
||||
b);
|
||||
}
|
||||
|
||||
// na(97-256) farmhashna.cc
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static unsafe ulong Hash64NA(byte* s, uint len)
|
||||
{
|
||||
const ulong seed = 81;
|
||||
|
||||
unchecked
|
||||
{
|
||||
// For strings over 64 bytes we loop. Internal state consists of
|
||||
// 56 bytes: v, w, x, y, and z.
|
||||
ulong x = seed;
|
||||
ulong y = seed * k1 + 113;
|
||||
ulong z = ShiftMix(y * k2 + 113) * k2;
|
||||
var v = make_pair(0, 0);
|
||||
var w = make_pair(0, 0);
|
||||
x = x * k2 + Fetch64(s);
|
||||
|
||||
// Set end so that after the loop we have 1 to 64 bytes left to process.
|
||||
byte* end = s + ((len - 1) / 64) * 64;
|
||||
byte* last64 = end + ((len - 1) & 63) - 63;
|
||||
|
||||
do
|
||||
{
|
||||
x = Rotate64(x + y + v.first + Fetch64(s + 8), 37) * k1;
|
||||
y = Rotate64(y + v.second + Fetch64(s + 48), 42) * k1;
|
||||
x ^= w.second;
|
||||
y += v.first + Fetch64(s + 40);
|
||||
z = Rotate64(z + w.first, 33) * k1;
|
||||
v = WeakHashLen32WithSeeds(s, v.second * k1, x + w.first);
|
||||
w = WeakHashLen32WithSeeds(s + 32, z + w.second, y + Fetch64(s + 16));
|
||||
swap(ref z, ref x);
|
||||
s += 64;
|
||||
} while (s != end);
|
||||
ulong mul = k1 + ((z & 0xff) << 1);
|
||||
// Make s point to the last 64 bytes of input.
|
||||
s = last64;
|
||||
w.first += ((len - 1) & 63);
|
||||
v.first += w.first;
|
||||
w.first += v.first;
|
||||
x = Rotate64(x + y + v.first + Fetch64(s + 8), 37) * mul;
|
||||
y = Rotate64(y + v.second + Fetch64(s + 48), 42) * mul;
|
||||
x ^= w.second * 9;
|
||||
y += v.first * 9 + Fetch64(s + 40);
|
||||
z = Rotate64(z + w.first, 33) * mul;
|
||||
v = WeakHashLen32WithSeeds(s, v.second * mul, x + w.first);
|
||||
w = WeakHashLen32WithSeeds(s + 32, z + w.second, y + Fetch64(s + 16));
|
||||
swap(ref z, ref x);
|
||||
return HashLen16(HashLen16(v.first, w.first, mul) + ShiftMix(y) * k0 + z,
|
||||
HashLen16(v.second, w.second, mul) + x,
|
||||
mul);
|
||||
}
|
||||
}
|
||||
|
||||
// farmhashuo.cc
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static ulong H(ulong x, ulong y, ulong mul, int r)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
ulong a = (x ^ y) * mul;
|
||||
a ^= (a >> 47);
|
||||
ulong b = (y ^ a) * mul;
|
||||
return Rotate64(b, r) * mul;
|
||||
}
|
||||
}
|
||||
|
||||
// uo(257-) farmhashuo.cc, Hash64WithSeeds
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static unsafe ulong Hash64UO(byte* s, uint len)
|
||||
{
|
||||
const ulong seed0 = 81;
|
||||
const ulong seed1 = 0;
|
||||
|
||||
unchecked
|
||||
{
|
||||
// For strings over 64 bytes we loop. Internal state consists of
|
||||
// 64 bytes: u, v, w, x, y, and z.
|
||||
ulong x = seed0;
|
||||
ulong y = seed1 * k2 + 113;
|
||||
ulong z = ShiftMix(y * k2) * k2;
|
||||
var v = make_pair(seed0, seed1);
|
||||
var w = make_pair(0, 0);
|
||||
ulong u = x - z;
|
||||
x *= k2;
|
||||
ulong mul = k2 + (u & 0x82);
|
||||
|
||||
// Set end so that after the loop we have 1 to 64 bytes left to process.
|
||||
byte* end = s + ((len - 1) / 64) * 64;
|
||||
byte* last64 = end + ((len - 1) & 63) - 63;
|
||||
|
||||
do
|
||||
{
|
||||
ulong a0 = Fetch64(s);
|
||||
ulong a1 = Fetch64(s + 8);
|
||||
ulong a2 = Fetch64(s + 16);
|
||||
ulong a3 = Fetch64(s + 24);
|
||||
ulong a4 = Fetch64(s + 32);
|
||||
ulong a5 = Fetch64(s + 40);
|
||||
ulong a6 = Fetch64(s + 48);
|
||||
ulong a7 = Fetch64(s + 56);
|
||||
x += a0 + a1;
|
||||
y += a2;
|
||||
z += a3;
|
||||
v.first += a4;
|
||||
v.second += a5 + a1;
|
||||
w.first += a6;
|
||||
w.second += a7;
|
||||
|
||||
x = Rotate64(x, 26);
|
||||
x *= 9;
|
||||
y = Rotate64(y, 29);
|
||||
z *= mul;
|
||||
v.first = Rotate64(v.first, 33);
|
||||
v.second = Rotate64(v.second, 30);
|
||||
w.first ^= x;
|
||||
w.first *= 9;
|
||||
z = Rotate64(z, 32);
|
||||
z += w.second;
|
||||
w.second += z;
|
||||
z *= 9;
|
||||
swap(ref u, ref y);
|
||||
|
||||
z += a0 + a6;
|
||||
v.first += a2;
|
||||
v.second += a3;
|
||||
w.first += a4;
|
||||
w.second += a5 + a6;
|
||||
x += a1;
|
||||
y += a7;
|
||||
|
||||
y += v.first;
|
||||
v.first += x - y;
|
||||
v.second += w.first;
|
||||
w.first += v.second;
|
||||
w.second += x - y;
|
||||
x += w.second;
|
||||
w.second = Rotate64(w.second, 34);
|
||||
swap(ref u, ref z);
|
||||
s += 64;
|
||||
} while (s != end);
|
||||
// Make s point to the last 64 bytes of input.
|
||||
s = last64;
|
||||
u *= 9;
|
||||
v.second = Rotate64(v.second, 28);
|
||||
v.first = Rotate64(v.first, 20);
|
||||
w.first += ((len - 1) & 63);
|
||||
u += y;
|
||||
y += u;
|
||||
x = Rotate64(y - x + v.first + Fetch64(s + 8), 37) * mul;
|
||||
y = Rotate64(y ^ v.second ^ Fetch64(s + 48), 42) * mul;
|
||||
x ^= w.second * 9;
|
||||
y += v.first + Fetch64(s + 40);
|
||||
z = Rotate64(z + w.first, 33) * mul;
|
||||
v = WeakHashLen32WithSeeds(s, v.second * mul, x + w.first);
|
||||
w = WeakHashLen32WithSeeds(s + 32, z + w.second, y + Fetch64(s + 16));
|
||||
return H(HashLen16(v.first + x, w.first ^ y, mul) + z - u,
|
||||
H(v.second + y, w.second + z, k2, 30) ^ x,
|
||||
k2,
|
||||
31);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
12
Assets/Scripts/MessagePack/Internal/FarmHash.cs.meta
Normal file
12
Assets/Scripts/MessagePack/Internal/FarmHash.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7b03526046058694e99952f4732e0672
|
||||
timeCreated: 1501832163
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
372
Assets/Scripts/MessagePack/Internal/GuidBits.cs
Normal file
372
Assets/Scripts/MessagePack/Internal/GuidBits.cs
Normal file
|
|
@ -0,0 +1,372 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace MessagePack.Internal
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Pack = 1)]
|
||||
internal struct GuidBits
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public readonly Guid Value;
|
||||
|
||||
[FieldOffset(0)]
|
||||
public readonly byte Byte0;
|
||||
[FieldOffset(1)]
|
||||
public readonly byte Byte1;
|
||||
[FieldOffset(2)]
|
||||
public readonly byte Byte2;
|
||||
[FieldOffset(3)]
|
||||
public readonly byte Byte3;
|
||||
[FieldOffset(4)]
|
||||
public readonly byte Byte4;
|
||||
[FieldOffset(5)]
|
||||
public readonly byte Byte5;
|
||||
[FieldOffset(6)]
|
||||
public readonly byte Byte6;
|
||||
[FieldOffset(7)]
|
||||
public readonly byte Byte7;
|
||||
[FieldOffset(8)]
|
||||
public readonly byte Byte8;
|
||||
[FieldOffset(9)]
|
||||
public readonly byte Byte9;
|
||||
[FieldOffset(10)]
|
||||
public readonly byte Byte10;
|
||||
[FieldOffset(11)]
|
||||
public readonly byte Byte11;
|
||||
[FieldOffset(12)]
|
||||
public readonly byte Byte12;
|
||||
[FieldOffset(13)]
|
||||
public readonly byte Byte13;
|
||||
[FieldOffset(14)]
|
||||
public readonly byte Byte14;
|
||||
[FieldOffset(15)]
|
||||
public readonly byte Byte15;
|
||||
|
||||
// string.Join(", ", Enumerable.Range(0, 256).Select(x => (int)BitConverter.ToString(new byte[] { (byte)x }).ToLower()[0]))
|
||||
static byte[] byteToHexStringHigh = new byte[256] { 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102 };
|
||||
|
||||
// string.Join(", ", Enumerable.Range(0, 256).Select(x => (int)BitConverter.ToString(new byte[] { (byte)x }).ToLower()[1]))
|
||||
static byte[] byteToHexStringLow = new byte[256] { 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102 };
|
||||
|
||||
public GuidBits(ref Guid value)
|
||||
{
|
||||
this = default(GuidBits);
|
||||
this.Value = value;
|
||||
}
|
||||
|
||||
// 4-pattern, lower/upper and '-' or no
|
||||
public GuidBits(ArraySegment<byte> utf8string)
|
||||
{
|
||||
this = default(GuidBits);
|
||||
|
||||
var array = utf8string.Array;
|
||||
var offset = utf8string.Offset;
|
||||
|
||||
// 32
|
||||
if (utf8string.Count == 32)
|
||||
{
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
this.Byte0 = Parse(array, offset + 6);
|
||||
this.Byte1 = Parse(array, offset + 4);
|
||||
this.Byte2 = Parse(array, offset + 2);
|
||||
this.Byte3 = Parse(array, offset + 0);
|
||||
|
||||
this.Byte4 = Parse(array, offset + 10);
|
||||
this.Byte5 = Parse(array, offset + 8);
|
||||
|
||||
this.Byte6 = Parse(array, offset + 14);
|
||||
this.Byte7 = Parse(array, offset + 12);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Byte0 = Parse(array, offset + 0);
|
||||
this.Byte1 = Parse(array, offset + 2);
|
||||
this.Byte2 = Parse(array, offset + 4);
|
||||
this.Byte3 = Parse(array, offset + 6);
|
||||
|
||||
this.Byte4 = Parse(array, offset + 8);
|
||||
this.Byte5 = Parse(array, offset + 10);
|
||||
|
||||
this.Byte6 = Parse(array, offset + 12);
|
||||
this.Byte7 = Parse(array, offset + 14);
|
||||
}
|
||||
this.Byte8 = Parse(array, offset + 16);
|
||||
this.Byte9 = Parse(array, offset + 18);
|
||||
|
||||
this.Byte10 = Parse(array, offset + 20);
|
||||
this.Byte11 = Parse(array, offset + 22);
|
||||
this.Byte12 = Parse(array, offset + 24);
|
||||
this.Byte13 = Parse(array, offset + 26);
|
||||
this.Byte14 = Parse(array, offset + 28);
|
||||
this.Byte15 = Parse(array, offset + 30);
|
||||
return;
|
||||
}
|
||||
else if (utf8string.Count == 36)
|
||||
{
|
||||
// '-' => 45
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
this.Byte0 = Parse(array, offset + 6);
|
||||
this.Byte1 = Parse(array, offset + 4);
|
||||
this.Byte2 = Parse(array, offset + 2);
|
||||
this.Byte3 = Parse(array, offset + 0);
|
||||
|
||||
if (array[offset + 8] != '-') goto ERROR;
|
||||
|
||||
this.Byte4 = Parse(array, offset + 11);
|
||||
this.Byte5 = Parse(array, offset + 9);
|
||||
|
||||
if (array[offset + 13] != '-') goto ERROR;
|
||||
|
||||
this.Byte6 = Parse(array, offset + 16);
|
||||
this.Byte7 = Parse(array, offset + 14);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Byte0 = Parse(array, offset + 0);
|
||||
this.Byte1 = Parse(array, offset + 2);
|
||||
this.Byte2 = Parse(array, offset + 4);
|
||||
this.Byte3 = Parse(array, offset + 6);
|
||||
|
||||
if (array[offset + 8] != '-') goto ERROR;
|
||||
|
||||
this.Byte4 = Parse(array, offset + 9);
|
||||
this.Byte5 = Parse(array, offset + 11);
|
||||
|
||||
if (array[offset + 13] != '-') goto ERROR;
|
||||
|
||||
this.Byte6 = Parse(array, offset + 14);
|
||||
this.Byte7 = Parse(array, offset + 16);
|
||||
}
|
||||
|
||||
if (array[offset + 18] != '-') goto ERROR;
|
||||
|
||||
this.Byte8 = Parse(array, offset + 19);
|
||||
this.Byte9 = Parse(array, offset + 21);
|
||||
|
||||
if (array[offset + 23] != '-') goto ERROR;
|
||||
|
||||
this.Byte10 = Parse(array, offset + 24);
|
||||
this.Byte11 = Parse(array, offset + 26);
|
||||
this.Byte12 = Parse(array, offset + 28);
|
||||
this.Byte13 = Parse(array, offset + 30);
|
||||
this.Byte14 = Parse(array, offset + 32);
|
||||
this.Byte15 = Parse(array, offset + 34);
|
||||
return;
|
||||
}
|
||||
|
||||
ERROR:
|
||||
throw new ArgumentException("Invalid Guid Pattern.");
|
||||
}
|
||||
|
||||
#if NETSTANDARD
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
|
||||
#endif
|
||||
static byte Parse(byte[] bytes, int highOffset)
|
||||
{
|
||||
return unchecked((byte)(SwitchParse(bytes[highOffset]) * 16 + SwitchParse(bytes[highOffset + 1])));
|
||||
}
|
||||
|
||||
#if NETSTANDARD
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
|
||||
#endif
|
||||
static byte SwitchParse(byte b)
|
||||
{
|
||||
// '0'(48) ~ '9'(57) => -48
|
||||
// 'A'(65) ~ 'F'(70) => -55
|
||||
// 'a'(97) ~ 'f'(102) => -87
|
||||
switch (b)
|
||||
{
|
||||
case 48:
|
||||
case 49:
|
||||
case 50:
|
||||
case 51:
|
||||
case 52:
|
||||
case 53:
|
||||
case 54:
|
||||
case 55:
|
||||
case 56:
|
||||
case 57:
|
||||
return unchecked((byte)((b - 48)));
|
||||
case 65:
|
||||
case 66:
|
||||
case 67:
|
||||
case 68:
|
||||
case 69:
|
||||
case 70:
|
||||
return unchecked((byte)((b - 55)));
|
||||
case 97:
|
||||
case 98:
|
||||
case 99:
|
||||
case 100:
|
||||
case 101:
|
||||
case 102:
|
||||
return unchecked((byte)((b - 87)));
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
case 16:
|
||||
case 17:
|
||||
case 18:
|
||||
case 19:
|
||||
case 20:
|
||||
case 21:
|
||||
case 22:
|
||||
case 23:
|
||||
case 24:
|
||||
case 25:
|
||||
case 26:
|
||||
case 27:
|
||||
case 28:
|
||||
case 29:
|
||||
case 30:
|
||||
case 31:
|
||||
case 32:
|
||||
case 33:
|
||||
case 34:
|
||||
case 35:
|
||||
case 36:
|
||||
case 37:
|
||||
case 38:
|
||||
case 39:
|
||||
case 40:
|
||||
case 41:
|
||||
case 42:
|
||||
case 43:
|
||||
case 44:
|
||||
case 45:
|
||||
case 46:
|
||||
case 47:
|
||||
case 58:
|
||||
case 59:
|
||||
case 60:
|
||||
case 61:
|
||||
case 62:
|
||||
case 63:
|
||||
case 64:
|
||||
case 71:
|
||||
case 72:
|
||||
case 73:
|
||||
case 74:
|
||||
case 75:
|
||||
case 76:
|
||||
case 77:
|
||||
case 78:
|
||||
case 79:
|
||||
case 80:
|
||||
case 81:
|
||||
case 82:
|
||||
case 83:
|
||||
case 84:
|
||||
case 85:
|
||||
case 86:
|
||||
case 87:
|
||||
case 88:
|
||||
case 89:
|
||||
case 90:
|
||||
case 91:
|
||||
case 92:
|
||||
case 93:
|
||||
case 94:
|
||||
case 95:
|
||||
case 96:
|
||||
default:
|
||||
throw new ArgumentException("Invalid Guid Pattern.");
|
||||
}
|
||||
}
|
||||
|
||||
// 4(x2) - 2(x2) - 2(x2) - 2(x2) - 6(x2)
|
||||
public void Write(byte[] buffer, int offset)
|
||||
{
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
// int(_a)
|
||||
buffer[offset + 6] = byteToHexStringHigh[Byte0];
|
||||
buffer[offset + 7] = byteToHexStringLow[Byte0];
|
||||
buffer[offset + 4] = byteToHexStringHigh[Byte1];
|
||||
buffer[offset + 5] = byteToHexStringLow[Byte1];
|
||||
buffer[offset + 2] = byteToHexStringHigh[Byte2];
|
||||
buffer[offset + 3] = byteToHexStringLow[Byte2];
|
||||
buffer[offset + 0] = byteToHexStringHigh[Byte3];
|
||||
buffer[offset + 1] = byteToHexStringLow[Byte3];
|
||||
|
||||
buffer[offset + 8] = (byte)'-';
|
||||
|
||||
// short(_b)
|
||||
buffer[offset + 11] = byteToHexStringHigh[Byte4];
|
||||
buffer[offset + 12] = byteToHexStringLow[Byte4];
|
||||
buffer[offset + 9] = byteToHexStringHigh[Byte5];
|
||||
buffer[offset + 10] = byteToHexStringLow[Byte5];
|
||||
|
||||
buffer[offset + 13] = (byte)'-';
|
||||
|
||||
// short(_c)
|
||||
buffer[offset + 16] = byteToHexStringHigh[Byte6];
|
||||
buffer[offset + 17] = byteToHexStringLow[Byte6];
|
||||
buffer[offset + 14] = byteToHexStringHigh[Byte7];
|
||||
buffer[offset + 15] = byteToHexStringLow[Byte7];
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[offset + 0] = byteToHexStringHigh[Byte0];
|
||||
buffer[offset + 1] = byteToHexStringLow[Byte0];
|
||||
buffer[offset + 2] = byteToHexStringHigh[Byte1];
|
||||
buffer[offset + 3] = byteToHexStringLow[Byte1];
|
||||
buffer[offset + 4] = byteToHexStringHigh[Byte2];
|
||||
buffer[offset + 5] = byteToHexStringLow[Byte2];
|
||||
buffer[offset + 6] = byteToHexStringHigh[Byte3];
|
||||
buffer[offset + 7] = byteToHexStringLow[Byte3];
|
||||
|
||||
buffer[offset + 8] = (byte)'-';
|
||||
|
||||
buffer[offset + 9] = byteToHexStringHigh[Byte4];
|
||||
buffer[offset + 10] = byteToHexStringLow[Byte4];
|
||||
buffer[offset + 11] = byteToHexStringHigh[Byte5];
|
||||
buffer[offset + 12] = byteToHexStringLow[Byte5];
|
||||
|
||||
buffer[offset + 13] = (byte)'-';
|
||||
|
||||
buffer[offset + 14] = byteToHexStringHigh[Byte6];
|
||||
buffer[offset + 15] = byteToHexStringLow[Byte6];
|
||||
buffer[offset + 16] = byteToHexStringHigh[Byte7];
|
||||
buffer[offset + 17] = byteToHexStringLow[Byte7];
|
||||
}
|
||||
|
||||
buffer[offset + 18] = (byte)'-';
|
||||
|
||||
buffer[offset + 19] = byteToHexStringHigh[Byte8];
|
||||
buffer[offset + 20] = byteToHexStringLow[Byte8];
|
||||
buffer[offset + 21] = byteToHexStringHigh[Byte9];
|
||||
buffer[offset + 22] = byteToHexStringLow[Byte9];
|
||||
|
||||
buffer[offset + 23] = (byte)'-';
|
||||
|
||||
buffer[offset + 24] = byteToHexStringHigh[Byte10];
|
||||
buffer[offset + 25] = byteToHexStringLow[Byte10];
|
||||
buffer[offset + 26] = byteToHexStringHigh[Byte11];
|
||||
buffer[offset + 27] = byteToHexStringLow[Byte11];
|
||||
buffer[offset + 28] = byteToHexStringHigh[Byte12];
|
||||
buffer[offset + 29] = byteToHexStringLow[Byte12];
|
||||
buffer[offset + 30] = byteToHexStringHigh[Byte13];
|
||||
buffer[offset + 31] = byteToHexStringLow[Byte13];
|
||||
buffer[offset + 32] = byteToHexStringHigh[Byte14];
|
||||
buffer[offset + 33] = byteToHexStringLow[Byte14];
|
||||
buffer[offset + 34] = byteToHexStringHigh[Byte15];
|
||||
buffer[offset + 35] = byteToHexStringLow[Byte15];
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Scripts/MessagePack/Internal/GuidBits.cs.meta
Normal file
12
Assets/Scripts/MessagePack/Internal/GuidBits.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d41e5f9c2ae8be2469a8d817a109b975
|
||||
timeCreated: 1505965655
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
393
Assets/Scripts/MessagePack/Internal/ILGeneratorExtensions.cs
Normal file
393
Assets/Scripts/MessagePack/Internal/ILGeneratorExtensions.cs
Normal file
|
|
@ -0,0 +1,393 @@
|
|||
#if !UNITY_WSA
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
|
||||
namespace MessagePack.Internal
|
||||
{
|
||||
internal struct ArgumentField
|
||||
{
|
||||
readonly int i;
|
||||
readonly bool @ref;
|
||||
readonly ILGenerator il;
|
||||
|
||||
public ArgumentField(ILGenerator il, int i, bool @ref = false)
|
||||
{
|
||||
this.il = il;
|
||||
this.i = i;
|
||||
this.@ref = @ref;
|
||||
}
|
||||
|
||||
public ArgumentField(ILGenerator il, int i, Type type)
|
||||
{
|
||||
this.il = il;
|
||||
this.i = i;
|
||||
var ti = type.GetTypeInfo();
|
||||
this.@ref = (ti.IsClass || ti.IsInterface || ti.IsAbstract) ? false : true;
|
||||
}
|
||||
|
||||
public void EmitLoad()
|
||||
{
|
||||
if (@ref)
|
||||
{
|
||||
il.EmitLdarga(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
il.EmitLdarg(i);
|
||||
}
|
||||
}
|
||||
|
||||
public void EmitLdarg()
|
||||
{
|
||||
il.EmitLdarg(i);
|
||||
}
|
||||
|
||||
public void EmitLdarga()
|
||||
{
|
||||
il.EmitLdarga(i);
|
||||
}
|
||||
|
||||
public void EmitStore()
|
||||
{
|
||||
il.EmitStarg(i);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides optimized generation code and helpers.
|
||||
/// </summary>
|
||||
internal static class ILGeneratorExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads the local variable at a specific index onto the evaluation stack.
|
||||
/// </summary>
|
||||
public static void EmitLdloc(this ILGenerator il, int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
il.Emit(OpCodes.Ldloc_0);
|
||||
break;
|
||||
case 1:
|
||||
il.Emit(OpCodes.Ldloc_1);
|
||||
break;
|
||||
case 2:
|
||||
il.Emit(OpCodes.Ldloc_2);
|
||||
break;
|
||||
case 3:
|
||||
il.Emit(OpCodes.Ldloc_3);
|
||||
break;
|
||||
default:
|
||||
if (index <= 255)
|
||||
{
|
||||
il.Emit(OpCodes.Ldloc_S, (byte)index);
|
||||
}
|
||||
else
|
||||
{
|
||||
il.Emit(OpCodes.Ldloc, (short)index);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void EmitLdloc(this ILGenerator il, LocalBuilder local)
|
||||
{
|
||||
EmitLdloc(il, local.LocalIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pops the current value from the top of the evaluation stack and stores it in a the local variable list at a specified index.
|
||||
/// </summary>
|
||||
public static void EmitStloc(this ILGenerator il, int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
il.Emit(OpCodes.Stloc_0);
|
||||
break;
|
||||
case 1:
|
||||
il.Emit(OpCodes.Stloc_1);
|
||||
break;
|
||||
case 2:
|
||||
il.Emit(OpCodes.Stloc_2);
|
||||
break;
|
||||
case 3:
|
||||
il.Emit(OpCodes.Stloc_3);
|
||||
break;
|
||||
default:
|
||||
if (index <= 255)
|
||||
{
|
||||
il.Emit(OpCodes.Stloc_S, (byte)index);
|
||||
}
|
||||
else
|
||||
{
|
||||
il.Emit(OpCodes.Stloc, (short)index);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void EmitStloc(this ILGenerator il, LocalBuilder local)
|
||||
{
|
||||
EmitStloc(il, local.LocalIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the address of the local variable at a specific index onto the evaluation statck.
|
||||
/// </summary>
|
||||
public static void EmitLdloca(this ILGenerator il, int index)
|
||||
{
|
||||
if (index <= 255)
|
||||
{
|
||||
il.Emit(OpCodes.Ldloca_S, (byte)index);
|
||||
}
|
||||
else
|
||||
{
|
||||
il.Emit(OpCodes.Ldloca, (short)index);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EmitLdloca(this ILGenerator il, LocalBuilder local)
|
||||
{
|
||||
EmitLdloca(il, local.LocalIndex);
|
||||
}
|
||||
|
||||
public static void EmitTrue(this ILGenerator il)
|
||||
{
|
||||
EmitBoolean(il, true);
|
||||
}
|
||||
|
||||
public static void EmitFalse(this ILGenerator il)
|
||||
{
|
||||
EmitBoolean(il, false);
|
||||
}
|
||||
|
||||
public static void EmitBoolean(this ILGenerator il, bool value)
|
||||
{
|
||||
EmitLdc_I4(il, value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pushes a supplied value of type int32 onto the evaluation stack as an int32.
|
||||
/// </summary>
|
||||
public static void EmitLdc_I4(this ILGenerator il, int value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case -1:
|
||||
il.Emit(OpCodes.Ldc_I4_M1);
|
||||
break;
|
||||
case 0:
|
||||
il.Emit(OpCodes.Ldc_I4_0);
|
||||
break;
|
||||
case 1:
|
||||
il.Emit(OpCodes.Ldc_I4_1);
|
||||
break;
|
||||
case 2:
|
||||
il.Emit(OpCodes.Ldc_I4_2);
|
||||
break;
|
||||
case 3:
|
||||
il.Emit(OpCodes.Ldc_I4_3);
|
||||
break;
|
||||
case 4:
|
||||
il.Emit(OpCodes.Ldc_I4_4);
|
||||
break;
|
||||
case 5:
|
||||
il.Emit(OpCodes.Ldc_I4_5);
|
||||
break;
|
||||
case 6:
|
||||
il.Emit(OpCodes.Ldc_I4_6);
|
||||
break;
|
||||
case 7:
|
||||
il.Emit(OpCodes.Ldc_I4_7);
|
||||
break;
|
||||
case 8:
|
||||
il.Emit(OpCodes.Ldc_I4_8);
|
||||
break;
|
||||
default:
|
||||
if (value >= -128 && value <= 127)
|
||||
{
|
||||
il.Emit(OpCodes.Ldc_I4_S, (sbyte)value);
|
||||
}
|
||||
else
|
||||
{
|
||||
il.Emit(OpCodes.Ldc_I4, value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void EmitUnboxOrCast(this ILGenerator il, Type type)
|
||||
{
|
||||
if (type.GetTypeInfo().IsValueType)
|
||||
{
|
||||
il.Emit(OpCodes.Unbox_Any, type);
|
||||
}
|
||||
else
|
||||
{
|
||||
il.Emit(OpCodes.Castclass, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EmitBoxOrDoNothing(this ILGenerator il, Type type)
|
||||
{
|
||||
if (type.GetTypeInfo().IsValueType)
|
||||
{
|
||||
il.Emit(OpCodes.Box, type);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EmitLdarg(this ILGenerator il, int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
il.Emit(OpCodes.Ldarg_0);
|
||||
break;
|
||||
case 1:
|
||||
il.Emit(OpCodes.Ldarg_1);
|
||||
break;
|
||||
case 2:
|
||||
il.Emit(OpCodes.Ldarg_2);
|
||||
break;
|
||||
case 3:
|
||||
il.Emit(OpCodes.Ldarg_3);
|
||||
break;
|
||||
default:
|
||||
if (index <= 255)
|
||||
{
|
||||
il.Emit(OpCodes.Ldarg_S, (byte)index);
|
||||
}
|
||||
else
|
||||
{
|
||||
il.Emit(OpCodes.Ldarg, index);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void EmitLoadThis(this ILGenerator il)
|
||||
{
|
||||
EmitLdarg(il, 0);
|
||||
}
|
||||
|
||||
public static void EmitLdarga(this ILGenerator il, int index)
|
||||
{
|
||||
if (index <= 255)
|
||||
{
|
||||
il.Emit(OpCodes.Ldarga_S, (byte)index);
|
||||
}
|
||||
else
|
||||
{
|
||||
il.Emit(OpCodes.Ldarga, index);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EmitStarg(this ILGenerator il, int index)
|
||||
{
|
||||
if (index <= 255)
|
||||
{
|
||||
il.Emit(OpCodes.Starg_S, (byte)index);
|
||||
}
|
||||
else
|
||||
{
|
||||
il.Emit(OpCodes.Starg, index);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper for Pop op.
|
||||
/// </summary>
|
||||
public static void EmitPop(this ILGenerator il, int count)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
il.Emit(OpCodes.Pop);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EmitCall(this ILGenerator il, MethodInfo methodInfo)
|
||||
{
|
||||
if (methodInfo.IsFinal || !methodInfo.IsVirtual)
|
||||
{
|
||||
il.Emit(OpCodes.Call, methodInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
il.Emit(OpCodes.Callvirt, methodInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EmitLdfld(this ILGenerator il, FieldInfo fieldInfo)
|
||||
{
|
||||
il.Emit(OpCodes.Ldfld, fieldInfo);
|
||||
}
|
||||
|
||||
public static void EmitLdsfld(this ILGenerator il, FieldInfo fieldInfo)
|
||||
{
|
||||
il.Emit(OpCodes.Ldsfld, fieldInfo);
|
||||
}
|
||||
|
||||
public static void EmitRet(this ILGenerator il)
|
||||
{
|
||||
il.Emit(OpCodes.Ret);
|
||||
}
|
||||
|
||||
public static void EmitIntZeroReturn(this ILGenerator il)
|
||||
{
|
||||
il.EmitLdc_I4(0);
|
||||
il.Emit(OpCodes.Ret);
|
||||
}
|
||||
|
||||
public static void EmitNullReturn(this ILGenerator il)
|
||||
{
|
||||
il.Emit(OpCodes.Ldnull);
|
||||
il.Emit(OpCodes.Ret);
|
||||
}
|
||||
|
||||
public static void EmitULong(this ILGenerator il, ulong value)
|
||||
{
|
||||
il.Emit(OpCodes.Ldc_I8, unchecked((long)value));
|
||||
}
|
||||
|
||||
public static void EmitThrowNotimplemented(this ILGenerator il)
|
||||
{
|
||||
il.Emit(OpCodes.Newobj, typeof(System.NotImplementedException).GetTypeInfo().DeclaredConstructors.First(x => x.GetParameters().Length == 0));
|
||||
il.Emit(OpCodes.Throw);
|
||||
}
|
||||
|
||||
/// <summary>for var i = 0, i ..., i++ </summary>
|
||||
public static void EmitIncrementFor(this ILGenerator il, LocalBuilder conditionGreater, Action<LocalBuilder> emitBody)
|
||||
{
|
||||
var loopBegin = il.DefineLabel();
|
||||
var condtionLabel = il.DefineLabel();
|
||||
|
||||
// var i = 0
|
||||
var forI = il.DeclareLocal(typeof(int));
|
||||
il.EmitLdc_I4(0);
|
||||
il.EmitStloc(forI);
|
||||
il.Emit(OpCodes.Br, condtionLabel);
|
||||
|
||||
il.MarkLabel(loopBegin);
|
||||
emitBody(forI);
|
||||
|
||||
// i++
|
||||
il.EmitLdloc(forI);
|
||||
il.EmitLdc_I4(1);
|
||||
il.Emit(OpCodes.Add);
|
||||
il.EmitStloc(forI);
|
||||
|
||||
//// i < ***
|
||||
il.MarkLabel(condtionLabel);
|
||||
il.EmitLdloc(forI);
|
||||
il.EmitLdloc(conditionGreater);
|
||||
il.Emit(OpCodes.Blt, loopBegin);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f4704d47f3414974f88f9f21e3dc281c
|
||||
timeCreated: 1488099024
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
57
Assets/Scripts/MessagePack/Internal/ReflectionExtensions.cs
Normal file
57
Assets/Scripts/MessagePack/Internal/ReflectionExtensions.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#if !UNITY_WSA
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace MessagePack.Internal
|
||||
{
|
||||
internal static class ReflectionExtensions
|
||||
{
|
||||
public static bool IsNullable(this System.Reflection.TypeInfo type)
|
||||
{
|
||||
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(System.Nullable<>);
|
||||
}
|
||||
|
||||
public static bool IsPublic(this System.Reflection.TypeInfo type)
|
||||
{
|
||||
return type.IsPublic;
|
||||
}
|
||||
|
||||
public static bool IsAnonymous(this System.Reflection.TypeInfo type)
|
||||
{
|
||||
return type.GetCustomAttribute<CompilerGeneratedAttribute>() != null
|
||||
&& type.IsGenericType && type.Name.Contains("AnonymousType")
|
||||
&& (type.Name.StartsWith("<>") || type.Name.StartsWith("VB$"))
|
||||
&& (type.Attributes & TypeAttributes.NotPublic) == TypeAttributes.NotPublic;
|
||||
}
|
||||
|
||||
public static bool IsIndexer(this System.Reflection.PropertyInfo propertyInfo)
|
||||
{
|
||||
return propertyInfo.GetIndexParameters().Length > 0;
|
||||
}
|
||||
|
||||
#if NETSTANDARD
|
||||
|
||||
public static bool IsConstructedGenericType(this System.Reflection.TypeInfo type)
|
||||
{
|
||||
return type.AsType().IsConstructedGenericType;
|
||||
}
|
||||
|
||||
public static MethodInfo GetGetMethod(this PropertyInfo propInfo)
|
||||
{
|
||||
return propInfo.GetMethod;
|
||||
}
|
||||
|
||||
public static MethodInfo GetSetMethod(this PropertyInfo propInfo)
|
||||
{
|
||||
return propInfo.SetMethod;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e61aa0b2e2300ee4a91c0c699b1533a3
|
||||
timeCreated: 1487501810
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,232 @@
|
|||
using System;
|
||||
|
||||
namespace MessagePack.Internal
|
||||
{
|
||||
// Safe for multiple-read, single-write.
|
||||
internal class ThreadsafeTypeKeyHashTable<TValue>
|
||||
{
|
||||
Entry[] buckets;
|
||||
int size; // only use in writer lock
|
||||
|
||||
readonly object writerLock = new object();
|
||||
readonly float loadFactor;
|
||||
|
||||
// IEqualityComparer.Equals is overhead if key only Type, don't use it.
|
||||
// readonly IEqualityComparer<TKey> comparer;
|
||||
|
||||
public ThreadsafeTypeKeyHashTable(int capacity = 4, float loadFactor = 0.75f)
|
||||
{
|
||||
var tableSize = CalculateCapacity(capacity, loadFactor);
|
||||
this.buckets = new Entry[tableSize];
|
||||
this.loadFactor = loadFactor;
|
||||
}
|
||||
|
||||
public bool TryAdd(Type key, TValue value)
|
||||
{
|
||||
return TryAdd(key, _ => value); // create lambda capture
|
||||
}
|
||||
|
||||
public bool TryAdd(Type key, Func<Type, TValue> valueFactory)
|
||||
{
|
||||
TValue _;
|
||||
return TryAddInternal(key, valueFactory, out _);
|
||||
}
|
||||
|
||||
bool TryAddInternal(Type key, Func<Type, TValue> valueFactory, out TValue resultingValue)
|
||||
{
|
||||
lock (writerLock)
|
||||
{
|
||||
var nextCapacity = CalculateCapacity(size + 1, loadFactor);
|
||||
|
||||
if (buckets.Length < nextCapacity)
|
||||
{
|
||||
// rehash
|
||||
var nextBucket = new Entry[nextCapacity];
|
||||
for (int i = 0; i < buckets.Length; i++)
|
||||
{
|
||||
var e = buckets[i];
|
||||
while (e != null)
|
||||
{
|
||||
var newEntry = new Entry { Key = e.Key, Value = e.Value, Hash = e.Hash };
|
||||
AddToBuckets(nextBucket, key, newEntry, null, out resultingValue);
|
||||
e = e.Next;
|
||||
}
|
||||
}
|
||||
|
||||
// add entry(if failed to add, only do resize)
|
||||
var successAdd = AddToBuckets(nextBucket, key, null, valueFactory, out resultingValue);
|
||||
|
||||
// replace field(threadsafe for read)
|
||||
VolatileWrite(ref buckets, nextBucket);
|
||||
|
||||
if (successAdd) size++;
|
||||
return successAdd;
|
||||
}
|
||||
else
|
||||
{
|
||||
// add entry(insert last is thread safe for read)
|
||||
var successAdd = AddToBuckets(buckets, key, null, valueFactory, out resultingValue);
|
||||
if (successAdd) size++;
|
||||
return successAdd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool AddToBuckets(Entry[] buckets, Type newKey, Entry newEntryOrNull, Func<Type, TValue> valueFactory, out TValue resultingValue)
|
||||
{
|
||||
var h = (newEntryOrNull != null) ? newEntryOrNull.Hash : newKey.GetHashCode();
|
||||
if (buckets[h & (buckets.Length - 1)] == null)
|
||||
{
|
||||
if (newEntryOrNull != null)
|
||||
{
|
||||
resultingValue = newEntryOrNull.Value;
|
||||
VolatileWrite(ref buckets[h & (buckets.Length - 1)], newEntryOrNull);
|
||||
}
|
||||
else
|
||||
{
|
||||
resultingValue = valueFactory(newKey);
|
||||
VolatileWrite(ref buckets[h & (buckets.Length - 1)], new Entry { Key = newKey, Value = resultingValue, Hash = h });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var searchLastEntry = buckets[h & (buckets.Length - 1)];
|
||||
while (true)
|
||||
{
|
||||
if (searchLastEntry.Key == newKey)
|
||||
{
|
||||
resultingValue = searchLastEntry.Value;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (searchLastEntry.Next == null)
|
||||
{
|
||||
if (newEntryOrNull != null)
|
||||
{
|
||||
resultingValue = newEntryOrNull.Value;
|
||||
VolatileWrite(ref searchLastEntry.Next, newEntryOrNull);
|
||||
}
|
||||
else
|
||||
{
|
||||
resultingValue = valueFactory(newKey);
|
||||
VolatileWrite(ref searchLastEntry.Next, new Entry { Key = newKey, Value = resultingValue, Hash = h });
|
||||
}
|
||||
break;
|
||||
}
|
||||
searchLastEntry = searchLastEntry.Next;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryGetValue(Type key, out TValue value)
|
||||
{
|
||||
var table = buckets;
|
||||
var hash = key.GetHashCode();
|
||||
var entry = table[hash & table.Length - 1];
|
||||
|
||||
if (entry == null) goto NOT_FOUND;
|
||||
|
||||
if (entry.Key == key)
|
||||
{
|
||||
value = entry.Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
var next = entry.Next;
|
||||
while (next != null)
|
||||
{
|
||||
if (next.Key == key)
|
||||
{
|
||||
value = next.Value;
|
||||
return true;
|
||||
}
|
||||
next = next.Next;
|
||||
}
|
||||
|
||||
NOT_FOUND:
|
||||
value = default(TValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
public TValue GetOrAdd(Type key, Func<Type, TValue> valueFactory)
|
||||
{
|
||||
TValue v;
|
||||
if (TryGetValue(key, out v))
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
TryAddInternal(key, valueFactory, out v);
|
||||
return v;
|
||||
}
|
||||
|
||||
static int CalculateCapacity(int collectionSize, float loadFactor)
|
||||
{
|
||||
var initialCapacity = (int)(((float)collectionSize) / loadFactor);
|
||||
var capacity = 1;
|
||||
while (capacity < initialCapacity)
|
||||
{
|
||||
capacity <<= 1;
|
||||
}
|
||||
|
||||
if (capacity < 8)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
return capacity;
|
||||
}
|
||||
|
||||
static void VolatileWrite(ref Entry location, Entry value)
|
||||
{
|
||||
#if NETSTANDARD
|
||||
System.Threading.Volatile.Write(ref location, value);
|
||||
#elif UNITY_WSA || NET_4_6
|
||||
System.Threading.Volatile.Write(ref location, value);
|
||||
#else
|
||||
System.Threading.Thread.MemoryBarrier();
|
||||
location = value;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void VolatileWrite(ref Entry[] location, Entry[] value)
|
||||
{
|
||||
#if NETSTANDARD
|
||||
System.Threading.Volatile.Write(ref location, value);
|
||||
#elif UNITY_WSA || NET_4_6
|
||||
System.Threading.Volatile.Write(ref location, value);
|
||||
#else
|
||||
System.Threading.Thread.MemoryBarrier();
|
||||
location = value;
|
||||
#endif
|
||||
}
|
||||
|
||||
class Entry
|
||||
{
|
||||
public Type Key;
|
||||
public TValue Value;
|
||||
public int Hash;
|
||||
public Entry Next;
|
||||
|
||||
// debug only
|
||||
public override string ToString()
|
||||
{
|
||||
return Key + "(" + Count() + ")";
|
||||
}
|
||||
|
||||
int Count()
|
||||
{
|
||||
var count = 1;
|
||||
var n = this;
|
||||
while (n.Next != null)
|
||||
{
|
||||
count++;
|
||||
n = n.Next;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fb97ef9df4c7e264b911fac3efcc52de
|
||||
timeCreated: 1501832163
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
355
Assets/Scripts/MessagePack/Internal/TinyJsonReader.cs
Normal file
355
Assets/Scripts/MessagePack/Internal/TinyJsonReader.cs
Normal file
|
|
@ -0,0 +1,355 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace MessagePack
|
||||
{
|
||||
// simple, tiny JSON reader for MessagePackSerializer.FromJson.
|
||||
// this is simple, compact and enough fast but not optimized extremely.
|
||||
|
||||
internal enum TinyJsonToken
|
||||
{
|
||||
None,
|
||||
StartObject, // {
|
||||
EndObject, // }
|
||||
StartArray, // [
|
||||
EndArray, // ]
|
||||
Number, // -0~9
|
||||
String, // "___"
|
||||
True, // true
|
||||
False, // false
|
||||
Null, // null
|
||||
}
|
||||
|
||||
internal enum ValueType : byte
|
||||
{
|
||||
Null,
|
||||
True,
|
||||
False,
|
||||
Double,
|
||||
Long,
|
||||
ULong,
|
||||
Decimal,
|
||||
String
|
||||
}
|
||||
|
||||
internal class TinyJsonException : Exception
|
||||
{
|
||||
public TinyJsonException(string message) : base(message)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
internal class TinyJsonReader : IDisposable
|
||||
{
|
||||
readonly TextReader reader;
|
||||
readonly bool disposeInnerReader;
|
||||
StringBuilder reusableBuilder;
|
||||
|
||||
public TinyJsonToken TokenType { get; private set; }
|
||||
public ValueType ValueType { get; private set; }
|
||||
public double DoubleValue { get; private set; }
|
||||
public long LongValue { get; private set; }
|
||||
public ulong ULongValue { get; private set; }
|
||||
public decimal DecimalValue { get; private set; }
|
||||
public string StringValue { get; private set; }
|
||||
|
||||
public TinyJsonReader(TextReader reader, bool disposeInnerReader = true)
|
||||
{
|
||||
this.reader = reader;
|
||||
this.disposeInnerReader = disposeInnerReader;
|
||||
}
|
||||
|
||||
public bool Read()
|
||||
{
|
||||
ReadNextToken();
|
||||
ReadValue();
|
||||
return TokenType != TinyJsonToken.None;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (reader != null && disposeInnerReader)
|
||||
{
|
||||
reader.Dispose();
|
||||
}
|
||||
TokenType = TinyJsonToken.None;
|
||||
ValueType = ValueType.Null;
|
||||
}
|
||||
|
||||
void SkipWhiteSpace()
|
||||
{
|
||||
var c = reader.Peek();
|
||||
while (c != -1 && Char.IsWhiteSpace((char)c))
|
||||
{
|
||||
reader.Read();
|
||||
c = reader.Peek();
|
||||
}
|
||||
}
|
||||
|
||||
char ReadChar()
|
||||
{
|
||||
return (char)reader.Read();
|
||||
}
|
||||
|
||||
static bool IsWordBreak(char c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case ' ':
|
||||
case '{':
|
||||
case '}':
|
||||
case '[':
|
||||
case ']':
|
||||
case ',':
|
||||
case ':':
|
||||
case '\"':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void ReadNextToken()
|
||||
{
|
||||
SkipWhiteSpace();
|
||||
|
||||
var intChar = reader.Peek();
|
||||
if (intChar == -1)
|
||||
{
|
||||
TokenType = TinyJsonToken.None;
|
||||
return;
|
||||
}
|
||||
|
||||
var c = (char)intChar;
|
||||
switch (c)
|
||||
{
|
||||
case '{':
|
||||
TokenType = TinyJsonToken.StartObject;
|
||||
return;
|
||||
case '}':
|
||||
TokenType = TinyJsonToken.EndObject;
|
||||
return;
|
||||
case '[':
|
||||
TokenType = TinyJsonToken.StartArray;
|
||||
return;
|
||||
case ']':
|
||||
TokenType = TinyJsonToken.EndArray;
|
||||
return;
|
||||
case '"':
|
||||
TokenType = TinyJsonToken.String;
|
||||
return;
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
case '-':
|
||||
TokenType = TinyJsonToken.Number;
|
||||
return;
|
||||
case 't':
|
||||
TokenType = TinyJsonToken.True;
|
||||
return;
|
||||
case 'f':
|
||||
TokenType = TinyJsonToken.False;
|
||||
return;
|
||||
case 'n':
|
||||
TokenType = TinyJsonToken.Null;
|
||||
return;
|
||||
case ',':
|
||||
case ':':
|
||||
reader.Read();
|
||||
ReadNextToken();
|
||||
return;
|
||||
default:
|
||||
throw new TinyJsonException("Invalid String:" + c);
|
||||
}
|
||||
}
|
||||
|
||||
void ReadValue()
|
||||
{
|
||||
ValueType = ValueType.Null;
|
||||
|
||||
switch (TokenType)
|
||||
{
|
||||
case TinyJsonToken.None:
|
||||
break;
|
||||
case TinyJsonToken.StartObject:
|
||||
case TinyJsonToken.EndObject:
|
||||
case TinyJsonToken.StartArray:
|
||||
case TinyJsonToken.EndArray:
|
||||
reader.Read();
|
||||
break;
|
||||
case TinyJsonToken.Number:
|
||||
ReadNumber();
|
||||
break;
|
||||
case TinyJsonToken.String:
|
||||
ReadString();
|
||||
break;
|
||||
case TinyJsonToken.True:
|
||||
if (ReadChar() != 't') throw new TinyJsonException("Invalid Token");
|
||||
if (ReadChar() != 'r') throw new TinyJsonException("Invalid Token");
|
||||
if (ReadChar() != 'u') throw new TinyJsonException("Invalid Token");
|
||||
if (ReadChar() != 'e') throw new TinyJsonException("Invalid Token");
|
||||
ValueType = ValueType.True;
|
||||
break;
|
||||
case TinyJsonToken.False:
|
||||
if (ReadChar() != 'f') throw new TinyJsonException("Invalid Token");
|
||||
if (ReadChar() != 'a') throw new TinyJsonException("Invalid Token");
|
||||
if (ReadChar() != 'l') throw new TinyJsonException("Invalid Token");
|
||||
if (ReadChar() != 's') throw new TinyJsonException("Invalid Token");
|
||||
if (ReadChar() != 'e') throw new TinyJsonException("Invalid Token");
|
||||
ValueType = ValueType.False;
|
||||
break;
|
||||
case TinyJsonToken.Null:
|
||||
if (ReadChar() != 'n') throw new TinyJsonException("Invalid Token");
|
||||
if (ReadChar() != 'u') throw new TinyJsonException("Invalid Token");
|
||||
if (ReadChar() != 'l') throw new TinyJsonException("Invalid Token");
|
||||
if (ReadChar() != 'l') throw new TinyJsonException("Invalid Token");
|
||||
ValueType = ValueType.Null;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("InvalidTokenState:" + TokenType);
|
||||
}
|
||||
}
|
||||
|
||||
void ReadNumber()
|
||||
{
|
||||
StringBuilder numberWord;
|
||||
if (reusableBuilder == null)
|
||||
{
|
||||
reusableBuilder = new StringBuilder();
|
||||
numberWord = reusableBuilder;
|
||||
}
|
||||
else
|
||||
{
|
||||
numberWord = reusableBuilder;
|
||||
numberWord.Length = 0; // Clear
|
||||
}
|
||||
|
||||
var isDouble = false;
|
||||
var intChar = reader.Peek();
|
||||
while (intChar != -1 && !IsWordBreak((char)intChar))
|
||||
{
|
||||
var c = ReadChar();
|
||||
numberWord.Append(c);
|
||||
if (c == '.') isDouble = true;
|
||||
intChar = reader.Peek();
|
||||
}
|
||||
|
||||
var number = numberWord.ToString();
|
||||
if (isDouble)
|
||||
{
|
||||
double parsedDouble;
|
||||
Double.TryParse(number, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowExponent, System.Globalization.CultureInfo.InvariantCulture, out parsedDouble);
|
||||
ValueType = ValueType.Double;
|
||||
DoubleValue = parsedDouble;
|
||||
}
|
||||
else
|
||||
{
|
||||
long parsedInt;
|
||||
if (Int64.TryParse(number, NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out parsedInt))
|
||||
{
|
||||
ValueType = ValueType.Long;
|
||||
LongValue = parsedInt;
|
||||
return;
|
||||
}
|
||||
|
||||
ulong parsedULong;
|
||||
if (ulong.TryParse(number, NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out parsedULong))
|
||||
{
|
||||
ValueType = ValueType.ULong;
|
||||
ULongValue = parsedULong;
|
||||
return;
|
||||
}
|
||||
|
||||
Decimal parsedDecimal;
|
||||
if (decimal.TryParse(number, NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out parsedDecimal))
|
||||
{
|
||||
ValueType = ValueType.Decimal;
|
||||
DecimalValue = parsedDecimal;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ReadString()
|
||||
{
|
||||
reader.Read(); // skip ["]
|
||||
|
||||
StringBuilder sb;
|
||||
if (reusableBuilder == null)
|
||||
{
|
||||
reusableBuilder = new StringBuilder();
|
||||
sb = reusableBuilder;
|
||||
}
|
||||
else
|
||||
{
|
||||
sb = reusableBuilder;
|
||||
sb.Length = 0; // Clear
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (reader.Peek() == -1) throw new TinyJsonException("Invalid Json String");
|
||||
|
||||
var c = ReadChar();
|
||||
switch (c)
|
||||
{
|
||||
case '"': // endtoken
|
||||
goto END;
|
||||
case '\\': // escape character
|
||||
if (reader.Peek() == -1) throw new TinyJsonException("Invalid Json String");
|
||||
|
||||
c = ReadChar();
|
||||
switch (c)
|
||||
{
|
||||
case '"':
|
||||
case '\\':
|
||||
case '/':
|
||||
sb.Append(c);
|
||||
break;
|
||||
case 'b':
|
||||
sb.Append('\b');
|
||||
break;
|
||||
case 'f':
|
||||
sb.Append('\f');
|
||||
break;
|
||||
case 'n':
|
||||
sb.Append('\n');
|
||||
break;
|
||||
case 'r':
|
||||
sb.Append('\r');
|
||||
break;
|
||||
case 't':
|
||||
sb.Append('\t');
|
||||
break;
|
||||
case 'u':
|
||||
var hex = new char[4];
|
||||
hex[0] = ReadChar();
|
||||
hex[1] = ReadChar();
|
||||
hex[2] = ReadChar();
|
||||
hex[3] = ReadChar();
|
||||
sb.Append((char)Convert.ToInt32(new string(hex), 16));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default: // string
|
||||
sb.Append(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
END:
|
||||
ValueType = ValueType.String;
|
||||
StringValue = sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Scripts/MessagePack/Internal/TinyJsonReader.cs.meta
Normal file
12
Assets/Scripts/MessagePack/Internal/TinyJsonReader.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 757d9ab32ae519a45b020eab3038332c
|
||||
timeCreated: 1498137502
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
167
Assets/Scripts/MessagePack/Internal/UnsafeMemory.Low.cs
Normal file
167
Assets/Scripts/MessagePack/Internal/UnsafeMemory.Low.cs
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
#if NETSTANDARD
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace MessagePack.Internal
|
||||
{
|
||||
// for string key property name write optimization.
|
||||
|
||||
public static class UnsafeMemory
|
||||
{
|
||||
public static readonly bool Is32Bit = (IntPtr.Size == 4);
|
||||
}
|
||||
|
||||
public static partial class UnsafeMemory32
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw1(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(byte*)pDst = *(byte*)pSrc;
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw2(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(short*)pDst = *(short*)pSrc;
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw3(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(byte*)pDst = *(byte*)pSrc;
|
||||
*(short*)(pDst + 1) = *(short*)(pSrc + 1);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public static partial class UnsafeMemory64
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw1(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(byte*)pDst = *(byte*)pSrc;
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw2(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(short*)pDst = *(short*)pSrc;
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw3(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(byte*)pDst = *(byte*)pSrc;
|
||||
*(short*)(pDst + 1) = *(short*)(pSrc + 1);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw4(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw5(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 1) = *(int*)(pSrc + 1);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw6(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 2) = *(int*)(pSrc + 2);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw7(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 3) = *(int*)(pSrc + 3);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
12
Assets/Scripts/MessagePack/Internal/UnsafeMemory.Low.cs.meta
Normal file
12
Assets/Scripts/MessagePack/Internal/UnsafeMemory.Low.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 66d2fe79920989d4792d401c6a51e9b8
|
||||
timeCreated: 1504181170
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
894
Assets/Scripts/MessagePack/Internal/UnsafeMemory.cs
Normal file
894
Assets/Scripts/MessagePack/Internal/UnsafeMemory.cs
Normal file
|
|
@ -0,0 +1,894 @@
|
|||
#if NETSTANDARD
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace MessagePack.Internal
|
||||
{
|
||||
public static partial class UnsafeMemory32
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw4(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw5(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 1) = *(int*)(pSrc + 1);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw6(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 2) = *(int*)(pSrc + 2);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw7(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 3) = *(int*)(pSrc + 3);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw8(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw9(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 5) = *(int*)(pSrc + 5);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw10(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 6) = *(int*)(pSrc + 6);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw11(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 7) = *(int*)(pSrc + 7);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw12(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw13(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 9) = *(int*)(pSrc + 9);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw14(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 10) = *(int*)(pSrc + 10);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw15(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 11) = *(int*)(pSrc + 11);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw16(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 12) = *(int*)(pSrc + 12);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw17(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 12) = *(int*)(pSrc + 12);
|
||||
*(int*)(pDst + 13) = *(int*)(pSrc + 13);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw18(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 12) = *(int*)(pSrc + 12);
|
||||
*(int*)(pDst + 14) = *(int*)(pSrc + 14);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw19(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 12) = *(int*)(pSrc + 12);
|
||||
*(int*)(pDst + 15) = *(int*)(pSrc + 15);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw20(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 12) = *(int*)(pSrc + 12);
|
||||
*(int*)(pDst + 16) = *(int*)(pSrc + 16);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw21(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 12) = *(int*)(pSrc + 12);
|
||||
*(int*)(pDst + 16) = *(int*)(pSrc + 16);
|
||||
*(int*)(pDst + 17) = *(int*)(pSrc + 17);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw22(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 12) = *(int*)(pSrc + 12);
|
||||
*(int*)(pDst + 16) = *(int*)(pSrc + 16);
|
||||
*(int*)(pDst + 18) = *(int*)(pSrc + 18);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw23(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 12) = *(int*)(pSrc + 12);
|
||||
*(int*)(pDst + 16) = *(int*)(pSrc + 16);
|
||||
*(int*)(pDst + 19) = *(int*)(pSrc + 19);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw24(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 12) = *(int*)(pSrc + 12);
|
||||
*(int*)(pDst + 16) = *(int*)(pSrc + 16);
|
||||
*(int*)(pDst + 20) = *(int*)(pSrc + 20);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw25(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 12) = *(int*)(pSrc + 12);
|
||||
*(int*)(pDst + 16) = *(int*)(pSrc + 16);
|
||||
*(int*)(pDst + 20) = *(int*)(pSrc + 20);
|
||||
*(int*)(pDst + 21) = *(int*)(pSrc + 21);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw26(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 12) = *(int*)(pSrc + 12);
|
||||
*(int*)(pDst + 16) = *(int*)(pSrc + 16);
|
||||
*(int*)(pDst + 20) = *(int*)(pSrc + 20);
|
||||
*(int*)(pDst + 22) = *(int*)(pSrc + 22);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw27(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 12) = *(int*)(pSrc + 12);
|
||||
*(int*)(pDst + 16) = *(int*)(pSrc + 16);
|
||||
*(int*)(pDst + 20) = *(int*)(pSrc + 20);
|
||||
*(int*)(pDst + 23) = *(int*)(pSrc + 23);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw28(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 12) = *(int*)(pSrc + 12);
|
||||
*(int*)(pDst + 16) = *(int*)(pSrc + 16);
|
||||
*(int*)(pDst + 20) = *(int*)(pSrc + 20);
|
||||
*(int*)(pDst + 24) = *(int*)(pSrc + 24);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw29(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 12) = *(int*)(pSrc + 12);
|
||||
*(int*)(pDst + 16) = *(int*)(pSrc + 16);
|
||||
*(int*)(pDst + 20) = *(int*)(pSrc + 20);
|
||||
*(int*)(pDst + 24) = *(int*)(pSrc + 24);
|
||||
*(int*)(pDst + 25) = *(int*)(pSrc + 25);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw30(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 12) = *(int*)(pSrc + 12);
|
||||
*(int*)(pDst + 16) = *(int*)(pSrc + 16);
|
||||
*(int*)(pDst + 20) = *(int*)(pSrc + 20);
|
||||
*(int*)(pDst + 24) = *(int*)(pSrc + 24);
|
||||
*(int*)(pDst + 26) = *(int*)(pSrc + 26);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw31(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(int*)(pDst + 0) = *(int*)(pSrc + 0);
|
||||
*(int*)(pDst + 4) = *(int*)(pSrc + 4);
|
||||
*(int*)(pDst + 8) = *(int*)(pSrc + 8);
|
||||
*(int*)(pDst + 12) = *(int*)(pSrc + 12);
|
||||
*(int*)(pDst + 16) = *(int*)(pSrc + 16);
|
||||
*(int*)(pDst + 20) = *(int*)(pSrc + 20);
|
||||
*(int*)(pDst + 24) = *(int*)(pSrc + 24);
|
||||
*(int*)(pDst + 27) = *(int*)(pSrc + 27);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static partial class UnsafeMemory64
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw8(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw9(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 1) = *(long*)(pSrc + 1);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw10(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 2) = *(long*)(pSrc + 2);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw11(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 3) = *(long*)(pSrc + 3);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw12(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 4) = *(long*)(pSrc + 4);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw13(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 5) = *(long*)(pSrc + 5);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw14(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 6) = *(long*)(pSrc + 6);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw15(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 7) = *(long*)(pSrc + 7);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw16(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 8) = *(long*)(pSrc + 8);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw17(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 8) = *(long*)(pSrc + 8);
|
||||
*(long*)(pDst + 9) = *(long*)(pSrc + 9);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw18(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 8) = *(long*)(pSrc + 8);
|
||||
*(long*)(pDst + 10) = *(long*)(pSrc + 10);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw19(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 8) = *(long*)(pSrc + 8);
|
||||
*(long*)(pDst + 11) = *(long*)(pSrc + 11);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw20(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 8) = *(long*)(pSrc + 8);
|
||||
*(long*)(pDst + 12) = *(long*)(pSrc + 12);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw21(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 8) = *(long*)(pSrc + 8);
|
||||
*(long*)(pDst + 13) = *(long*)(pSrc + 13);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw22(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 8) = *(long*)(pSrc + 8);
|
||||
*(long*)(pDst + 14) = *(long*)(pSrc + 14);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw23(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 8) = *(long*)(pSrc + 8);
|
||||
*(long*)(pDst + 15) = *(long*)(pSrc + 15);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw24(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 8) = *(long*)(pSrc + 8);
|
||||
*(long*)(pDst + 16) = *(long*)(pSrc + 16);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw25(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 8) = *(long*)(pSrc + 8);
|
||||
*(long*)(pDst + 16) = *(long*)(pSrc + 16);
|
||||
*(long*)(pDst + 17) = *(long*)(pSrc + 17);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw26(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 8) = *(long*)(pSrc + 8);
|
||||
*(long*)(pDst + 16) = *(long*)(pSrc + 16);
|
||||
*(long*)(pDst + 18) = *(long*)(pSrc + 18);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw27(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 8) = *(long*)(pSrc + 8);
|
||||
*(long*)(pDst + 16) = *(long*)(pSrc + 16);
|
||||
*(long*)(pDst + 19) = *(long*)(pSrc + 19);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw28(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 8) = *(long*)(pSrc + 8);
|
||||
*(long*)(pDst + 16) = *(long*)(pSrc + 16);
|
||||
*(long*)(pDst + 20) = *(long*)(pSrc + 20);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw29(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 8) = *(long*)(pSrc + 8);
|
||||
*(long*)(pDst + 16) = *(long*)(pSrc + 16);
|
||||
*(long*)(pDst + 21) = *(long*)(pSrc + 21);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw30(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 8) = *(long*)(pSrc + 8);
|
||||
*(long*)(pDst + 16) = *(long*)(pSrc + 16);
|
||||
*(long*)(pDst + 22) = *(long*)(pSrc + 22);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe int WriteRaw31(ref byte[] dst, int dstOffset, byte[] src)
|
||||
{
|
||||
MessagePackBinary.EnsureCapacity(ref dst, dstOffset, src.Length);
|
||||
|
||||
fixed (byte* pSrc = &src[0])
|
||||
fixed (byte* pDst = &dst[dstOffset])
|
||||
{
|
||||
*(long*)(pDst + 0) = *(long*)(pSrc + 0);
|
||||
*(long*)(pDst + 8) = *(long*)(pSrc + 8);
|
||||
*(long*)(pDst + 16) = *(long*)(pSrc + 16);
|
||||
*(long*)(pDst + 23) = *(long*)(pSrc + 23);
|
||||
}
|
||||
|
||||
return src.Length;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
12
Assets/Scripts/MessagePack/Internal/UnsafeMemory.cs.meta
Normal file
12
Assets/Scripts/MessagePack/Internal/UnsafeMemory.cs.meta
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d0e5250baf56d1141abd42ed1ba1b6f6
|
||||
timeCreated: 1504181170
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue