public static CheckEndian ( byte bytes ) : byte[] | ||
bytes | byte | |
return | byte[] |
/// <summary> /// Marshals an entry into a byte[] to be sent to restAPI /// </summary> /// <param name="e">Entry to be marshaled</param> /// <returns>Marshaled entry</returns> public static byte[] MarshalBinary(DataStructs.EntryData e) { var entryBStruct = new List <byte>(); var idsSize = MarshalExtIDsSize(e); idsSize = Bytes.CheckEndian(idsSize); // Header // 1 byte version byte version = 0; entryBStruct.Add(version); // 32 byte chainid var chain = e.ChainId; entryBStruct.AddRange(chain); // Ext Ids Size entryBStruct.AddRange(idsSize); // Payload // ExtIDS if (e.ExtIDs != null) { var ids = MarshalExtIDsBinary(e); entryBStruct.AddRange(ids); } // Content var content = e.Content; entryBStruct.AddRange(content); return(entryBStruct.ToArray()); }
public static byte[] MilliTime() { var unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); // 6 Byte millisec unix time var unixMilliLong = (long)(DateTime.UtcNow - unixEpoch).TotalMilliseconds; var unixBytes = Bytes.CheckEndian(BitConverter.GetBytes(unixMilliLong)); unixBytes = Arrays.CopyOfRange(unixBytes, 2, unixBytes.Length); return(unixBytes); }
/// <summary> /// Helper function of MarshalBinary /// </summary> /// <param name="e"></param> /// <returns></returns> private static byte[] MarshalExtIDsBinary(DataStructs.EntryData e) { var byteList = new List <byte>(); foreach (var exId in e.ExtIDs) { // 2 byte size of ExtID var extLen = Convert.ToInt16(exId.Length); var bytes = BitConverter.GetBytes(extLen); bytes = Bytes.CheckEndian(bytes); byteList.AddRange(bytes); var extIdStr = exId; byteList.AddRange(extIdStr); } return(byteList.ToArray()); }
/// <summary> /// Helper function of MarshalBinary /// </summary> /// <param name="e"></param> /// <returns></returns> private static byte[] MarshalExtIDsSize(DataStructs.EntryData e) { if (e.ExtIDs == null) { short extLen = 0; var bytes = BitConverter.GetBytes(extLen); return(Bytes.CheckEndian(bytes)); } else { var totalSize = 0; foreach (var extElement in e.ExtIDs) { totalSize += extElement.Length + 2; } var extLen = Convert.ToInt16(totalSize); var bytes = BitConverter.GetBytes(extLen); return(bytes); // return Bytes.CheckEndian(bytes); } }