Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-16 Thread Van Fury
Thank you all for the clarification. At least I now know in this case octetString is referring to []byte. I did the conversion to []byte and the radius server accepted the result. I was just confused when the one handling the radius server asked for "raw binary" in the response. Help appreciated!!

Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-15 Thread Jesper Louis Andersen
On Tue, Mar 14, 2023 at 10:25 AM Van Fury wrote: > Am developing a server (diameter) which will response with an AVP > SIP-Authenticate. > In the specification > > " The SIP-Authenticate AVP is of type OctetString and It shall contain, > binary encoded, the concatenation of the authentication

Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-14 Thread Brian Candler
Presumably you are looking at something like this: https://www.etsi.org/deliver/etsi_ts/129200_129299/129229/13.01.00_60/ts_129229v130100p.pdf *6.3.10 SIP-Authenticate AVP* *The SIP-Authenticate AVP is of type OctetString and contains specific parts of the data portion of the

Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-14 Thread Brian Candler
On Tuesday, 14 March 2023 at 09:26:05 UTC Van Fury wrote: Am developing a server (diameter) which will response with an AVP SIP-Authenticate. In the specification " The SIP-Authenticate AVP is of type OctetString and It shall contain, binary encoded, the concatenation of the authentication

Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-14 Thread Van Fury
Am developing a server (diameter) which will response with an AVP SIP-Authenticate. In the specification " The SIP-Authenticate AVP is of type OctetString and It shall contain, binary encoded, the concatenation of the authentication challenge RAND and the token AUTN" The RAND and the AUTN in this

Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-14 Thread Marcello H
You can also use gob for that. Here are 2 functions from my library that can help. import "encoding/gob" /* encodeGob encodes a model to gob bytes. */ func encodeGob(data any) ([]byte, error) { var ( buf bytes.Buffer enc = gob.NewEncoder() // Will write to network. ) err := enc.Encode(data)

Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-13 Thread robert engels
Am arbitrary byte can be encoded in 2 HEX characters - only a 2x increase in size not 8x. > On Mar 13, 2023, at 2:35 PM, Volker Dobler wrote: > > On Monday, 13 March 2023 at 17:41:42 UTC+1 Van Fury wrote: > Relating to my previous question, I have been reading but it is still not > clear to

Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-13 Thread Volker Dobler
On Monday, 13 March 2023 at 17:41:42 UTC+1 Van Fury wrote: Relating to my previous question, I have been reading but it is still not clear to me what raw binary is, how is it different from text formatted binary (fmt.Sprintf("%b", s1s2Byte))? "text formated binary" takes a stream of bytes and

Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-13 Thread Bruno Albuquerque
I wonder if what is needed here is just null-terminated strings. -Bruno On Mon, Mar 13, 2023 at 1:28 PM Kurtis Rader wrote: > On Mon, Mar 13, 2023 at 9:41 AM Van Fury wrote: > >> Relating to my previous question, I have been reading but it is still not >> clear to me what raw binary is, how

Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-13 Thread Kurtis Rader
On Mon, Mar 13, 2023 at 9:41 AM Van Fury wrote: > Relating to my previous question, I have been reading but it is still not > clear to me what raw binary is, how is it different from > text formatted binary (fmt.Sprintf("%b", s1s2Byte))? > In my problem above I need to encode s1+s2 to raw binary

Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-13 Thread Van Fury
Relating to my previous question, I have been reading but it is still not clear to me what raw binary is, how is it different from text formatted binary (fmt.Sprintf("%b", s1s2Byte))? In my problem above I need to encode s1+s2 to raw binary before sending the result to the server which then

Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-13 Thread Van Fury
Do you mean encoding should be rawdata := fmt.Print("%016d%s%s", len(s1), s1,s2) or rawdata := fmt.Printf("%016d%s%s", len(s1), s1,s2) On Monday, March 13, 2023 at 4:36:50 PM UTC+2 Alex Howarth wrote: > You might be looking for strconv.ParseUint() > https://pkg.go.dev/strconv#ParseUint > >

Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-13 Thread Alex Howarth
You might be looking for strconv.ParseUint() https://pkg.go.dev/strconv#ParseUint https://go.dev/play/p/qAO9LfLD41D On Mon, 13 Mar 2023 at 07:24, Van Fury wrote: > > Sorry I did not frame my question properly but what I would like to do is > to > encode concatenated s1 and s2 into raw binary

Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-13 Thread Volker Dobler
On Monday, 13 March 2023 at 12:24:15 UTC+1 Van Fury wrote: Sorry I did not frame my question properly but what I would like to do is to encode concatenated s1 and s2 into raw binary and then decode the raw binary back to s1 and s2. The only problem is knowing where s1 ends / where s2 starts. So

Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-13 Thread Van Fury
Sorry I did not frame my question properly but what I would like to do is to encode concatenated s1 and s2 into raw binary and then decode the raw binary back to s1 and s2. On Friday, March 10, 2023 at 11:36:09 PM UTC+2 Alex Howarth wrote: > If s1 and s2 are a fixed length then you can just

Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-10 Thread Alex Howarth
If s1 and s2 are a fixed length then you can just slice up the decoded string based on the lengths. If they are of a variable length, you'll need a separator in the input string to later split on when decoded (s3 := s1 + ":" + s2 etc)? On Fri, 10 Mar 2023 at 10:33, Van Fury wrote: > Hi, > > I

Re: [go-nuts] How to encode/decode string to binary in golang

2023-03-10 Thread Kurtis Rader
Perhaps I have misunderstood your question but doesn't hex.EncodeToString(s1s2Byte) do what you want? On Fri, Mar 10, 2023 at 7:33 AM Van Fury wrote: > Hi, > > I have two hexadecimal string values and would like to concatenate the two > strings and > >1. encode the result to binary >2.

[go-nuts] How to encode/decode string to binary in golang

2023-03-10 Thread Van Fury
Hi, I have two hexadecimal string values and would like to concatenate the two strings and 1. encode the result to binary 2. decode the resulting binary back to hexadecimal string I did the following but I was finding it difficult to decode the result back. I ignore error check in this