11a161a8333ec1fa382a06485b7ffad955c001151Wouter van Oortmerssen/* 21a161a8333ec1fa382a06485b7ffad955c001151Wouter van Oortmerssen * Copyright 2016 Google Inc. All rights reserved. 31a161a8333ec1fa382a06485b7ffad955c001151Wouter van Oortmerssen * 41a161a8333ec1fa382a06485b7ffad955c001151Wouter van Oortmerssen * Licensed under the Apache License, Version 2.0 (the "License"); 51a161a8333ec1fa382a06485b7ffad955c001151Wouter van Oortmerssen * you may not use this file except in compliance with the License. 61a161a8333ec1fa382a06485b7ffad955c001151Wouter van Oortmerssen * You may obtain a copy of the License at 71a161a8333ec1fa382a06485b7ffad955c001151Wouter van Oortmerssen * 81a161a8333ec1fa382a06485b7ffad955c001151Wouter van Oortmerssen * http://www.apache.org/licenses/LICENSE-2.0 91a161a8333ec1fa382a06485b7ffad955c001151Wouter van Oortmerssen * 101a161a8333ec1fa382a06485b7ffad955c001151Wouter van Oortmerssen * Unless required by applicable law or agreed to in writing, software 111a161a8333ec1fa382a06485b7ffad955c001151Wouter van Oortmerssen * distributed under the License is distributed on an "AS IS" BASIS, 121a161a8333ec1fa382a06485b7ffad955c001151Wouter van Oortmerssen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131a161a8333ec1fa382a06485b7ffad955c001151Wouter van Oortmerssen * See the License for the specific language governing permissions and 141a161a8333ec1fa382a06485b7ffad955c001151Wouter van Oortmerssen * limitations under the License. 151a161a8333ec1fa382a06485b7ffad955c001151Wouter van Oortmerssen */ 161a161a8333ec1fa382a06485b7ffad955c001151Wouter van Oortmerssen 179d66af6efc0498e90e2757659761ae0c4f797eeeevolutionalnamespace FlatBuffers.Test 189d66af6efc0498e90e2757659761ae0c4f797eeeevolutional{ 199d66af6efc0498e90e2757659761ae0c4f797eeeevolutional /// <summary> 209d66af6efc0498e90e2757659761ae0c4f797eeeevolutional /// A test Table object that gives easy access to the slot data 219d66af6efc0498e90e2757659761ae0c4f797eeeevolutional /// </summary> 2252ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen internal struct TestTable 239d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 2452ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen Table t; 2552ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen 269d66af6efc0498e90e2757659761ae0c4f797eeeevolutional public TestTable(ByteBuffer bb, int pos) 279d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 2852ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen t.bb = bb; 2952ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen t.bb_pos = pos; 309d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 319d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 329d66af6efc0498e90e2757659761ae0c4f797eeeevolutional public bool GetSlot(int slot, bool def) 339d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 3452ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen var off = t.__offset(slot); 359d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 369d66af6efc0498e90e2757659761ae0c4f797eeeevolutional if (off == 0) 379d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 389d66af6efc0498e90e2757659761ae0c4f797eeeevolutional return def; 399d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 4052ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen return t.bb.GetSbyte(t.bb_pos + off) != 0; 419d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 429d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 439d66af6efc0498e90e2757659761ae0c4f797eeeevolutional public sbyte GetSlot(int slot, sbyte def) 449d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 4552ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen var off = t.__offset(slot); 469d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 479d66af6efc0498e90e2757659761ae0c4f797eeeevolutional if (off == 0) 489d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 499d66af6efc0498e90e2757659761ae0c4f797eeeevolutional return def; 509d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 5152ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen return t.bb.GetSbyte(t.bb_pos + off); 529d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 539d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 549d66af6efc0498e90e2757659761ae0c4f797eeeevolutional public byte GetSlot(int slot, byte def) 559d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 5652ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen var off = t.__offset(slot); 579d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 589d66af6efc0498e90e2757659761ae0c4f797eeeevolutional if (off == 0) 599d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 609d66af6efc0498e90e2757659761ae0c4f797eeeevolutional return def; 619d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 6252ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen return t.bb.Get(t.bb_pos + off); 639d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 649d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 659d66af6efc0498e90e2757659761ae0c4f797eeeevolutional public short GetSlot(int slot, short def) 669d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 6752ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen var off = t.__offset(slot); 689d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 699d66af6efc0498e90e2757659761ae0c4f797eeeevolutional if (off == 0) 709d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 719d66af6efc0498e90e2757659761ae0c4f797eeeevolutional return def; 729d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 7352ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen return t.bb.GetShort(t.bb_pos + off); 749d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 759d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 769d66af6efc0498e90e2757659761ae0c4f797eeeevolutional public ushort GetSlot(int slot, ushort def) 779d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 7852ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen var off = t.__offset(slot); 799d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 809d66af6efc0498e90e2757659761ae0c4f797eeeevolutional if (off == 0) 819d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 829d66af6efc0498e90e2757659761ae0c4f797eeeevolutional return def; 839d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 8452ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen return t.bb.GetUshort(t.bb_pos + off); 859d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 869d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 879d66af6efc0498e90e2757659761ae0c4f797eeeevolutional public int GetSlot(int slot, int def) 889d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 8952ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen var off = t.__offset(slot); 909d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 919d66af6efc0498e90e2757659761ae0c4f797eeeevolutional if (off == 0) 929d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 939d66af6efc0498e90e2757659761ae0c4f797eeeevolutional return def; 949d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 9552ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen return t.bb.GetInt(t.bb_pos + off); 969d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 979d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 989d66af6efc0498e90e2757659761ae0c4f797eeeevolutional public uint GetSlot(int slot, uint def) 999d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 10052ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen var off = t.__offset(slot); 1019d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 1029d66af6efc0498e90e2757659761ae0c4f797eeeevolutional if (off == 0) 1039d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 1049d66af6efc0498e90e2757659761ae0c4f797eeeevolutional return def; 1059d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 10652ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen return t.bb.GetUint(t.bb_pos + off); 1079d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 1089d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 1099d66af6efc0498e90e2757659761ae0c4f797eeeevolutional public long GetSlot(int slot, long def) 1109d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 11152ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen var off = t.__offset(slot); 1129d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 1139d66af6efc0498e90e2757659761ae0c4f797eeeevolutional if (off == 0) 1149d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 1159d66af6efc0498e90e2757659761ae0c4f797eeeevolutional return def; 1169d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 11752ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen return t.bb.GetLong(t.bb_pos + off); 1189d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 1199d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 1209d66af6efc0498e90e2757659761ae0c4f797eeeevolutional public ulong GetSlot(int slot, ulong def) 1219d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 12252ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen var off = t.__offset(slot); 1239d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 1249d66af6efc0498e90e2757659761ae0c4f797eeeevolutional if (off == 0) 1259d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 1269d66af6efc0498e90e2757659761ae0c4f797eeeevolutional return def; 1279d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 12852ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen return t.bb.GetUlong(t.bb_pos + off); 1299d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 1309d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 1319d66af6efc0498e90e2757659761ae0c4f797eeeevolutional public float GetSlot(int slot, float def) 1329d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 13352ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen var off = t.__offset(slot); 1349d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 1359d66af6efc0498e90e2757659761ae0c4f797eeeevolutional if (off == 0) 1369d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 1379d66af6efc0498e90e2757659761ae0c4f797eeeevolutional return def; 1389d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 13952ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen return t.bb.GetFloat(t.bb_pos + off); 1409d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 1419d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 1429d66af6efc0498e90e2757659761ae0c4f797eeeevolutional public double GetSlot(int slot, double def) 1439d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 14452ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen var off = t.__offset(slot); 1459d66af6efc0498e90e2757659761ae0c4f797eeeevolutional 1469d66af6efc0498e90e2757659761ae0c4f797eeeevolutional if (off == 0) 1479d66af6efc0498e90e2757659761ae0c4f797eeeevolutional { 1489d66af6efc0498e90e2757659761ae0c4f797eeeevolutional return def; 1499d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 15052ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen return t.bb.GetDouble(t.bb_pos + off); 1519d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 1529d66af6efc0498e90e2757659761ae0c4f797eeeevolutional } 15352ca75506abd82b5616bdef4d28e9535262c1d65Wouter van Oortmerssen} 154