Example #1
0
        /// <inheritdoc />
        public async Task WriteStringContents([NotNull] IReadOnlyCollection <string> stringsToWrite)
        {
            if (stringsToWrite == null)
            {
                throw new ArgumentNullException(nameof(stringsToWrite));
            }

            //If none we don't need to write
            if (stringsToWrite.Count == 0)
            {
                return;
            }

            //We should expect that the caller ordered this the way they wanted.
            foreach (string s in stringsToWrite)
            {
#if !NETSTANDARD2_0
                ReadOnlyMemory <byte> asciiBytes = ReadStringAsASCIIBytes(s);

                await DbcStream.WriteAsync(asciiBytes);
#else
                byte[] bytes = new byte[s.Length + 1];
                Encoding.ASCII.GetEncoder().GetBytes(s.ToCharArray(), 0, s.Length, bytes, 0, true);

                await DbcStream.WriteAsync(bytes, 0, bytes.Length);
#endif
            }
        }
        /// <inheritdoc />
        public async Task WriteHeader(DBCHeader header)
        {
            await DbcStream.FlushAsync();

            //TODO: This is kinda hack, but makes things really easy for callers. Header should always go in front.
            DbcStream.Position = 0;

            byte[] bytes = Serializer.Serialize(header);

            await DbcStream.WriteAsync(bytes, 0, bytes.Length);

            await DbcStream.FlushAsync();
        }
Example #3
0
        /// <summary>
        /// Writes the provided <see cref="entries"/>.
        /// Returns the entry size of the serialized entries.
        /// Does NOT write the header.
        /// </summary>
        /// <param name="entries">The entries to write.</param>
        /// <returns>The entry size. (size * <see cref="entries"/> = the total size written)</returns>
        public async Task <int> WriteContents([NotNull] IReadOnlyCollection <TDBCEntryType> entries)
        {
            if (entries == null)
            {
                throw new ArgumentNullException(nameof(entries));
            }

            GDBCCollection <TDBCEntryType> collection = new GDBCCollection <TDBCEntryType>(entries.ToArray());

            byte[] bytes = Serializer.Serialize(collection);

            await DbcStream.WriteAsync(bytes, 0, bytes.Length);

            //Variable
            return(0);
        }
Example #4
0
        /// <summary>
        /// Writes the provided <see cref="entries"/>.
        /// Returns the entry size of the serialized entries.
        /// Does NOT write the header.
        /// </summary>
        /// <param name="entries">The entries to write.</param>
        /// <returns>The entry size. (size * <see cref="entries"/> = the total size written)</returns>
        public async Task <int> WriteContents([NotNull] IReadOnlyCollection <TDBCEntryType> entries)
        {
            if (entries == null)
            {
                throw new ArgumentNullException(nameof(entries));
            }

            //This is kinda hacky, we serialize the first one like this because
            //we want to know the size of the entry. Since it's not a struct or marshalable/bittable
            //we HAVE to do this
            byte[] bytes = Serializer.Serialize(entries.First());

            int entrySize = bytes.Length;
            await DbcStream.WriteAsync(bytes, 0, entrySize);

            foreach (TDBCEntryType entry in entries.Skip(1))
            {
                bytes = Serializer.Serialize(entry);
                await DbcStream.WriteAsync(bytes, 0, bytes.Length);
            }

            return(entrySize);
        }