Skip to content

Commit

Permalink
codec: streamline library: refactor sendContainerState and clean up h…
Browse files Browse the repository at this point in the history
…andle-specific test flags

refactor sendContainerState to be methods on (en|de)cDriver

    Basically, move from sendContainerState to roughly
    (Read|Write)(Array|Map)(Elem)(Key|Value)(Start|End)

Support IndefiniteLength in cbor during encoding

test: make testUseIoEncDec an int flag, which specifies buffer size

    It defaults to -1, which means do not use io.
    if >= 0, then we use io.Reader/io.Writer with a buffer in front.

test: do not use flags for handle-specific configuration

    Instead, create suite groups for each handle, and modify the configuration
    for the test group, and execute the handle-specific tests.
  • Loading branch information
ugorji committed Oct 18, 2017
1 parent f26fc64 commit c3953de
Show file tree
Hide file tree
Showing 20 changed files with 5,459 additions and 6,823 deletions.
13 changes: 8 additions & 5 deletions codec/binc.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ type bincEncDriver struct {
m map[string]uint16 // symbols
b [scratchByteArrayLen]byte
s uint16 // symbols sequencer
encNoSeparator
// encNoSeparator
encDriverNoopContainerWriter
}

func (e *bincEncDriver) IsBuiltinType(rt uintptr) bool {
Expand Down Expand Up @@ -195,11 +196,11 @@ func (e *bincEncDriver) encodeExtPreamble(xtag byte, length int) {
e.w.writen1(xtag)
}

func (e *bincEncDriver) EncodeArrayStart(length int) {
func (e *bincEncDriver) WriteArrayStart(length int) {
e.encLen(bincVdArray<<4, uint64(length))
}

func (e *bincEncDriver) EncodeMapStart(length int) {
func (e *bincEncDriver) WriteMapStart(length int) {
e.encLen(bincVdMap<<4, uint64(length))
}

Expand Down Expand Up @@ -332,13 +333,14 @@ type bincDecDriver struct {
bd byte
vd byte
vs byte
noStreamingCodec
decNoSeparator
// noStreamingCodec
// decNoSeparator
b [scratchByteArrayLen]byte

// linear searching on this slice is ok,
// because we typically expect < 32 symbols in each stream.
s []bincDecSymbol
decDriverNoopContainerReader
}

func (d *bincDecDriver) readNextBd() {
Expand Down Expand Up @@ -909,6 +911,7 @@ func (d *bincDecDriver) DecodeNaked() {
type BincHandle struct {
BasicHandle
binaryEncodingType
noElemSeparators
}

func (h *BincHandle) SetBytesExt(rt reflect.Type, tag uint64, ext BytesExt) (err error) {
Expand Down
38 changes: 32 additions & 6 deletions codec/cbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ const (

type cborEncDriver struct {
noBuiltInTypes
encNoSeparator
encDriverNoopContainerWriter
// encNoSeparator
e *Encoder
w encWriter
h *CborHandle
Expand Down Expand Up @@ -143,12 +144,32 @@ func (e *cborEncDriver) EncodeRawExt(re *RawExt, en *Encoder) {
}
}

func (e *cborEncDriver) EncodeArrayStart(length int) {
e.encLen(cborBaseArray, length)
func (e *cborEncDriver) WriteArrayStart(length int) {
if e.h.IndefiniteLength {
e.w.writen1(cborBdIndefiniteArray)
} else {
e.encLen(cborBaseArray, length)
}
}

func (e *cborEncDriver) EncodeMapStart(length int) {
e.encLen(cborBaseMap, length)
func (e *cborEncDriver) WriteMapStart(length int) {
if e.h.IndefiniteLength {
e.w.writen1(cborBdIndefiniteMap)
} else {
e.encLen(cborBaseMap, length)
}
}

func (e *cborEncDriver) WriteMapEnd() {
if e.h.IndefiniteLength {
e.w.writen1(cborBdBreak)
}
}

func (e *cborEncDriver) WriteArrayEnd() {
if e.h.IndefiniteLength {
e.w.writen1(cborBdBreak)
}
}

func (e *cborEncDriver) EncodeString(c charEncoding, v string) {
Expand Down Expand Up @@ -180,7 +201,8 @@ type cborDecDriver struct {
bdRead bool
bd byte
noBuiltInTypes
decNoSeparator
// decNoSeparator
decDriverNoopContainerReader
}

func (d *cborDecDriver) readNextBd() {
Expand Down Expand Up @@ -577,7 +599,11 @@ func (d *cborDecDriver) DecodeNaked() {
//
type CborHandle struct {
binaryEncodingType
noElemSeparators
BasicHandle

// IndefiniteLength=true, means that we encode using indefinitelength
IndefiniteLength bool
}

func (h *CborHandle) SetInterfaceExt(rt reflect.Type, tag uint64, ext InterfaceExt) (err error) {
Expand Down
20 changes: 5 additions & 15 deletions codec/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ import (

func init() {
testPreInitFns = append(testPreInitFns, testInit)
fmt.Printf("sizeof: Decoder: %v, Encoder: %v, decNaked: %v\n",
reflect.TypeOf((*Decoder)(nil)).Elem().Size(),
reflect.TypeOf((*Encoder)(nil)).Elem().Size(),
reflect.TypeOf((*decNaked)(nil)).Elem().Size(),
)
// fmt.Printf("sizeof: Decoder: %v, Encoder: %v, decNaked: %v\n",
// reflect.TypeOf((*Decoder)(nil)).Elem().Size(),
// reflect.TypeOf((*Encoder)(nil)).Elem().Size(),
// reflect.TypeOf((*decNaked)(nil)).Elem().Size(),
// )
}

// make this a mapbyslice
Expand Down Expand Up @@ -349,18 +349,8 @@ func testInit() {
bh.CheckCircularRef = testCheckCircRef
bh.StructToArray = testStructToArray
bh.MaxInitLen = testMaxInitLen
// mostly doing this for binc
if testWriteNoSymbols {
bh.AsSymbols = AsSymbolNone
} else {
bh.AsSymbols = AsSymbolAll
}
}

testJsonH.Indent = int8(testJsonIndent)
testJsonH.HTMLCharsAsIs = testJsonHTMLCharsAsIs
testJsonH.PreferFloat = testJsonPreferFloat

testMsgpackH.RawToString = true

// testMsgpackH.AddExt(byteSliceTyp, 0, testMsgpackH.BinaryEncodeExt, testMsgpackH.BinaryDecodeExt)
Expand Down
Loading

4 comments on commit c3953de

@georgekarrv
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This broke etcd client :(

@georgekarrv
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ugorji
Copy link
Owner Author

@ugorji ugorji commented on c3953de Oct 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@georgekarrv Did you recreate codecgen and then re-generate the files?

@georgekarrv
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.