public static void WriteGetItemsResult(this DataOutputStream output, DashboardItem[] value) { if (value == null) { throw new ArgumentNullException("value"); } output.WriteInt32(value.Length); foreach (var item in value) { output.WriteString(item.AskQuestion); output.WriteDateTime(item.DateTime.ToDateTime()); output.WriteInt32(item.FeedItemType); output.WriteString(item.Friend1FullName); output.WriteString(item.Friend2FullName); output.WriteString(item.FriendNickname1); output.WriteString(item.FriendNickname2); output.WriteString(item.FriendWebMemberID1); output.WriteString(item.FriendWebMemberID2); output.WriteString(item.Text); output.WriteString(item.ThumbnailUrl); output.WriteString(item.Title); output.WriteInt32(item.ObjectID); output.WriteString(item.WebPhotoCollectionID); output.WriteString(item.WebPhotoID); } }
public static void WriteInt32Array(this DataOutputStream output, Int32[] value) { if (value == null) { throw new ArgumentNullException("value"); } output.WriteInt32(value.Length); foreach (var item in value) { output.WriteInt32(item); } }
public static void WriteGetResponseResult(this DataOutputStream output, AskResponse value) { if (value == null) { throw new ArgumentNullException("value"); } output.WriteInt32(value.AskQuestionID); output.WriteString(value.Question); output.WriteByteArray(Convert.FromBase64String(value.PhotoBase64Binary)); output.WriteInt32Array(value.ResponseValues); output.WriteFloat(Convert.ToSingle(value.Average)); output.WriteInt32(value.ResponseType); output.WriteStringArray(value.CustomResponses); }
public static void WriteGetCommentResult(this DataOutputStream output, WebComment value) { if (value == null) { throw new ArgumentNullException("value"); } output.WriteInt32(value.ID); output.WriteInt32(value.ObjectID); output.WriteString(value.Nickname); output.WriteString(value.Text); output.WriteDateTime(value.DTCreated.ToDateTime()); output.WriteInt32(value.InReplyToCommentID); output.WriteInt32(value.ParentCommentID); output.WriteInt32(value.CommentType); }
public static void WriteGetPhotosForCollectionResult(this DataOutputStream output, WebPhoto[] value) { if (value == null) { throw new ArgumentNullException("value"); } output.WriteInt32(value.Length); foreach (var item in value) { output.WriteInt32(item.ID); output.WriteDateTime(item.CreatedDT.ToDateTime()); output.WriteString(item.Title); output.WriteString(item.Description); } }
/// <summary> /// Serialize the token data for communication between server and client. /// </summary> /// <exception cref="IOException"></exception> public void Serialize(DataOutputStream writer) { writer.WriteUTF(Id); writer.WriteUTF(Version); writer.WriteInt32(SourceFiles.Count); foreach (KeyValuePair <string, IList <RevisionFile> > pair in SourceFiles) { writer.WriteUTF(pair.Key); writer.WriteInt32(pair.Value.Count); foreach (RevisionFile file in pair.Value) { writer.WriteUTF(file.FileName); writer.WriteInt64(file.Length); } } }
public static void WriteGetQuestionResult(this DataOutputStream output, AskQuestion value) { if (value == null) { throw new ArgumentNullException("value"); } output.WriteInt32(value.ID); output.WriteString(value.Question); output.WriteDateTime(value.DTCreated.ToDateTime()); }
public static void WriteGetEntryResult(this DataOutputStream output, BlogEntry value) { if (value == null) { throw new ArgumentNullException("value"); } output.WriteInt32(value.ID); output.WriteString(value.Title); output.WriteString(value.Body); output.WriteDateTime(value.DTCreated.ToDateTime()); }
public static void WriteGetQuestionsResult(this DataOutputStream output, AskQuestion[] value) { if (value == null) { throw new ArgumentNullException("value"); } output.WriteInt32(value.Length); foreach (var item in value) { output.WriteGetQuestionResult(item); } }
/// <summary> /// Writes an ICU data header. /// Does not write a copyright string. /// </summary> /// <param name="dataFormat"></param> /// <param name="formatVersion"></param> /// <param name="dataVersion"></param> /// <param name="dos"></param> /// <returns>The length of the header (number of bytes written).</returns> /// <exception cref="IOException">From the <see cref="DataOutputStream"/>.</exception> public static int WriteHeader(int dataFormat, int formatVersion, int dataVersion, DataOutputStream dos) { // ucmndata.h MappedData dos.WriteChar(32); // headerSize dos.WriteByte(MAGIC1); dos.WriteByte(MAGIC2); // unicode/udata.h UDataInfo dos.WriteChar(20); // sizeof(UDataInfo) dos.WriteChar(0); // reservedWord dos.WriteByte(1); // isBigEndian dos.WriteByte(CHAR_SET_); // charsetFamily dos.WriteByte(CHAR_SIZE_); // sizeofUChar dos.WriteByte(0); // reservedByte dos.WriteInt32(dataFormat); dos.WriteInt32(formatVersion); dos.WriteInt32(dataVersion); // 8 bytes padding for 32 bytes headerSize (multiple of 16). dos.WriteInt64(0); Debug.Assert(dos.Length == 32); return(32); }
/// <summary> /// Serialize a <see cref="Trie2_32"/> onto an <see cref="Stream"/>. /// </summary> /// <remarks> /// A <see cref="Trie2"/> can be serialized multiple times. /// The serialized data is compatible with ICU4C UTrie2 serialization. /// <see cref="Trie2"/> serialization is unrelated to .NET object serialization. /// </remarks> /// <param name="os">The stream to which the serialized Trie2 data will be written.</param> /// <returns>The number of bytes written.</returns> /// <exception cref="IOException">On an error writing to the <see cref="Stream"/>.</exception> public int Serialize(Stream os) { DataOutputStream dos = new DataOutputStream(os); int bytesWritten = 0; bytesWritten += SerializeHeader(dos); for (int i = 0; i < dataLength; i++) { dos.WriteInt32(data32[i]); } bytesWritten += dataLength * 4; return(bytesWritten); }
public static void WriteUploadTagsResult(this DataOutputStream output, TagConfirmation[] value) { if (value == null) { throw new ArgumentNullException("value"); } output.WriteInt32(value.Length); foreach (var item in value) { output.WriteString(item.DeviceID); output.WriteBoolean(item.ConfirmedByServer); } }
public static void WriteByteArray(this DataOutputStream output, Byte[] value) { if (value == null) { throw new ArgumentNullException("value"); } output.WriteInt32(value.Length); _byte2SByteMap.ByteArray = value; foreach (var item in _byte2SByteMap.SByteArray) { output.WriteByte(item); } }
public static void WriteGetNewFriendsResult(this DataOutputStream output, DashboardNewFriend[] value) { if (value == null) { throw new ArgumentNullException("value"); } output.WriteInt32(value.Length); foreach (var item in value) { output.WriteDateTime(item.DateTime.ToDateTime()); output.WriteString(item.Nickname1); output.WriteString(item.Nickname2); } }
public static void WriteGetVideosResult(this DataOutputStream output, DashboardVideo[] value) { if (value == null) { throw new ArgumentNullException("value"); } output.WriteInt32(value.Length); foreach (var item in value) { output.WriteDateTime(item.DateTime.ToDateTime()); output.WriteString(item.Nickname); output.WriteString(item.Text); output.WriteString(item.Title); output.WriteString(item.ThumbnailUrl); } }
public void Return(DataOutputStream output) { output.WriteInt32(_result); }
/// <summary> /// Serializes the build table to an output stream. /// <para/> /// Compacts the build-time trie after all values are set, and then /// writes the serialized form onto an output stream. /// <para/> /// After this, this build-time Trie can only be serialized again and/or closed; /// no further values can be added. /// <para/> /// This function is the rough equivalent of utrie_seriaize() in ICU4C. /// </summary> /// <param name="os">The output stream to which the seriaized trie will be written. /// If nul, the function still returns the size of the serialized Trie.</param> /// <param name="reduceTo16Bits">If true, reduce the data size to 16 bits. The resulting /// serialized form can then be used to create a <see cref="CharTrie"/>.</param> /// <param name="datamanipulate">Builder raw fold method implementation.</param> /// <returns>The number of bytes written to the output stream.</returns> public virtual int Serialize(Stream os, bool reduceTo16Bits, ITrieBuilderDataManipulate datamanipulate) { if (datamanipulate == null) { throw new ArgumentException("Parameters can not be null"); } // fold and compact if necessary, also checks that indexLength is // within limits if (!m_isCompacted_) { // compact once without overlap to improve folding Compact(false); // fold the supplementary part of the index array Fold(datamanipulate); // compact again with overlap for minimum data array length Compact(true); m_isCompacted_ = true; } // is dataLength within limits? int length; if (reduceTo16Bits) { length = m_dataLength_ + m_indexLength_; } else { length = m_dataLength_; } if (length >= MaxDataLength) { throw new IndexOutOfRangeException("Data length too small"); } // struct UTrieHeader { // int32_t signature; // int32_t options (a bit field) // int32_t indexLength // int32_t dataLength length = Trie.HeaderLength + 2 * m_indexLength_; if (reduceTo16Bits) { length += 2 * m_dataLength_; } else { length += 4 * m_dataLength_; } if (os == null) { // No output stream. Just return the length of the serialized Trie, in bytes. return(length); } DataOutputStream dos = new DataOutputStream(os); dos.WriteInt32(Trie.HeaderSignature); int options = Trie.IndexStage1Shift | (Trie.IndexStage2Shift << Trie.HeaderOptionsIndexShift); if (!reduceTo16Bits) { options |= Trie.HeaderOptionsDataIs32Bit; } if (m_isLatin1Linear_) { options |= Trie.HeaderOptionsLatin1IsLinearMask; } dos.WriteInt32(options); dos.WriteInt32(m_indexLength_); dos.WriteInt32(m_dataLength_); /* write the index (stage 1) array and the 16/32-bit data (stage 2) array */ if (reduceTo16Bits) { /* write 16-bit index values shifted right by UTRIE_INDEX_SHIFT, after adding indexLength */ for (int i = 0; i < m_indexLength_; i++) { int v = (m_index_[i] + m_indexLength_).TripleShift(Trie.IndexStage2Shift); dos.WriteChar(v); } /* write 16-bit data values */ for (int i = 0; i < m_dataLength_; i++) { int v = m_data_[i] & 0x0000ffff; dos.WriteChar(v); } } else { /* write 16-bit index values shifted right by UTRIE_INDEX_SHIFT */ for (int i = 0; i < m_indexLength_; i++) { int v = (m_index_[i]).TripleShift(Trie.IndexStage2Shift); dos.WriteChar(v); } /* write 32-bit data values */ for (int i = 0; i < m_dataLength_; i++) { dos.WriteInt32(m_data_[i]); } } return(length); }
internal void FlattenData(Stream os) { DataOutputStream dos = new DataOutputStream(os); int i; // Remove comments and whitespace from the rules to make it smaller. string strippedRules = RBBIRuleScanner.StripRules(fRules); // Calculate the size of each section in the data in bytes. // Sizes here are padded up to a multiple of 8 for better memory alignment. // Sections sizes actually stored in the header are for the actual data // without the padding. // int headerSize = 24 * 4; // align8(sizeof(RBBIDataHeader)); int forwardTableSize = Align8(fForwardTables.GetTableSize()); int reverseTableSize = Align8(fReverseTables.GetTableSize()); // int safeFwdTableSize = Align8(fSafeFwdTables.getTableSize()); int safeRevTableSize = Align8(fSafeRevTables.GetTableSize()); int trieSize = Align8(fSetBuilder.GetTrieSize()); int statusTableSize = Align8(fRuleStatusVals.Count * 4); int rulesSize = Align8((strippedRules.Length) * 2); int totalSize = headerSize + forwardTableSize + /* reverseTableSize */ 0 + /* safeFwdTableSize */ 0 + (safeRevTableSize > 0 ? safeRevTableSize : reverseTableSize) + statusTableSize + trieSize + rulesSize; int outputPos = 0; // Track stream position, starting from RBBIDataHeader. // // Write out an ICU Data Header // ICUBinary.WriteHeader(RBBIDataWrapper.DATA_FORMAT, RBBIDataWrapper.FORMAT_VERSION, 0, dos); // // Write out the RBBIDataHeader // int[] header = new int[RBBIDataWrapper.DH_SIZE]; // sizeof struct RBBIDataHeader header[RBBIDataWrapper.DH_MAGIC] = 0xb1a0; header[RBBIDataWrapper.DH_FORMATVERSION] = RBBIDataWrapper.FORMAT_VERSION; header[RBBIDataWrapper.DH_LENGTH] = totalSize; // fLength, the total size of all rule sections. header[RBBIDataWrapper.DH_CATCOUNT] = fSetBuilder.NumCharCategories; // fCatCount. // Only save the forward table and the safe reverse table, // because these are the only ones used at run-time. // // For the moment, we still build the other tables if they are present in the rule source files, // for backwards compatibility. Old rule files need to work, and this is the simplest approach. // // Additional backwards compatibility consideration: if no safe rules are provided, consider the // reverse rules to actually be the safe reverse rules. header[RBBIDataWrapper.DH_FTABLE] = headerSize; // fFTable header[RBBIDataWrapper.DH_FTABLELEN] = forwardTableSize; // fTableLen // Do not save Reverse Table. header[RBBIDataWrapper.DH_RTABLE] = header[RBBIDataWrapper.DH_FTABLE] + forwardTableSize; // fRTable header[RBBIDataWrapper.DH_RTABLELEN] = 0; // fRTableLen // Do not save the Safe Forward table. header[RBBIDataWrapper.DH_SFTABLE] = header[RBBIDataWrapper.DH_RTABLE] + 0; // fSTable header[RBBIDataWrapper.DH_SFTABLELEN] = 0; // fSTableLen // Safe reverse table. Use if present, otherwise save regular reverse table as the safe reverse. header[RBBIDataWrapper.DH_SRTABLE] = header[RBBIDataWrapper.DH_SFTABLE] + 0; // fSRTable if (safeRevTableSize > 0) { header[RBBIDataWrapper.DH_SRTABLELEN] = safeRevTableSize; } else { Debug.Assert(reverseTableSize > 0); header[RBBIDataWrapper.DH_SRTABLELEN] = reverseTableSize; } header[RBBIDataWrapper.DH_TRIE] = header[RBBIDataWrapper.DH_SRTABLE] + header[RBBIDataWrapper.DH_SRTABLELEN]; // fTrie header[RBBIDataWrapper.DH_TRIELEN] = fSetBuilder.GetTrieSize(); // fTrieLen header[RBBIDataWrapper.DH_STATUSTABLE] = header[RBBIDataWrapper.DH_TRIE] + header[RBBIDataWrapper.DH_TRIELEN]; header[RBBIDataWrapper.DH_STATUSTABLELEN] = statusTableSize; // fStatusTableLen header[RBBIDataWrapper.DH_RULESOURCE] = header[RBBIDataWrapper.DH_STATUSTABLE] + statusTableSize; header[RBBIDataWrapper.DH_RULESOURCELEN] = strippedRules.Length * 2; for (i = 0; i < header.Length; i++) { dos.WriteInt32(header[i]); outputPos += 4; } // Write out the actual state tables. short[] tableData; tableData = fForwardTables.ExportTable(); Assert.Assrt(outputPos == header[4]); for (i = 0; i < tableData.Length; i++) { dos.WriteInt16(tableData[i]); outputPos += 2; } /* do not write the reverse table * tableData = fReverseTables.exportTable(); * Assert.Assrt(outputPos == header[6]); * for (i = 0; i < tableData.length; i++) { * dos.WriteInt16(tableData[i]); * outputPos += 2; * } */ /* do not write safe forwards table * Assert.Assrt(outputPos == header[8]); * tableData = fSafeFwdTables.exportTable(); * for (i = 0; i < tableData.length; i++) { * dos.WriteInt16(tableData[i]); * outputPos += 2; * } */ // Write the safe reverse table. // If not present, write the plain reverse table (old style rule compatibility) Assert.Assrt(outputPos == header[10]); if (safeRevTableSize > 0) { tableData = fSafeRevTables.ExportTable(); } else { tableData = fReverseTables.ExportTable(); } for (i = 0; i < tableData.Length; i++) { dos.WriteInt16(tableData[i]); outputPos += 2; } // write out the Trie table Assert.Assrt(outputPos == header[12]); fSetBuilder.SerializeTrie(os); outputPos += header[13]; while (outputPos % 8 != 0) { // pad to an 8 byte boundary dos.Write(0); outputPos += 1; } // Write out the status {tag} table. Assert.Assrt(outputPos == header[16]); foreach (var val in fRuleStatusVals) { dos.WriteInt32(val); outputPos += 4; } while (outputPos % 8 != 0) { // pad to an 8 byte boundary dos.Write(0); outputPos += 1; } // Write out the stripped rules (rules with extra spaces removed // These go last in the data area, even though they are not last in the header. Assert.Assrt(outputPos == header[14]); dos.WriteChars(strippedRules); outputPos += strippedRules.Length * 2; while (outputPos % 8 != 0) { // pad to an 8 byte boundary dos.Write(0); outputPos += 1; } }
public void Return(DataOutputStream output) { output.WriteInt32(_result); }