-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
456b1ca
commit 404f314
Showing
6 changed files
with
187 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Antlr4.Runtime.Misc; | ||
using Antlr4.Runtime; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace ProtoBuf.Logic | ||
{ | ||
public static class ParserRuleContextExtensions | ||
{ | ||
[return: NotNullIfNotNull(nameof(context))] | ||
public static string? GetFullText(this ParserRuleContext? context) | ||
{ | ||
if (context==null) | ||
{ | ||
return null; | ||
} | ||
if (context.Start == null || context.Stop == null || context.Start.StartIndex < 0 || context.Stop.StopIndex < 0) | ||
return context.GetText(); // Fallback | ||
|
||
return context.Start.InputStream.GetText(Interval.Of(context.Start.StartIndex, context.Stop.StopIndex)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Google.Protobuf; | ||
using Microsoft.AspNetCore.Components.Forms; | ||
using ProtoBuf.Logic; | ||
using static ProtoBuf.Antlr.Protobuf3Parser; | ||
|
||
namespace ProtoBufViewer.Blazor.Pages | ||
{ | ||
public partial class Index | ||
{ | ||
private const string DefaultDragClass = "relative rounded-lg border-2 border-dashed pa-4 mt-4 mud-width-full mud-height-full z-10"; | ||
private IBrowserFile? ProtoFile; | ||
private IBrowserFile? ProtoBinFile; | ||
HashSet<MessageViewModel> Messages { get; } = new(); | ||
MessageViewModel? SelectedMessage { get; set; } | ||
ProtoContext? ParseResult { get; set; } | ||
|
||
List<ProtoType>? TypedMessages { get; set; } | ||
|
||
private async Task MessageFileChanged(IBrowserFile file) | ||
{ | ||
ProtoFile = file; | ||
Messages.Clear(); | ||
using var ms = new MemoryStream(); | ||
await file.OpenReadStream().CopyToAsync(ms); | ||
ms.Position = 0; | ||
ParseResult = ProtoParser.ParseFile(ms); | ||
var visitor = new MessageViewModel.Visitor(); | ||
visitor.Visit(ParseResult); | ||
foreach (var m in visitor.Messages.Where(x => x.Parent == null)) | ||
{ | ||
Messages.Add(m); | ||
} | ||
} | ||
|
||
private async Task BinFilesChanged(IBrowserFile file) | ||
{ | ||
ProtoBinFile = file; | ||
using var ms = new MemoryStream(); | ||
await file.OpenReadStream().CopyToAsync(ms); | ||
ms.Position = 0; | ||
using var coded = CodedInputStream.CreateWithLimits(ms, int.MaxValue, int.MaxValue); | ||
var decoder = new TypedMessageDecoder(); | ||
var result = decoder.Parse(coded, ParseResult, SelectedMessage.MessageDefContext); | ||
TypedMessages = new(result); | ||
} | ||
} | ||
} |
Oops, something went wrong.