Esempio n. 1
0
 public static Offset <SyncIDList> CreateSyncIDList(FlatBufferBuilder builder,
                                                    ushort length           = 0,
                                                    VectorOffset listOffset = default(VectorOffset))
 {
     builder.StartObject(2);
     SyncIDList.AddList(builder, listOffset);
     SyncIDList.AddLength(builder, length);
     return(SyncIDList.EndSyncIDList(builder));
 }
Esempio n. 2
0
        public static Dictionary <int, string> DeserializeSyncIDList(byte[] data)
        {
            ByteBuffer b      = new ByteBuffer(data);
            var        list   = SyncIDList.GetRootAsSyncIDList(b);
            int        length = list.Length;

            Debug.Log(list.ListLength);
            Dictionary <int, string> results = new Dictionary <int, string>();

            if (length != list.ListLength)
            {
                return(results);
            }
            for (int index = 0; index < length; index++)
            {
                if (list.List(index).HasValue)
                {
                    SyncObjectID soid = list.List(index).Value;
                    results.Add((int)soid.Id, soid.Name);
                }
            }
            return(results);
        }
Esempio n. 3
0
        public static byte[] SerializeSyncIDList(List <string> syncObjects)
        {
            var builder = new FlatBufferBuilder(1);

            int length = syncObjects.Count;

            StringOffset[] names = new StringOffset[length];

            for (int index = 0; index < length; index++)
            {
                names[index] = builder.CreateString(syncObjects[index]);
            }

            Offset <SyncObjectID>[] off = new Offset <SyncObjectID> [length];
            for (int index = 0; index < length; index++)
            {
                SyncObjectID.StartSyncObjectID(builder);
                SyncObjectID.AddId(builder, (ushort)index);
                SyncObjectID.AddName(builder, names[index]);
                off[index] = SyncObjectID.EndSyncObjectID(builder);
            }

            var ids = SyncIDList.CreateListVector(builder, off);


            SyncIDList.StartSyncIDList(builder);
            SyncIDList.AddLength(builder, (ushort)length);
            SyncIDList.AddList(builder, ids);
            var list = SyncIDList.EndSyncIDList(builder);

            SyncIDList.FinishSyncIDListBuffer(builder, list);
            using (var ms = new MemoryStream(builder.DataBuffer.Data, builder.DataBuffer.Position, builder.Offset))
            {
                var data = ms.ToArray();
                return(data);
            }
        }
Esempio n. 4
0
 public static SyncIDList GetRootAsSyncIDList(ByteBuffer _bb, SyncIDList obj)
 {
     return(obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }