internal void EnsureMapToken(BssMapRouteToken token) { BssMapRouteToken t = ReadOne <BssMapRouteToken>(); if (t != token) { BssomSerializationOperationException.UnexpectedCodeRead((byte)t, Position); } }
public static byte GetLessThenByteCount(BssMapRouteToken equalNext) { DEBUG.Assert(equalNext >= BssMapRouteToken.LessThen1 && equalNext <= BssMapRouteToken.LessThen8); byte t = (byte)equalNext; if (t > 20) { return((byte)(t - 20)); } return(t); }
public static byte GetEqualNextOrLastByteCount(BssMapRouteToken equalNext) { DEBUG.Assert(equalNext >= BssMapRouteToken.EqualNext1 && equalNext <= BssMapRouteToken.EqualNext8 || equalNext >= BssMapRouteToken.EqualLast1 && equalNext <= BssMapRouteToken.EqualLast8); byte t = (byte)equalNext; if (t > 10) { return((byte)(t - 10)); } return(t); }
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; }
public void AppendRouteToken(long position, BssMapRouteToken value) { sb.Append($"[{position.ToString()}]"); sb.Append(value.ToString()); sb.Append(" "); }
private void WriteMapToken(BssMapRouteToken token) { AdvanceSize(1); }
private void WriteMapToken(BssMapRouteToken token) { writer.WriteWithOutTypeHead((byte)token); }
public void PushToken(BssMapRouteToken branchToken) { _tokens.Push(branchToken); }