## digitalmars.D.learn - MemoryConduit

• Alberto (47/47) Feb 13 2007 I can write xml on buffer/file without problems, but I have some little
• kris (18/72) Feb 13 2007 It's not quite clear what you wish to do, but I'll have a go? First,
• Alberto (9/17) Feb 13 2007 because they didn't work for me, (some strange error on compile), now
• kris (2/20) Feb 13 2007 What tool are you using to build your project?
• Alberto (6/7) Feb 13 2007 I'm using build (bud) under windows (the project must works on windows :...
• kris (6/17) Feb 13 2007 Yep, I removed that as simply being unnecessary coupling.
• Alberto (19/20) Feb 13 2007 Now I can compile every tango example without problems with build, but
• John Reimer (8/33) Feb 14 2007 I actually think I'll have to remove the build-all.bat eventually becaus...
• kris (7/9) Feb 13 2007 The reason for the Eof is that you need to flush the output first. In
• John Demme (7/61) Feb 13 2007 I just added support today for reader.parse(IBuffer).
Alberto <reda zioale.it> writes:
I can write xml on buffer/file without  problems, but I have some little
problem parsing an xml from a buffer.
This is part of the sax example:

{
FileConduit file = new FileConduit("sample-32BE.xml",
MyOutputHandler handler = new MyOutputHandler();
}

/**
All SAX parsers must implement this interface.
*/
/**
Tells the parser to begin processing a document

Params:
source =	The IConduit that the parser should draw xml content from
handler =	The client interface who's methods the parser should call
encoding =	If the client knows it, tell the parser the text encoding
of the incoming XML.
If not specified, the parser will guess, and failing that assume
UTF8N.  The
enum for these types is in mango.convert.Unicode.
*/
public void parse(IConduit source, ISAXHandler!(T) handler, Encoding
encoding=Encoding.Unknown);
}

I must pass a conduit, ok.
I have tried to use MemoryConduit (I suppose that is the right way to do
what I want) but without success, something like:

char[] msg = "blabla";
char[] xml;
auto mc = new MemoryConduit();
auto write = new Writer (mc);
write (msg);
xml.length = msg.length;
Stdout(xml);
mc.close();

this give me:

I can't use the method writer because is not accessible, so how can I
use MemoryConduit?

Feb 13 2007
kris <foo bar.com> writes:
Alberto wrote:
I can write xml on buffer/file without  problems, but I have some little
problem parsing an xml from a buffer.
This is part of the sax example:

{
FileConduit file = new FileConduit("sample-32BE.xml",
MyOutputHandler handler = new MyOutputHandler();
}

/**
All SAX parsers must implement this interface.
*/
/**
Tells the parser to begin processing a document

Params:
source =	The IConduit that the parser should draw xml content from
handler =	The client interface who's methods the parser should call
encoding =	If the client knows it, tell the parser the text encoding
of the incoming XML.
If not specified, the parser will guess, and failing that assume
UTF8N.  The
enum for these types is in mango.convert.Unicode.
*/
public void parse(IConduit source, ISAXHandler!(T) handler, Encoding
encoding=Encoding.Unknown);
}

I must pass a conduit, ok.
I have tried to use MemoryConduit (I suppose that is the right way to do
what I want) but without success, something like:

char[] msg = "blabla";
char[] xml;
auto mc = new MemoryConduit();
auto write = new Writer (mc);
write (msg);
xml.length = msg.length;
Stdout(xml);
mc.close();

this give me:

I can't use the method writer because is not accessible, so how can I
use MemoryConduit?

It's not quite clear what you wish to do, but I'll have a go? First,
it's worth cleaning up a bit using "auto":

{
auto handler = new MyOutputHandler;
auto file = new FileConduit ("sample-32BE.xml");
}

Now the questions:

1) why do you require MemoryConduit? Have you constructed some in-memory
XML for parsing?

2) it's not clear why you're using protocols for this (Reader/Writer)
when you can use mc.write(void[]) and/or mc.read(void[])

3) is there a version of reader.parse() that accepts a Buffer instance
instead? If not, then there probably ought to be (since it would save
you some effort).

Feb 13 2007
Alberto <reda zioale.it> writes:
 1) why do you require MemoryConduit? Have you constructed some in-memory
XML for parsing?

yes, I must transfer xml file using POST method of HTTP (text/xml). So a
servlet of my HTTP server (I use mango) read the xml and must parse it.

2) it's not clear why you're using protocols for this (Reader/Writer)
when you can use mc.write(void[]) and/or mc.read(void[])

because they didn't work for me, (some strange error on compile), now
works. With that my problem with MemoryConduit is solved.
But now tango give me an error when I include tango.io.FileConduit.

c:\dmd\tango\tango\io\FileProxy.obj(FileProxy)
Error 42: Symbol Undefined _D12TypeInfo_AAa6__initZ

3) is there a version of reader.parse() that accepts a Buffer instance
instead? If not, then there probably ought to be (since it would save
you some effort).

no, I didn't find it.

Feb 13 2007
kris <foo bar.com> writes:
Alberto wrote:
1) why do you require MemoryConduit? Have you constructed some in-memory
XML for parsing?

yes, I must transfer xml file using POST method of HTTP (text/xml). So a
servlet of my HTTP server (I use mango) read the xml and must parse it.

2) it's not clear why you're using protocols for this (Reader/Writer)
when you can use mc.write(void[]) and/or mc.read(void[])

