tlog.app/go/tlog@v0.23.1/examples/raw/main.go (about) 1 package main 2 3 import ( 4 "tlog.app/go/tlog" 5 "tlog.app/go/tlog/tlwire" 6 ) 7 8 type ( 9 ValueEncoder struct { 10 b []byte 11 } 12 ) 13 14 func main() { 15 var e tlwire.Encoder 16 17 // pre encode key-value pair 18 kvs := e.AppendKeyInt(nil, "raw_key_val", 4) 19 20 tlog.Printw("raw kv pair", tlog.RawMessage(kvs)) 21 22 // pre encode value 23 val1 := e.AppendString(nil, "_value_") 24 25 tlog.Printw("raw value", "raw_value", tlog.RawMessage(val1)) 26 27 // custom value encoding 28 val2 := ValueEncoder{ 29 b: []byte{0x00, 0x11, 0x22}, 30 } 31 32 tlog.Printw("custom value encoder", "custom_formatted", val2) 33 34 tlog.Printw("modifyer", "want_in_hex", tlog.NextAsHex, 42) 35 36 tlog.Printw("inline object", "object", tlog.RawTag(tlwire.Map, 2), "first_key", 42, "second_key", "val") 37 } 38 39 func (x ValueEncoder) TlogAppend(b []byte) []byte { 40 var e tlwire.Encoder 41 b = e.AppendTag(b, tlwire.Semantic, tlwire.Hex) 42 b = e.AppendBytes(b, x.b) 43 return b 44 }