parsing from file fixes + pretty printing.

This commit is contained in:
fiatjaf
2023-09-24 22:05:54 -03:00
parent 619f2cb453
commit 3c38206ce3
3 changed files with 180 additions and 29 deletions

View File

@@ -88,3 +88,29 @@ func (buf Buffer) readVarBytes() ([]byte, error) {
fmt.Println("->", hex.EncodeToString(b))
return b, nil
}
func appendVarUint(buf []byte, value uint64) []byte {
if value == 0 {
buf = append(buf, 0)
} else {
for value != 0 {
b := byte(value & 0b01111111)
if value > 0b01111111 {
b |= 0b10000000
}
buf = append(buf, b)
if value <= 0b01111111 {
break
}
value >>= 7
}
}
return buf
}
func appendVarBytes(buf []byte, value []byte) []byte {
buf = appendVarUint(buf, uint64(len(value)))
buf = append(buf, value...)
return buf
}