Пример #1
0
// decode from bytes.
// Return bytes decoded or 0 if we could not decode a complete object.
//
func decode(data *C.pn_data_t, bytes []byte) (int, error) {
	if len(bytes) == 0 {
		return 0, nil
	}
	n := int(C.pn_data_decode(data, cPtr(bytes), cLen(bytes)))
	if n == int(C.PN_UNDERFLOW) {
		C.pn_error_clear(C.pn_data_error(data))
		return 0, nil
	} else if n <= 0 {
		return 0, fmt.Errorf("unmarshal %s", PnErrorCode(n))
	}
	return n, nil
}
Пример #2
0
// decode from bytes.
// Return bytes decoded or 0 if we could not decode a complete object.
//
func decode(data *C.pn_data_t, bytes []byte) int {
	if len(bytes) == 0 {
		return 0
	}
	n := int(C.pn_data_decode(data, cPtr(bytes), cLen(bytes)))
	if n == int(C.PN_UNDERFLOW) {
		C.pn_error_clear(C.pn_data_error(data))
		return 0
	} else if n <= 0 {
		panic(internal.Errorf("unmarshal %s", internal.PnErrorCode(n)))
	}
	return n
}