because they didn't work for me, (some strange error on compile), now
works. With that my problem with MemoryConduit is solved.
But now tango give me an error when I include tango.io.FileConduit.

c:\dmd\tango\tango\io\FileProxy.obj(FileProxy)
Error 42: Symbol Undefined _D12TypeInfo_AAa6__initZ

What tool are you using to build your project?

Feb 13 2007
Alberto <reda zioale.it> writes:
 What tool are you using to build your project?

I'm using build (bud) under windows (the project must works on windows :\)
Of course I'm using lastest tango+mango.

io  1676  2 hours  kris: removed FileProxy? dependency from

Ater the last update of tango all works.
Thanks.

Feb 13 2007
kris <foo bar.com> writes:
Alberto wrote:
What tool are you using to build your project?

I'm using build (bud) under windows (the project must works on windows :\)
Of course I'm using lastest tango+mango.

io  1676  2 hours  kris: removed FileProxy? dependency from

Ater the last update of tango all works.
Thanks.

Yep, I removed that as simply being unnecessary coupling.

But that should not have affected your build in any legitimate manner.
Everyone else has been building and linking these modules for ages and
not run into a problem. I'd like to get to the bottom of it ...

Would imagine you'll have some difficulty building the examples?

Feb 13 2007
Alberto <reda zioale.it> writes:
 Would imagine you'll have some difficulty building the examples?

Now I can compile every tango example without problems with build, but
with the build-all.bat I have some problem.

for example, if I did something like (cutted from build.all):

C:\dmd\tango\example> dmd conduits\composite.d
..\tango\io\model\IBuffer.d ..\tango\io\model\IConduit.d
..\tango\io\protocol\model\IProtocol.d ..\tango\io\protocol\Writer.d
..\tango\io\FileConst.d ..\tango\io\protocol\model\IWriter.d
..\tango\io\FileConduit.d ..\tango\sys\Common.d  ..\tango\io\FileProxy.d
..\tango\io\FilePath.d ..\tango\text\convert\Utf.d
..\tango\io\DeviceConduit.d ..\tango\io\Conduit.d -I.. -op

I get:

..\tango\io\FileProxy.obj(FileProxy)
Error 42: Symbol Undefined
_D5tango4util4time3Utc3Utc7convertFS5tango3sys5win325Types8FIL
ETIMEZE5tango4core4Type4Time
--- errorlevel 1

The same happens with system\argparser.d and all other conduits examples.

Feb 13 2007
John Reimer <terminal.node gmail.com> writes:
On Wed, 14 Feb 2007 01:40:26 +0100, Alberto wrote:

Would imagine you'll have some difficulty building the examples?

Now I can compile every tango example without problems with build, but
with the build-all.bat I have some problem.

for example, if I did something like (cutted from build.all):

C:\dmd\tango\example> dmd conduits\composite.d
..\tango\io\model\IBuffer.d ..\tango\io\model\IConduit.d
..\tango\io\protocol\model\IProtocol.d ..\tango\io\protocol\Writer.d
..\tango\io\FileConst.d ..\tango\io\protocol\model\IWriter.d
..\tango\io\FileConduit.d ..\tango\sys\Common.d  ..\tango\io\FileProxy.d
..\tango\io\FilePath.d ..\tango\text\convert\Utf.d
..\tango\io\DeviceConduit.d ..\tango\io\Conduit.d -I.. -op

I get:

..\tango\io\FileProxy.obj(FileProxy)
Error 42: Symbol Undefined
_D5tango4util4time3Utc3Utc7convertFS5tango3sys5win325Types8FIL
ETIMEZE5tango4core4Type4Time
--- errorlevel 1

The same happens with system\argparser.d and all other conduits examples.

I actually think I'll have to remove the build-all.bat eventually because,
if you are using the svn latest code, the code changes end up
rendering build-all quite useless.

It the meantime, if you use windows, you can use the jake version of it
(jake-all.bat) and it sould succeed.  rebuild also appears to work well.
I haven't tried bud, but it will probably work too.

-JJR

Feb 14 2007
kris <foo bar.com> writes:
Alberto wrote:
this give me:

The reason for the Eof is that you need to flush the output first. In
Tango pretty much all IO above the level of a Conduit is buffered, so
you'd need to do this:

# write (data) ();

or

# write (data).flush;

Feb 13 2007
John Demme <me teqdruid.com> writes:
Alberto wrote:

I can write xml on buffer/file without  problems, but I have some little
problem parsing an xml from a buffer.
This is part of the sax example:

{
FileConduit file = new FileConduit("sample-32BE.xml",
MyOutputHandler handler = new MyOutputHandler();
}

/**
All SAX parsers must implement this interface.
*/
/**
Tells the parser to begin processing a document

Params:
source =      The IConduit that the parser should draw xml content from
handler =     The client interface who's methods the parser should call
encoding =    If the client knows it, tell the parser the text encoding
of the incoming XML.
If not specified, the parser will guess, and failing that assume
UTF8N.  The
enum for these types is in mango.convert.Unicode.
*/
public void parse(IConduit source, ISAXHandler!(T) handler, Encoding
encoding=Encoding.Unknown);
}

I must pass a conduit, ok.
I have tried to use MemoryConduit (I suppose that is the right way to do
what I want) but without success, something like:

char[] msg = "blabla";
char[] xml;
auto mc = new MemoryConduit();
auto write = new Writer (mc);
write (msg);
xml.length = msg.length;
Stdout(xml);
mc.close();

this give me:

I can't use the method writer because is not accessible, so how can I
use MemoryConduit?