}
// NumElems returns the number of elements in section k.
-func (pr *PkgDecoder) NumElems(k RelocKind) int {
+func (pr *PkgDecoder) NumElems(k SectionKind) int {
count := int(pr.elemEndsEnds[k])
if k > 0 {
count -= int(pr.elemEndsEnds[k-1])
// AbsIdx returns the absolute index for the given (section, index)
// pair.
-func (pr *PkgDecoder) AbsIdx(k RelocKind, idx RelIndex) int {
+func (pr *PkgDecoder) AbsIdx(k SectionKind, idx RelIndex) int {
absIdx := int(idx)
if k > 0 {
absIdx += int(pr.elemEndsEnds[k-1])
// DataIdx returns the raw element bitstream for the given (section,
// index) pair.
-func (pr *PkgDecoder) DataIdx(k RelocKind, idx RelIndex) string {
+func (pr *PkgDecoder) DataIdx(k SectionKind, idx RelIndex) string {
absIdx := pr.AbsIdx(k, idx)
var start uint32
// NewDecoder returns a Decoder for the given (section, index) pair,
// and decodes the given SyncMarker from the element bitstream.
-func (pr *PkgDecoder) NewDecoder(k RelocKind, idx RelIndex, marker SyncMarker) Decoder {
+func (pr *PkgDecoder) NewDecoder(k SectionKind, idx RelIndex, marker SyncMarker) Decoder {
r := pr.NewDecoderRaw(k, idx)
r.Sync(marker)
return r
// and decodes the given SyncMarker from the element bitstream.
// If possible the Decoder should be RetireDecoder'd when it is no longer
// needed, this will avoid heap allocations.
-func (pr *PkgDecoder) TempDecoder(k RelocKind, idx RelIndex, marker SyncMarker) Decoder {
+func (pr *PkgDecoder) TempDecoder(k SectionKind, idx RelIndex, marker SyncMarker) Decoder {
r := pr.TempDecoderRaw(k, idx)
r.Sync(marker)
return r
// NewDecoderRaw returns a Decoder for the given (section, index) pair.
//
// Most callers should use NewDecoder instead.
-func (pr *PkgDecoder) NewDecoderRaw(k RelocKind, idx RelIndex) Decoder {
+func (pr *PkgDecoder) NewDecoderRaw(k SectionKind, idx RelIndex) Decoder {
r := Decoder{
common: pr,
k: k,
r.Relocs = make([]RelocEnt, r.Len())
for i := range r.Relocs {
r.Sync(SyncReloc)
- r.Relocs[i] = RelocEnt{RelocKind(r.Len()), RelIndex(r.Len())}
+ r.Relocs[i] = RelocEnt{SectionKind(r.Len()), RelIndex(r.Len())}
}
return r
}
-func (pr *PkgDecoder) TempDecoderRaw(k RelocKind, idx RelIndex) Decoder {
+func (pr *PkgDecoder) TempDecoderRaw(k SectionKind, idx RelIndex) Decoder {
r := Decoder{
common: pr,
k: k,
}
for i := range r.Relocs {
r.Sync(SyncReloc)
- r.Relocs[i] = RelocEnt{RelocKind(r.Len()), RelIndex(r.Len())}
+ r.Relocs[i] = RelocEnt{SectionKind(r.Len()), RelIndex(r.Len())}
}
return r
Relocs []RelocEnt
Data strings.Reader
- k RelocKind
+ k SectionKind
Idx RelIndex
}
return x
}
-func (r *Decoder) rawReloc(k RelocKind, idx int) RelIndex {
+func (r *Decoder) rawReloc(k SectionKind, idx int) RelIndex {
e := r.Relocs[idx]
assert(e.Kind == k)
return e.Idx
// Reloc decodes a relocation of expected section k from the element
// bitstream and returns an index to the referenced element.
-func (r *Decoder) Reloc(k RelocKind) RelIndex {
+func (r *Decoder) Reloc(k SectionKind) RelIndex {
r.Sync(SyncUseReloc)
return r.rawReloc(k, r.Len())
}
// NewEncoder returns an Encoder for a new element within the given
// section, and encodes the given SyncMarker as the start of the
// element bitstream.
-func (pw *PkgEncoder) NewEncoder(k RelocKind, marker SyncMarker) Encoder {
+func (pw *PkgEncoder) NewEncoder(k SectionKind, marker SyncMarker) Encoder {
e := pw.NewEncoderRaw(k)
e.Sync(marker)
return e
// section.
//
// Most callers should use NewEncoder instead.
-func (pw *PkgEncoder) NewEncoderRaw(k RelocKind) Encoder {
+func (pw *PkgEncoder) NewEncoderRaw(k SectionKind) Encoder {
idx := RelIndex(len(pw.elems[k]))
pw.elems[k] = append(pw.elems[k], "") // placeholder
encodingRelocHeader bool
- k RelocKind
+ k SectionKind
Idx RelIndex // index within relocation section
}
w.rawUvarint(ux)
}
-func (w *Encoder) rawReloc(r RelocKind, idx RelIndex) int {
- e := RelocEnt{r, idx}
+func (w *Encoder) rawReloc(k SectionKind, idx RelIndex) int {
+ e := RelocEnt{k, idx}
if w.RelocMap != nil {
if i, ok := w.RelocMap[e]; ok {
return int(i)
// Note: Only the index is formally written into the element
// bitstream, so bitstream decoders must know from context which
// section an encoded relocation refers to.
-func (w *Encoder) Reloc(r RelocKind, idx RelIndex) {
+func (w *Encoder) Reloc(k SectionKind, idx RelIndex) {
w.Sync(SyncUseReloc)
- w.Len(w.rawReloc(r, idx))
+ w.Len(w.rawReloc(k, idx))
}
// Code encodes and writes a Code value into the element bitstream.