flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

Read error

Open lcals opened this issue 7 years ago • 5 comments

C# For Unity fbs namespace Scripts.CSharpCode.FlatBuffers; table GameKeyIconCfg { assetName:string(key); bundleName:string; } table GameTableIconCfg{ icon_cfg:[GameKeyIconCfg];
} root_type GameTableIconCfg;

Json

{ "icon_cfg": [ { "assetName": "crossbow", "bundleName": "base_ui" }, { "assetName": "icon_0", "bundleName": "base_ui" }, { "assetName": "background_1", "bundleName": "background_1" }, { "assetName": "background_2", "bundleName": "background_2" }, { "assetName": "background_3", "bundleName": "background_3" }, { "assetName": "background_4", "bundleName": "background_4" } ] }

var _gameTableIconCfg = GameTableIconCfg.GetRootAsGameTableIconCfg(buffer); var iconCfgLength = _gameTableIconCfg.IconCfgLength; var t1 = _gameTableIconCfg.IconCfg(0)?.AssetName; var t2 = _gameTableIconCfg.IconCfgByKey("crossbow")?.AssetName;

iconCfgLength== 6 t1="crossbow" t2=null

ByKey only works if the vector has been sorted, it will likely not find elements if it hasn't been sorted.

Is my use wrong?

lcals avatar Oct 03 '19 17:10 lcals

That looks to be the same problem as https://github.com/google/flatbuffers/issues/5424 where flatc doesn't sort the JSON. It works if instead you construct the data in code, since that will have a CreateSortedVectorOfGameKeyIconCfg function.

aardappel avatar Oct 03 '19 17:10 aardappel

Request to add JSON sort to flatc. I have too many jsons. I don't know C++.

lcals avatar Oct 04 '19 03:10 lcals

Working on it..

aardappel avatar Oct 07 '19 18:10 aardappel

Ok, this should implement JSON sort: https://github.com/google/flatbuffers/commit/32f47ad24727c7af17996aed5e48840e9139b2f5

Let me know if it works for you.

aardappel avatar Oct 10 '19 23:10 aardappel

This issue is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days.

github-actions[bot] avatar Jun 12 '20 20:06 github-actions[bot]