Last active
May 11, 2016 20:32
-
-
Save bprosnitz/5a79afc84c4a21a856d9a06f84ac1796 to your computer and use it in GitHub Desktop.
debug_encoder_decoder.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package vdl | |
import ( | |
"fmt" | |
"strings" | |
) | |
type DebugDecoder struct { | |
Depth int | |
Prefix string | |
Inner Decoder | |
} | |
func (d *DebugDecoder) StartValue() error { | |
fmt.Printf("%s%s StartValue\n", strings.Repeat("\t", d.Depth), d.Prefix) | |
err := d.Inner.StartValue() | |
fmt.Printf("%s%s -> error: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, err) | |
d.Depth++ | |
return err | |
} | |
func (d *DebugDecoder) FinishValue() error { | |
d.Depth-- | |
fmt.Printf("%s%s FinishValue\n", strings.Repeat("\t", d.Depth), d.Prefix) | |
err := d.Inner.FinishValue() | |
fmt.Printf("%s%s -> error: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, err) | |
return err | |
} | |
func (d *DebugDecoder) StackDepth() int { | |
fmt.Printf("%s%s StackDepth\n", strings.Repeat("\t", d.Depth), d.Prefix) | |
depth := d.Inner.StackDepth() | |
fmt.Printf("%s%s -> depth: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, depth) | |
return depth | |
} | |
func (d *DebugDecoder) SkipValue() error { | |
fmt.Printf("%s%s SkipValue\n", strings.Repeat("\t", d.Depth), d.Prefix) | |
err := d.Inner.SkipValue() | |
fmt.Printf("%s%s -> error: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, err) | |
return err | |
} | |
func (d *DebugDecoder) IgnoreNextStartValue() { | |
fmt.Printf("%s%s IgnoreNextStartValue\n", strings.Repeat("\t", d.Depth), d.Prefix) | |
d.Inner.IgnoreNextStartValue() | |
} | |
func (d *DebugDecoder) NextEntry() (bool, error) { | |
fmt.Printf("%s%s NextEntry\n", strings.Repeat("\t", d.Depth), d.Prefix) | |
done, err := d.Inner.NextEntry() | |
fmt.Printf("%s%s -> done: %v, error: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, done, err) | |
return done, err | |
} | |
func (d *DebugDecoder) NextField() (string, error) { | |
fmt.Printf("%s%s NextField\n", strings.Repeat("\t", d.Depth), d.Prefix) | |
name, err := d.Inner.NextField() | |
fmt.Printf("%s%s -> name: %q, error: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, name, err) | |
return name, err | |
} | |
func (d *DebugDecoder) Type() *Type { | |
fmt.Printf("%s%s Type\n", strings.Repeat("\t", d.Depth), d.Prefix) | |
tt := d.Inner.Type() | |
fmt.Printf("%s%s -> type: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, tt) | |
return tt | |
} | |
func (d *DebugDecoder) IsAny() bool { | |
fmt.Printf("%s%s IsAny\n", strings.Repeat("\t", d.Depth), d.Prefix) | |
isAny := d.Inner.IsAny() | |
fmt.Printf("%s%s -> is any: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, isAny) | |
return isAny | |
} | |
func (d *DebugDecoder) IsOptional() bool { | |
fmt.Printf("%s%s IsOptional\n", strings.Repeat("\t", d.Depth), d.Prefix) | |
isOptional := d.Inner.IsOptional() | |
fmt.Printf("%s%s -> is optional: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, isOptional) | |
return isOptional | |
} | |
func (d *DebugDecoder) IsNil() bool { | |
fmt.Printf("%s%s IsNil\n", strings.Repeat("\t", d.Depth), d.Prefix) | |
isNil := d.Inner.IsNil() | |
fmt.Printf("%s%s -> is nil: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, isNil) | |
return isNil | |
} | |
func (d *DebugDecoder) Index() int { | |
fmt.Printf("%s%s Index\n", strings.Repeat("\t", d.Depth), d.Prefix) | |
index := d.Inner.Index() | |
fmt.Printf("%s%s -> index: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, index) | |
return index | |
} | |
func (d *DebugDecoder) LenHint() int { | |
fmt.Printf("%s%s LenHint\n", strings.Repeat("\t", d.Depth), d.Prefix) | |
lenhint := d.Inner.LenHint() | |
fmt.Printf("%s%s -> len hint: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, lenhint) | |
return lenhint | |
} | |
func (d *DebugDecoder) DecodeBool() (bool, error) { | |
fmt.Printf("%s%s DecodeBool\n", strings.Repeat("\t", d.Depth), d.Prefix) | |
val, err := d.Inner.DecodeBool() | |
fmt.Printf("%s%s -> val: %v, error: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, val, err) | |
return val, err | |
} | |
func (d *DebugDecoder) DecodeString() (string, error) { | |
fmt.Printf("%s%s DecodeString\n", strings.Repeat("\t", d.Depth), d.Prefix) | |
val, err := d.Inner.DecodeString() | |
fmt.Printf("%s%s -> val: %v, error: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, val, err) | |
return val, err | |
} | |
func (d *DebugDecoder) DecodeTypeObject() (*Type, error) { | |
fmt.Printf("%s%s DecodeTypeObject\n", strings.Repeat("\t", d.Depth), d.Prefix) | |
val, err := d.Inner.DecodeTypeObject() | |
fmt.Printf("%s%s -> val: %v, error: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, val, err) | |
return val, err | |
} | |
func (d *DebugDecoder) DecodeUint(bitlen int) (uint64, error) { | |
fmt.Printf("%s%s DecodeUint bitlen: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, bitlen) | |
val, err := d.Inner.DecodeUint(bitlen) | |
fmt.Printf("%s%s -> val: %v, error: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, val, err) | |
return val, err | |
} | |
func (d *DebugDecoder) DecodeInt(bitlen int) (int64, error) { | |
fmt.Printf("%s%s DecodeInt bitlen: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, bitlen) | |
val, err := d.Inner.DecodeInt(bitlen) | |
fmt.Printf("%s%s -> val: %v, error: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, val, err) | |
return val, err | |
} | |
func (d *DebugDecoder) DecodeFloat(bitlen int) (float64, error) { | |
fmt.Printf("%s%s DecodeFloat bitlen: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, bitlen) | |
val, err := d.Inner.DecodeFloat(bitlen) | |
fmt.Printf("%s%s -> val: %v, error: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, val, err) | |
return val, err | |
} | |
func (d *DebugDecoder) DecodeBytes(fixedlen int, x *[]byte) error { | |
fmt.Printf("%s%s DecodeBytes fixedlen: %v, x: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, fixedlen, x) | |
err := d.Inner.DecodeBytes(fixedlen, x) | |
fmt.Printf("%s%s -> error: %v\n", strings.Repeat("\t", d.Depth), d.Prefix, err) | |
return err | |
} | |
type DebugEncoder struct { | |
Depth int | |
Prefix string | |
Inner Encoder | |
} | |
func (e *DebugEncoder) SetNextStartValueIsOptional() { | |
fmt.Printf("%s%s SetNextStartValueIsOptional\n", strings.Repeat("\t", e.Depth), e.Prefix) | |
e.Inner.SetNextStartValueIsOptional() | |
} | |
func (e *DebugEncoder) StartValue(tt *Type) error { | |
fmt.Printf("%s%s StartValue type: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, tt) | |
err := e.Inner.StartValue(tt) | |
fmt.Printf("%s%s -> error: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, err) | |
e.Depth++ | |
return err | |
} | |
func (e *DebugEncoder) FinishValue() error { | |
e.Depth-- | |
fmt.Printf("%s%s FinishValue\n", strings.Repeat("\t", e.Depth), e.Prefix) | |
err := e.Inner.FinishValue() | |
fmt.Printf("%s%s -> error: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, err) | |
return err | |
} | |
func (e *DebugEncoder) NilValue(tt *Type) error { | |
fmt.Printf("%s%s NilValue type: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, tt) | |
err := e.Inner.NilValue(tt) | |
fmt.Printf("%s%s -> error: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, err) | |
return err | |
} | |
func (e *DebugEncoder) NextEntry(done bool) error { | |
fmt.Printf("%s%s NextEntry done: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, done) | |
err := e.Inner.NextEntry(done) | |
fmt.Printf("%s%s -> error: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, err) | |
return err | |
} | |
func (e *DebugEncoder) NextField(name string) error { | |
fmt.Printf("%s%s NextField name: %q\n", strings.Repeat("\t", e.Depth), e.Prefix, name) | |
err := e.Inner.NextField(name) | |
fmt.Printf("%s%s -> error: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, err) | |
return err | |
} | |
func (e *DebugEncoder) SetLenHint(lenHint int) error { | |
fmt.Printf("%s%s SetLenHint lenHint: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, lenHint) | |
err := e.Inner.SetLenHint(lenHint) | |
fmt.Printf("%s%s -> error: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, err) | |
return err | |
} | |
func (e *DebugEncoder) EncodeBool(v bool) error { | |
fmt.Printf("%s%s EncodeBool val: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, v) | |
err := e.Inner.EncodeBool(v) | |
fmt.Printf("%s%s -> error: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, err) | |
return err | |
} | |
func (e *DebugEncoder) EncodeUint(v uint64) error { | |
fmt.Printf("%s%s EncodeUint val: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, v) | |
err := e.Inner.EncodeUint(v) | |
fmt.Printf("%s%s -> error: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, err) | |
return err | |
} | |
func (e *DebugEncoder) EncodeInt(v int64) error { | |
fmt.Printf("%s%s EncodeInt val: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, v) | |
err := e.Inner.EncodeInt(v) | |
fmt.Printf("%s%s -> error: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, err) | |
return err | |
} | |
func (e *DebugEncoder) EncodeFloat(v float64) error { | |
fmt.Printf("%s%s EncodeFloat val: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, v) | |
err := e.Inner.EncodeFloat(v) | |
fmt.Printf("%s%s -> error: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, err) | |
return err | |
} | |
func (e *DebugEncoder) EncodeBytes(v []byte) error { | |
fmt.Printf("%s%s EncodeBytes val: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, v) | |
err := e.Inner.EncodeBytes(v) | |
fmt.Printf("%s%s -> error: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, err) | |
return err | |
} | |
func (e *DebugEncoder) EncodeString(v string) error { | |
fmt.Printf("%s%s EncodeString val: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, v) | |
err := e.Inner.EncodeString(v) | |
fmt.Printf("%s%s -> error: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, err) | |
return err | |
} | |
func (e *DebugEncoder) EncodeTypeObject(v *Type) error { | |
fmt.Printf("%s%s EncodeTypeObject val: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, v) | |
err := e.Inner.EncodeTypeObject(v) | |
fmt.Printf("%s%s -> error: %v\n", strings.Repeat("\t", e.Depth), e.Prefix, err) | |
return err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment