3!:3 is the easiest way  to see those extra bytes.

I don't know if you have a very narrow constant rank and shape format, but even 
if you did, you could read it from the file rather than assume it is in 
expected format.

using the reference page and simple examples as below
3!:3 ] 5
3!:3 ] <5
3!:3 ] <5;3

Something interesting about the format is that adding an extra level of boxing 
around data, doesn't change any of the data offsets within the data.  It just 
adds a 5 word header to it.

----- Original Message -----
From: Jon Hough <[email protected]>
To: "[email protected]" <[email protected]>
Cc: 
Sent: Wednesday, January 21, 2015 7:49 PM
Subject: Re: [Jprogramming] J Equivalent of Python Struct.Pack/Unpack

It seems, if I want to send the data over a network, I'm going to have to strip 
off several bytes after packing, because  
x 3!:1
puts on several bytes on the front of the result. e.g. flag, type, num of 
elements etc. Is this normal to do this?

> Date: Wed, 21 Jan 2015 13:04:57 +0900
> From: [email protected]
> To: [email protected]
> Subject: Re: [Jprogramming] J Equivalent of Python Struct.Pack/Unpack
> 
> Thanks.
> I am working on a small project in which I need to use these binary string 
> conversions and parse them in other languages, eg python.
> 
> I am hoping if I use 3!: 1  then I can unpack in Python.
> 
> --- Original Message ---
> 
> From: "Raul Miller" <[email protected]>
> Sent: January 21, 2015 10:57 AM
> To: "Programming forum" <[email protected]>
> Subject: Re: [Jprogramming] J Equivalent of Python Struct.Pack/Unpack
> 
> I usually use 3!:4 and 3!:5 when reading objects streamed to file from
> someone else's code. I wind up writing a read verb (and a write verb)
> for every "type" which reads its stuff starting at a global offset
> into the reference character array and then updates that offset to
> point at the end. If there's ever an array of them, the dyadic form of
> the verb reads x of them. (And one dimension is sufficient in this
> context.)
> 
> I can tell my code is correct when it can read a file to my internal
> representation and write it back out without introducing any defects
> on my test data set. Except I can also identify bugs in the original
> code when coding to spec requires that what I write back out differs
> from what I read in. That can get annoying sometimes (it means that
> for complete correctness I need to represent the buggy data - that's
> the sort of thing that makes me feel like abandoning a project or at
> least wish I could replace larger parts of the system).
> 
> It's very "forth-like" in feel, and verbose. And some types require a
> bit of manipulation after the initial conversion, to make things
> correct. But, this seems to me to be a fairly appropriate match to the
> problem.
> 
> Your mileage may vary.
> 
> Thanks,
> 
> --
> Raul
> 
> On Tue, Jan 20, 2015 at 10:47 AM, 'Pascal Jasmin' via Programming
> <[email protected]> wrote:
> > 3!:1 is more powerful than this.  Converts any noun to a binary (string) 
> > representation.  3!:2 unpacks.
> >
> >
> > ----- Original Message -----
> > From: Jon Hough <[email protected]>
> > To: "[email protected]" <[email protected]>
> > Cc:
> > Sent: Tuesday, January 20, 2015 10:42 AM
> > Subject: [Jprogramming] J Equivalent of Python Struct.Pack/Unpack
> >
> > Python has a useful module called struct
> > https://docs.python.org/2/library/struct.html
> > which is useful for converting strings to packed binary data.
> > e.g.
> > data = struct.pack('B', someHexString)
> >
> > Does J have an equivalent or similar function / verb?
> > I spent a bit of time looking, but couldn't find anything.
> >
> > Example usage would be sending data over a network.
> >
> >
> >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm

> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
                          
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to