private static TKey GetKey(bool isNativeType, byte keyType, BssmapAnalysisStack stack, byte valueByteCount) { if (keyType != staticKeyResolver.KeyType && isNativeType != staticKeyResolver.KeyIsNativeType) { return(BssomSerializationOperationException.UnexpectedCodeRead <TKey>()); } return(staticKeyResolver.ReadMap2Key(stack.ToUlongs((byte)valueByteCount))); }
public Enumerator(BssMapObjMarshalReader <TKey, TValue> bssReader) { bssmapReader = bssReader; bssaStack = new BssmapAnalysisStack(bssmapReader.Paras.MapHead.MaxDepth); count = bssmapReader.Paras.MapHead.ElementCount; state = AutomateState.ReadBranch; pos = 0; Current = default; }
public static unsafe string GetSchemaString(ref BssomReader reader) { long positionWithOutMap2TypeHead(ref BssomReader r) { return(r.Position - 1); } MapSchemaStringBuilder msb = new MapSchemaStringBuilder(); BssMapHead head = BssMapHead.Read(ref reader); byte nextKeyByteCount = 0; BssMapRouteToken t = default; int count = head.ElementCount; BssmapAnalysisStack stack = new BssmapAnalysisStack(head.MaxDepth); AutomateState state = AutomateState.ReadBranch; switch (state) { case AutomateState.ReadBranch: { t = reader.ReadMapToken(); msb.AppendRouteToken(positionWithOutMap2TypeHead(ref reader) - 1, t); stack.PushToken(t); if (t >= BssMapRouteToken.EqualNext1 && t <= BssMapRouteToken.EqualNext8 || t >= BssMapRouteToken.EqualLast1 && t <= BssMapRouteToken.EqualLast8) { if (t >= BssMapRouteToken.EqualNext1 && t <= BssMapRouteToken.EqualNext8) { long position = positionWithOutMap2TypeHead(ref reader); reader.EnsureType(BssomBinaryPrimitives.FixUInt16); msb.AppendNextOff(position, reader.ReadUInt16WithOutTypeHead()); } nextKeyByteCount = BssMapRouteTokenHelper.GetEqualNextOrLastByteCount(t); goto case AutomateState.ReadKey; } else if (t == BssMapRouteToken.EqualNextN || t == BssMapRouteToken.EqualLastN) { if (t == BssMapRouteToken.EqualNextN) { long position = positionWithOutMap2TypeHead(ref reader); reader.EnsureType(BssomBinaryPrimitives.FixUInt16); msb.AppendNextOff(position, reader.ReadUInt16WithOutTypeHead()); } ulong uint64Val = reader.ReadUInt64WithOutTypeHead(); msb.AppendUInt64Val(positionWithOutMap2TypeHead(ref reader) - 8, uint64Val); goto case AutomateState.ReadBranch; } else if (t >= BssMapRouteToken.LessThen1 && t <= BssMapRouteToken.LessThen8) { long position = positionWithOutMap2TypeHead(ref reader); reader.EnsureType(BssomBinaryPrimitives.FixUInt16); msb.AppendNextOff(position, reader.ReadUInt16WithOutTypeHead()); nextKeyByteCount = BssMapRouteTokenHelper.GetLessThenByteCount(t); position = positionWithOutMap2TypeHead(ref reader); if (nextKeyByteCount == 8) { msb.AppendUInt64Val(position, reader.ReadUInt64WithOutTypeHead()); } else { msb.AppendUInt64Val(position, ref reader.BssomBuffer.ReadRef(nextKeyByteCount), nextKeyByteCount); reader.BssomBuffer.SeekWithOutVerify(nextKeyByteCount, BssomSeekOrgin.Current); } goto case AutomateState.ReadBranch; } else if (t == BssMapRouteToken.LessElse) { goto case AutomateState.ReadBranch; } else { throw BssomSerializationOperationException.UnexpectedCodeRead((byte)t, reader.Position); } } case AutomateState.ReadKey: { if (nextKeyByteCount == 8) { ulong uint64Val = reader.ReadUInt64WithOutTypeHead(); msb.AppendUInt64Val(positionWithOutMap2TypeHead(ref reader) - 8, uint64Val); } else { //Read Raw(lessthan 8 byte) ref byte ref1 = ref reader.BssomBuffer.ReadRef(nextKeyByteCount); msb.AppendUInt64Val(positionWithOutMap2TypeHead(ref reader) - nextKeyByteCount, ref ref1, nextKeyByteCount); reader.BssomBuffer.SeekWithOutVerify(nextKeyByteCount, BssomSeekOrgin.Current); } long position = positionWithOutMap2TypeHead(ref reader); byte keyType = reader.ReadBssomType(); if (keyType == BssomType.NativeCode) { msb.AppendKeyType(position, true, reader.ReadBssomType()); } else { msb.AppendKeyType(position, false, keyType); } position = positionWithOutMap2TypeHead(ref reader); reader.EnsureType(BssomBinaryPrimitives.FixUInt32); msb.AppendValOffset(position, reader.ReadUInt32WithOutTypeHead()); count--; goto case AutomateState.ReadChildren; }
private static TKey GetObjectKey(bool isNativeType, byte keyType, BssmapAnalysisStack stack, byte valueByteCount) { IBssMapKeyResolver convert = BssMapKeyResolverProvider.GetAndVertiyBssMapKeyResolver(isNativeType, keyType); return((TKey)convert.ReadMap2Key(stack.ToUlongs((byte)valueByteCount))); }