Ejemplo n.º 1
0
Archivo: byte.go Proyecto: eaciit/labs
func main() {
	type Obj struct {
		AA string
		BB string
	}
	data := []Obj{
		{"A", "B"},
		{"C", "D"},
		{"E", "F"}}

	b := toolkit.GetEncodeByte(data)
	fmt.Printf("Data is : %v\nString: %v\nLen: %d\n", b, string(b), len(b))
	var decoded Obj
	toolkit.DecodeByte(b, &decoded)
	fmt.Printf("Decoded: %v \n\n", decoded)

	//b = []byte(fmt.Sprint(data))
	buf := new(bytes.Buffer)
	binary.Write(buf, binary.LittleEndian, data)
	b = buf.Bytes()
	fmt.Printf("Data is : %v\nString: %v\nLen: %d\n", b, string(b), len(b))
	eread := binary.Read(buf, binary.LittleEndian, &decoded)
	if eread != nil {
		fmt.Printf("Unable to decode. %s \n", eread.Error())
	} else {
		fmt.Printf("Decoded: %v \n\n", decoded)
	}
}
Ejemplo n.º 2
0
func main() {
	s := new(obj)
	s.Output = "Arief Darmawan"
	sb, _ := tk.EncodeByte(s)
	fmt.Printf("Encoded: %v \n", s)
	result := new(obj)
	e := tk.DecodeByte(sb, &result)
	if e != nil {
		fmt.Println("Error decoding: ", e.Error())
	}
	fmt.Printf("Decode: %v \n", result.Output)
}
Ejemplo n.º 3
0
func (a *AppClient) Call(methodName string, in toolkit.M, result interface{}) error {
	out := new(toolkit.Result)
	in["method"] = methodName
	e := a.client.Call("Rpc.Do", in, out)
	//_ = "breakpoint"
	if e != nil {
		return errorlib.Error(packageName, objAppClient, "Call", e.Error())
	} else if out.Status == toolkit.Status_NOK {
		return errorlib.Error(packageName, objAppClient, "Call", out.Message)
	} else {
		if result != nil {
			if out.Data != nil {
				result = toolkit.DecodeByte(out.Data.([]byte), result)
			}
		}
	}
	return nil
}