public void CanRead() { var orenStr = "Oren Eini"; var oren = Encoding.UTF8.GetBytes(orenStr); var longerStr = "There is a man on the moon and he's eating cheese"; var longer = Encoding.UTF8.GetBytes(longerStr); var funStr = "Writing code that make funny stuff happen is quite a pleasurable activity"; var fun = Encoding.UTF8.GetBytes(funStr); fixed(byte *pOren = oren) { fixed(byte *pLonger = longer) { fixed(byte *pFun = fun) { var tableValue = new TableValueBuilder { { pOren, oren.Length }, { pFun, fun.Length }, { pLonger, longer.Length } }; fixed(byte *buffer = new byte[tableValue.Size]) { tableValue.CopyTo(buffer); var reader = new TableValueReader(buffer, tableValue.Size); int size; var p = reader.Read(2, out size); var actual = Encoding.UTF8.GetString(p, size); Assert.Equal(longerStr, actual); p = reader.Read(0, out size); actual = Encoding.UTF8.GetString(p, size); Assert.Equal(orenStr, actual); p = reader.Read(1, out size); actual = Encoding.UTF8.GetString(p, size); Assert.Equal(funStr, actual); } } } } }
private static Document TableValueToDocument(JsonOperationContext context, TableValueReader tvr) { var result = new Document { StorageId = tvr.Id }; int size; // See format of the lazy string key in the GetLowerKeySliceAndStorageKey method var ptr = tvr.Read(3, out size); byte offset; size = BlittableJsonReaderBase.ReadVariableSizeInt(ptr, 0, out offset); result.Key = new LazyStringValue(null, ptr + offset, size, context); ptr = tvr.Read(2, out size); result.Etag = IPAddress.NetworkToHostOrder(*(long *)ptr); result.Data = new BlittableJsonReaderObject(tvr.Read(4, out size), size, context); return(result); }
private IndexConflictEntry TableValueToConflict(TableValueReader tvr, JsonOperationContext context) { var data = new IndexConflictEntry(); int size; data.Name = new LazyStringValue(null, tvr.Read((int)ConflictFields.Name, out size), size, context).ToString(); data.ChangeVector = ReplicationUtils.GetChangeVectorEntriesFromTableValueReader(tvr, (int)ConflictFields.ChangeVector); data.Type = (IndexEntryType)(*tvr.Read((int)ConflictFields.Type, out size)); data.Etag = Bits.SwapBytes(*(long *)tvr.Read((int)ConflictFields.Etag, out size)); var ptr = tvr.Read((int)ConflictFields.Definition, out size); data.Definition = new BlittableJsonReaderObject(ptr, size, context); return(data); }
private static Document TableValueToRevision(JsonOperationContext context, ref TableValueReader tvr) { var result = new Document { StorageId = tvr.Id, LowerId = TableValueToString(context, (int)RevisionsTable.LowerId, ref tvr), Id = TableValueToId(context, (int)RevisionsTable.Id, ref tvr), Etag = TableValueToEtag((int)RevisionsTable.Etag, ref tvr), LastModified = TableValueToDateTime((int)RevisionsTable.LastModified, ref tvr), Flags = TableValueToFlags((int)RevisionsTable.Flags, ref tvr), TransactionMarker = *(short *)tvr.Read((int)RevisionsTable.TransactionMarker, out int size), ChangeVector = TableValueToChangeVector(context, (int)RevisionsTable.ChangeVector, ref tvr) }; var ptr = tvr.Read((int)RevisionsTable.Document, out size); result.Data = new BlittableJsonReaderObject(ptr, size, context); return(result); }
public static byte[] ReadData(this TableValueReader reader, int index) { int size; var rawData = reader.Read(index, out size); var data = new byte[size]; fixed(byte *dataPtr = data) Memory.Copy(dataPtr, rawData, size); return(data); }
public static ChangeVectorEntry[] GetChangeVectorEntriesFromTableValueReader(TableValueReader tvr, int index) { int size; var pChangeVector = (ChangeVectorEntry *)tvr.Read(index, out size); var changeVector = new ChangeVectorEntry[size / sizeof(ChangeVectorEntry)]; for (int i = 0; i < changeVector.Length; i++) { changeVector[i] = pChangeVector[i]; } return(changeVector); }
private NotificationTableValue Read(JsonOperationContext context, ref TableValueReader reader) { var createdAt = new DateTime(Bits.SwapBytes(*(long *)reader.Read(NotificationsSchema.NotificationsTable.CreatedAtIndex, out int size))); var postponeUntilTicks = *(long *)reader.Read(NotificationsSchema.NotificationsTable.PostponedUntilIndex, out size); DateTime?postponedUntil = null; if (postponeUntilTicks != _postponeDateNotSpecified) { postponedUntil = new DateTime(Bits.SwapBytes(postponeUntilTicks)); } var jsonPtr = reader.Read(NotificationsSchema.NotificationsTable.JsonIndex, out size); return(new NotificationTableValue { CreatedAt = createdAt, PostponedUntil = postponedUntil, Json = new BlittableJsonReaderObject(jsonPtr, size, context) }); }
private unsafe DynamicJsonValue ExtractSubscriptionConfigValue(TableValueReader tvr, JsonOperationContext context) { int size; var subscriptionId = Bits.SwapBytes(*(long *)tvr.Read(SubscriptionSchema.SubscriptionTable.IdIndex, out size)); var ackEtag = *(long *)tvr.Read(SubscriptionSchema.SubscriptionTable.AckEtagIndex, out size); var timeOfReceivingLastAck = *(long *)tvr.Read(SubscriptionSchema.SubscriptionTable.TimeOfReceivingLastAck, out size); var ptr = tvr.Read(SubscriptionSchema.SubscriptionTable.CriteriaIndex, out size); var data = context.GetMemory(size); Memory.Copy((byte *)data.Address, ptr, size); var criteria = new BlittableJsonReaderObject((byte *)data.Address, size, context); return(new DynamicJsonValue { ["SubscriptionId"] = subscriptionId, ["Criteria"] = criteria, ["AckEtag"] = ackEtag, ["TimeOfReceivingLastAck"] = new DateTime(timeOfReceivingLastAck).ToString(CultureInfo.InvariantCulture), }); }
private IndexEntryMetadata TableValueToMetadata(TableValueReader tvr, JsonOperationContext context, bool returnNullIfTombstone) { var metadata = new IndexEntryMetadata(); int size; metadata.Id = Bits.SwapBytes(*(int *)tvr.Read((int)MetadataFields.Id, out size)); if (returnNullIfTombstone && metadata.Id == -1) { return(null); } metadata.Name = new LazyStringValue(null, tvr.Read((int)MetadataFields.Name, out size), size, context).ToString(); metadata.ChangeVector = ReplicationUtils.GetChangeVectorEntriesFromTableValueReader(tvr, (int)MetadataFields.ChangeVector); metadata.Type = (IndexEntryType)(*tvr.Read((int)MetadataFields.Type, out size)); metadata.Etag = Bits.SwapBytes(*(long *)tvr.Read((int)MetadataFields.Etag, out size)); metadata.IsConflicted = *(bool *)tvr.Read((int)MetadataFields.IsConflicted, out size); return(metadata); }
private static (LazyStringValue Doc, LazyStringValue Name) ExtractDocIdAndName(JsonOperationContext context, TableValueReader tvr) { var p = tvr.Read((int)CountersTable.CounterKey, out var size); Debug.Assert(size > DbIdAsBase64Size + 2 /* record separators */); int sizeOfDocId = 0; for (; sizeOfDocId < size; sizeOfDocId++) { if (p[sizeOfDocId] == SpecialChars.RecordSeparator) { break; } } var doc = context.AllocateStringValue(null, p, sizeOfDocId); var name = ExtractCounterName(context, tvr); return(doc, name); }
public static DocumentConflict ParseRawDataSectionConflictWithValidation(JsonOperationContext context, ref TableValueReader tvr, int expectedSize, out long etag) { var read = tvr.Read((int)ConflictsTable.Data, out var size); if (size > expectedSize || size <= 0) { throw new ArgumentException("Document size is invalid, possible corruption when parsing BlittableJsonReaderObject", nameof(size)); } var result = new DocumentConflict { StorageId = tvr.Id, LowerId = TableValueToString(context, (int)ConflictsTable.LowerId, ref tvr), Id = TableValueToId(context, (int)ConflictsTable.Id, ref tvr), ChangeVector = TableValueToChangeVector(context, (int)ConflictsTable.ChangeVector, ref tvr), Etag = etag = TableValueToEtag((int)ConflictsTable.Etag, ref tvr), Doc = new BlittableJsonReaderObject(read, size, context), Collection = TableValueToId(context, (int)ConflictsTable.Collection, ref tvr), LastModified = TableValueToDateTime((int)ConflictsTable.LastModified, ref tvr), Flags = TableValueToFlags((int)ConflictsTable.Flags, ref tvr) }; return(result); }
private static unsafe BlittableJsonReaderObject Read(JsonOperationContext context, ref TableValueReader reader) { var ptr = reader.Read(DatabaseInfoSchema.DatabaseInfoTable.JsonIndex, out int size); return(new BlittableJsonReaderObject(ptr, size, context)); }
public static unsafe long GetValue(TableValueReader tvr) { return(*(long *)tvr.Read((int)ClusterStateMachine.IdentitiesTable.Value, out _)); }
private static unsafe LazyStringValue ReadCompareExchangeKey(JsonOperationContext context, TableValueReader reader) { var ptr = reader.Read((int)ClusterStateMachine.CompareExchangeTable.Key, out var size); return(context.AllocateStringValue(null, ptr, size)); }
private static unsafe BlittableJsonReaderObject ReadCompareExchangeValue(JsonOperationContext context, TableValueReader reader) { return(new BlittableJsonReaderObject(reader.Read((int)ClusterStateMachine.CompareExchangeTable.Value, out var size), size, context)); }