MCPcopy Create free account
hub / github.com/PlatformLab/NanoLog / Encoder

Class Encoder

runtime/Log.h:635–688  ·  view source on GitHub ↗

* Encapsulates the knowledge on how to transform UncompresedLogMessage's * created by the generated code into a compressed log for a Decoder * object to interpret later. * * The intended usage pattern is for the user to create an Encoder object * per compressed log file that they intend to create, feed it a character * buffer array to operate on, and repeatedly invoke

Source from the content-addressed store, hash-verified

633 * - Log Messages live within BufferExtents and do not span BufferExtents.
634 */
635 class Encoder {
636 PUBLIC:
637 Encoder(char *buffer, size_t bufferSize,
638 bool skipCheckpoint=false,
639 bool forceDictionaryOutput=false);
640
641 long encodeLogMsgs(char *from, uint64_t nbytes,
642 uint32_t bufferId,
643 bool wrapAround,
644 uint64_t *numEventsCompressed);
645
646 long encodeLogMsgs(char *from, uint64_t nbytes,
647 uint32_t bufferId,
648 bool wrapAround,
649 std::vector<StaticLogInfo> dictionary,
650 uint64_t *numEventsCompressed);
651 uint32_t encodeNewDictionaryEntries(uint32_t& currentPosition,
652 std::vector<StaticLogInfo> allMetadata);
653
654 size_t getEncodedBytes();
655 void swapBuffer(char *inBuffer, size_t inSize,
656 char **outBuffer=nullptr, size_t *outLength=nullptr,
657 size_t *outSize=nullptr);
658
659 PRIVATE:
660 bool encodeBufferExtentStart(uint32_t bufferId, bool wrapAround);
661
662 // Used to store the compressed log messages and related metadata
663 char *backing_buffer;
664
665 // Position within the backing_buffer where the next log entries or
666 // log metadata should be placed.
667 char *writePos;
668
669 // Marks the first invalid byte in the backing_buffer
670 char *endOfBuffer;
671
672 // Saves the last bufferId encoded to determine when a new BufferExtent
673 // needs to be encoded. A value of (-1) indicates no extent was encoded.
674 uint32_t lastBufferIdEncoded;
675
676 // A pointer to the last encoded BufferExtent's length to allow updating
677 // the value as the user performs more encodeLogMsgs with the same id.
678 uint32_t *currentExtentSize;
679
680 // Metric: Total number of encode failures due to missing metadata. This
681 // is typically due to a benign race condition, but could indicate an
682 // error if it happens repeatedly.
683 uint32_t encodeMissDueToMetadata;
684
685 // Metric: Number of consecutive encode failures due to missing metadata
686 // Used to detect cases where the dictionary isn't persisted due to bugs
687 uint32_t consecutiveEncodeMissesDueToMetadata;
688 };
689
690 /**
691 * This class embodies a runtime log statement returned from

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected