LLVM 22.0.0git
llvm::yaml::BinaryRef Class Reference

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.
LLVM_ABI void writeAsBinary (raw_ostream &OS, uint64_t N=UINT64_MAX) const
 Write the contents (regardless of whether it is binary or a hex string) as binary to the given raw_ostream.
LLVM_ABI 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.

Friends

bool operator== (const BinaryRef &LHS, const BinaryRef &RHS)

Detailed Description

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: '\x44' == '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:

Foo: DEADBEEFCAFEBABE

Could be modeled in YAMLIO by the struct:

struct FooHolder {
BinaryRef Foo;
};
namespace llvm {
namespace yaml {
template <>
struct MappingTraits<FooHolder> {
static void mapping(IO &IO, FooHolder &FH) {
IO.mapRequired("Foo", FH.Foo);
}
};
} // end namespace yaml
} // end namespace llvm
void mapRequired(const char *Key, T &Val)
Definition YAMLTraits.h:790
This is an optimization pass for GlobalISel generic memory operations.
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
Definition YAMLTraits.h:62

Definition at line 64 of file YAML.h.

Constructor & Destructor Documentation

◆ BinaryRef() [1/3]

llvm::yaml::BinaryRef::BinaryRef ( )
default

Referenced by operator==.

◆ BinaryRef() [2/3]

llvm::yaml::BinaryRef::BinaryRef ( ArrayRef< uint8_t > Data)
inline

Definition at line 76 of file YAML.h.

◆ BinaryRef() [3/3]

llvm::yaml::BinaryRef::BinaryRef ( StringRef Data)
inline

Definition at line 77 of file YAML.h.

References llvm::arrayRefFromStringRef().

Member Function Documentation

◆ binary_size()

ArrayRef< uint8_t >::size_type llvm::yaml::BinaryRef::binary_size ( ) const
inline

The number of bytes that are represented by this BinaryRef.

This is the number of bytes that writeAsBinary() will write.

Definition at line 81 of file YAML.h.

References llvm::ArrayRef< T >::size().

Referenced by layoutCOFF(), llvm::yaml::MappingTraits< COFFYAML::Section >::mapping(), writeAsHex(), and writeCOFF().

◆ writeAsBinary()

void yaml::BinaryRef::writeAsBinary ( raw_ostream & OS,
uint64_t N = UINT64_MAX ) const

Write the contents (regardless of whether it is binary or a hex string) as binary to the given raw_ostream.

N can be used to specify the maximum number of bytes.

Definition at line 39 of file YAML.cpp.

References llvm::hexDigitValue(), I, N, and llvm::raw_ostream::write().

Referenced by writeCOFF().

◆ writeAsHex()

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 54 of file YAML.cpp.

References binary_size(), llvm::hexdigit(), and llvm::raw_ostream::write().

◆ operator==

bool operator== ( const BinaryRef & LHS,
const BinaryRef & RHS )
friend

Definition at line 99 of file YAML.h.

References BinaryRef(), LHS, and RHS.


The documentation for this class was generated from the following files: