From 3479b3dbacceeb2fdc7591bdb150c10e31299ba4 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 9 Oct 2015 19:41:46 +0200 Subject: First real communication --- rose/rose.go | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'rose/rose.go') diff --git a/rose/rose.go b/rose/rose.go index 27365cd..1e670cc 100644 --- a/rose/rose.go +++ b/rose/rose.go @@ -7,7 +7,12 @@ import "github.com/dim13/asn1" // Invoke is Context-specific Constructed 1 type Invoke struct { asn1.Tag `asn1:"tag:1"` - InvokeId int + InvokeID int + Opcode int `asn1:"optional"` + asn1.RawValue `asn1:"optional"` +} + +type Result struct { Opcode int `asn1:"optional"` asn1.RawValue `asn1:"optional"` } @@ -15,9 +20,28 @@ type Invoke struct { // ReturnResult it Context-specific Constructed 2 type ReturnResult struct { asn1.Tag `asn1:"tag:2"` - InvokeId int - Result struct { - Opcode int `asn1:"optional"` - asn1.RawValue `asn1:"optional"` + InvokeID int + Result `asn1:"optional,expicit"` +} + +func Unmarshal(b []byte) (int, int, []byte, error) { + v := &Invoke{} + _, err := asn1.Unmarshal(b, v) + if err != nil { + return 0, 0, nil, err + } + return v.InvokeID, v.Opcode, v.RawValue.FullBytes, nil +} + +func Marshal(id, opcode int, b []byte) ([]byte, error) { + v := ReturnResult{ + InvokeID: id, + Result: Result{ + Opcode: opcode, + RawValue: asn1.RawValue{ + FullBytes: b, + }, + }, } + return asn1.Marshal(v) } -- cgit v1.2.3