github.com/stellar/go-xdr@v0.0.0-20231122183749-b53fb00bcac2/xdr3/internal_test.go (about) 1 /* 2 * Copyright (c) 2012-2014 Dave Collins <dave@davec.name> 3 * 4 * Permission to use, copy, modify, and distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 /* 18 This test file is part of the xdr package rather than than the xdr_test package 19 so it can bridge access to the internals to properly test cases which are either 20 not possible or can't reliably be tested via the public interface. The functions 21 are only exported while the tests are being run. 22 */ 23 24 package xdr 25 26 import ( 27 "io" 28 "reflect" 29 ) 30 31 // TstEncode creates a new Encoder to the passed writer and returns the internal 32 // encode function on the Encoder. 33 func TstEncode(w io.Writer) func(v reflect.Value) (int, error) { 34 enc := NewEncoder(w) 35 return enc.encode 36 } 37 38 // TstDecode creates a new Decoder for the passed reader and returns the 39 // internal decode function on the Decoder. 40 func TstDecode(r io.Reader) func(v reflect.Value, maxLen int, maxDepth uint) (int, error) { 41 dec := NewDecoder(r) 42 return dec.decode 43 }