stringを返さず直接byte配列を渡すように変更

This commit is contained in:
momoma-null
2026-06-10 16:08:01 +09:00
committed by hadashiA
parent 5860a7940e
commit 38434ee9f9
5 changed files with 37 additions and 12 deletions

View File

@@ -2,7 +2,11 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
<<<<<<< HEAD:Packages/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs
using UniJSON;
=======
using System.Text;
>>>>>>> bce3a9b5c (stringを返さず直接byte配列を渡すように変更):Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs
using Unity.Collections;
namespace UniGLTF
@@ -33,7 +37,11 @@ namespace UniGLTF
/// JSON chunk ToString
/// > This chunk MUST be the very first chunk of Binary glTF asset
/// </summary>
<<<<<<< HEAD:Packages/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs
public string Json => _jsonString ??= _utf8JsonString.ToString();
=======
public string Json => _json ?? Encoding.UTF8.GetString(_jsonBytes.Span);
>>>>>>> bce3a9b5c (stringを返さず直接byte配列を渡すように変更):Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs
/// <summary>
/// GLTF parsed from JSON chunk
@@ -73,6 +81,7 @@ namespace UniGLTF
/// <returns></returns>
Dictionary<string, NativeArray<byte>> _UriCache = new Dictionary<string, NativeArray<byte>>();
<<<<<<< HEAD:Packages/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs
/// <summary>
/// json string in utf8
/// </summary>
@@ -106,6 +115,15 @@ namespace UniGLTF
{
TargetPath = targetPath;
_utf8JsonString = jsonString;
=======
private string _json;
readonly ReadOnlyMemory<byte> _jsonBytes;
public GltfData(string targetPath, ReadOnlyMemory<byte> jsonBytes, glTF gltf, IReadOnlyList<GlbChunk> chunks, IStorage storage, MigrationFlags migrationFlags)
{
TargetPath = targetPath;
_jsonBytes = jsonBytes;
>>>>>>> bce3a9b5c (stringを返さず直接byte配列を渡すように変更):Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs
GLTF = gltf;
Chunks = chunks;
_storage = storage;
@@ -136,7 +154,7 @@ namespace UniGLTF
{
return new GltfData(
string.Empty,
string.Empty,
Array.Empty<byte>(),
gltf,
new List<GlbChunk>
{

View File

@@ -35,7 +35,7 @@ namespace UniGLTF
var jsonBytes = chunks[0].Bytes;
return ParseGltf(
path,
Encoding.UTF8.GetString(jsonBytes.Span),
jsonBytes,
chunks,
default,
new MigrationFlags()
@@ -79,6 +79,11 @@ namespace UniGLTF
}
internal static GltfData ParseGltf(string path, Utf8String json, IReadOnlyList<GlbChunk> chunks, IStorage storage, MigrationFlags migrationFlags)
{
return ParseGltf(path, json.Bytes, chunks, storage, migrationFlags);
}
public static GltfData ParseGltf(string path, ReadOnlyMemory<byte> json, IReadOnlyList<GlbChunk> chunks, IStorage storage, MigrationFlags migrationFlags)
{
var jsonNode = json.ParseAsJson();
var GLTF = GltfDeserializer.Deserialize(jsonNode);

View File

@@ -21,5 +21,9 @@ namespace UniJSON
{
return JsonParser.Parse(new Utf8String(bytes));
}
public static JsonNode ParseAsJson(this ReadOnlyMemory<byte> bytes)
{
return JsonParser.Parse(new Utf8String(bytes));
}
}
}

View File

@@ -8,11 +8,9 @@ namespace UniJSON
{
public static readonly System.Text.Encoding Encoding = new System.Text.UTF8Encoding(false);
public readonly ReadOnlyMemory<Byte> Bytes;
public int ByteLength
{
get { return Bytes.Length; }
}
public readonly ReadOnlyMemory<byte> Bytes;
public int ByteLength => Bytes.Length;
public Utf8Iterator GetIterator()
{
@@ -59,17 +57,17 @@ namespace UniJSON
public Utf8String(ArraySegment<Byte> bytes)
{
Bytes = new ReadOnlyMemory<Byte>(bytes.Array, bytes.Offset, bytes.Count);
Bytes = bytes;
}
public Utf8String(Byte[] bytes, int offset, int count)
{
Bytes = new ReadOnlyMemory<Byte>(bytes, offset, count);
Bytes = bytes.AsMemory(offset,count);
}
public Utf8String(Byte[] bytes)
{
Bytes = new ReadOnlyMemory<Byte>(bytes);
Bytes = bytes;
}
public static Utf8String From(string src)
@@ -117,7 +115,7 @@ namespace UniJSON
return new Utf8String(bytes);
}
public ReadOnlySpan<byte> AsSpan() => Bytes.AsSpan();
public ReadOnlySpan<byte> AsSpan() => Bytes.Span;
public override string ToString()
{

View File

@@ -232,7 +232,7 @@ namespace UniGLTF
{
return new GltfData(
string.Empty,
string.Empty,
Array.Empty<byte>(),
gltf,
new List<GlbChunk>(),
default,