LLVM
8.0.1
|
Specialized YAMLIO scalar type for representing a binary blob. More...
#include "llvm/ObjectYAML/YAML.h"
Public Member Functions | |
BinaryRef ()=default | |
BinaryRef (ArrayRef< uint8_t > Data) | |
BinaryRef (StringRef Data) | |
ArrayRef< uint8_t >::size_type | binary_size () const |
The number of bytes that are represented by this BinaryRef. More... | |
void | writeAsBinary (raw_ostream &OS) const |
Write the contents (regardless of whether it is binary or a hex string) as binary to the given raw_ostream. More... | |
void | writeAsHex (raw_ostream &OS) const |
Write the contents (regardless of whether it is binary or a hex string) as hex to the given raw_ostream. More... | |
Friends | |
bool | operator== (const BinaryRef &LHS, const BinaryRef &RHS) |
Specialized YAMLIO scalar type for representing a binary blob.
A typical use case would be to represent the content of a section in a binary file. This class has custom YAMLIO traits for convenient reading and writing. It renders as a string of hex digits in a YAML file. For example, it might render as DEADBEEFCAFEBABE
(YAML does not require the quotation marks, so for simplicity when outputting they are omitted). When reading, any string whose content is an even number of hex digits will be accepted. For example, all of the following are acceptable: DEADBEEF
, "DeADbEeF"
, "\x44EADBEEF"
(Note: '' == 'D')
A significant advantage of using this class is that it never allocates temporary strings or buffers for any of its functionality.
Example:
The YAML mapping:
Could be modeled in YAMLIO by the struct:
|
default |
|
inline |
|
inline |
The number of bytes that are represented by this BinaryRef.
This is the number of bytes that writeAsBinary() will write.
Definition at line 82 of file YAML.h.
References llvm::ArrayRef< T >::size(), writeAsBinary(), and writeAsHex().
Referenced by llvm::yaml::sectionMapping(), and writeAsHex().
void yaml::BinaryRef::writeAsBinary | ( | raw_ostream & | OS | ) | const |
Write the contents (regardless of whether it is binary or a hex string) as binary to the given raw_ostream.
Definition at line 41 of file YAML.cpp.
References llvm::ArrayRef< T >::data(), llvm::StringRef::getAsInteger(), I, N, llvm::ArrayRef< T >::size(), and llvm::raw_ostream::write().
Referenced by binary_size(), and llvm::CodeViewYAML::detail::UnknownSymbolRecord::map().
void yaml::BinaryRef::writeAsHex | ( | raw_ostream & | OS | ) | const |
Write the contents (regardless of whether it is binary or a hex string) as hex to the given raw_ostream.
For example, a possible output could be DEADBEEFCAFEBABE
.
Definition at line 53 of file YAML.cpp.
References binary_size(), llvm::ArrayRef< T >::data(), llvm::hexdigit(), llvm::ArrayRef< T >::size(), and llvm::raw_ostream::write().
Referenced by binary_size().