Example #1
0
        public Dictionary <string, Tdf> Decode()
        {
            while (_stream.Position != _stream.Length)
            {
                Tdf tdf = ReadTdf();

                if (tdf != null)
                {
                    _result.Add(tdf.label, tdf);
                }
            }

            /*
             * string result = "";
             *
             * _result.ForEach(delegate(Tdf item)
             * {
             *  result += string.Format("{0}({1}), ", item.label, item.type);
             *
             *  Console.WriteLine(string.Format("{0}: {1}", item.label, item.type));
             * });
             *
             * //Console.WriteLine(result);
             */

            return(_result);
        }
Example #2
0
        /// <summary>
        /// Encodes a Tdf.
        /// </summary>
        /// <param name="tdf">The input Tdf.</param>
        public void WriteTdf(Tdf tdf)
        {
            // write label
            WriteLabel(tdf.label);

            // write type
            _stream.WriteByte((byte)tdf.type);

            switch (tdf.type)
            {
            /* case TdfBaseType.TDF_TYPE_MIN:
             *  WriteTdfMin((TdfMin)tdf);
             *  break; */

            case TdfBaseType.TDF_TYPE_INTEGER:
                WriteTdfInteger((TdfInteger)tdf);
                break;

            case TdfBaseType.TDF_TYPE_STRING:
                WriteString(((TdfString)tdf).value);
                break;

            case TdfBaseType.TDF_TYPE_BINARY:
                WriteBlob(((TdfBlob)tdf).data);
                break;

            case TdfBaseType.TDF_TYPE_STRUCT:
                WriteStruct(((TdfStruct)tdf).data);
                break;

            case TdfBaseType.TDF_TYPE_LIST:
                WriteTdfList((TdfList)tdf);
                break;

            case TdfBaseType.TDF_TYPE_MAP:
                WriteTdfMap((TdfMap)tdf);
                break;

            case TdfBaseType.TDF_TYPE_UNION:
                WriteTdfUnion((TdfUnion)tdf);
                break;

            case TdfBaseType.TDF_TYPE_VARIABLE:
                WriteTdfIntegerList((TdfIntegerList)tdf);
                break;

            case TdfBaseType.TDF_TYPE_BLAZE_OBJECT_TYPE:
                WriteTdfVector2((TdfVector2)tdf);
                break;

            case TdfBaseType.TDF_TYPE_BLAZE_OBJECT_ID:
                WriteTdfVector3((TdfVector3)tdf);
                break;

            default:
                Log.Warn(string.Format("Unknown Tdf type: {0}.", tdf.type));
                break;
            }
        }
Example #3
0
        private Tdf ReadTdf()
        {
            Tdf tdf = null;

            string      label = ReadLabel();
            TdfBaseType type  = (TdfBaseType)_stream.ReadByte();

            switch (type)
            {
            case TdfBaseType.TDF_TYPE_INTEGER:
                tdf = DecodeTdfInteger(label);
                break;

            case TdfBaseType.TDF_TYPE_STRING:
                tdf = DecodeTdfString(label);
                break;

            case TdfBaseType.TDF_TYPE_BINARY:
                tdf = DecodeTdfBlob(label);
                break;

            case TdfBaseType.TDF_TYPE_STRUCT:
                tdf = DecodeTdfStruct(label);
                break;

            case TdfBaseType.TDF_TYPE_LIST:
                tdf = DecodeTdfList(label);
                break;

            case TdfBaseType.TDF_TYPE_MAP:
                tdf = DecodeTdfMap(label);
                break;

            case TdfBaseType.TDF_TYPE_UNION:
                tdf = DecodeTdfUnion(label);
                break;

            case TdfBaseType.TDF_TYPE_BLAZE_OBJECT_TYPE:
                tdf = DecodeTdfVector2(label);
                break;

            case TdfBaseType.TDF_TYPE_BLAZE_OBJECT_ID:
                tdf = DecodeTdfVector3(label);
                break;

            default:
                Log.Warn(string.Format("Unknown Tdf type: {0}.", type));
                break;
            }

            return(tdf);
        }